interplane.Get Omega
Read in your language

omtex

aien-dev/omtex

Brought by drakestapleton

branch main Branches Tags History

omtex / tools / compare.sh

32 lines · 2077 bytes Raw Blame History
1#!/bin/sh
2# compare.sh ORIG.tex ORIG.pdf OMTEX.tex OMTEX.pdf -- compare an omtex reproduction with the original.
3# 1. text: pdftotext -layout of the published ORIG.pdf vs OMTEX.pdf (diff line count, 0 = identical)
4# 2. pages: page counts
5# 3. pixels: ORIG.tex compiled here with the same pdflatex, rendered at 100 dpi, page-by-page cmp
6# with OMTEX.pdf (isolates omtex from TeX Live version differences)
7# 4. source: word-level diff of ORIG.tex vs OMTEX.tex (whitespace-insensitive), as counted pairs
8set -eu
9otex=$(realpath "$1") opdf=$(realpath "$2") mtex=$(realpath "$3") mpdf=$(realpath "$4")
10nice=${OMTEX_NICE-nice -n 19 ionice -c3}
11W=$(mktemp -d "${TMPDIR:-/tmp}/omtex-cmp.XXXXXX")
12trap 'rm -rf "$W"' EXIT
13pages() { pdfinfo "$1" | awk '/^Pages/{print $2}'; }
14echo "orig.tex sha256 $(sha256sum < "$otex" | cut -d' ' -f1)"
15echo "orig.pdf sha256 $(sha256sum < "$opdf" | cut -d' ' -f1) producer $(pdfinfo "$opdf" | sed -n 's/^Producer: *//p')"
16echo "omtex.tex sha256 $(sha256sum < "$mtex" | cut -d' ' -f1)"
17echo "omtex.pdf producer $(pdfinfo "$mpdf" | sed -n 's/^Producer: *//p')"
18pdftotext -layout "$opdf" "$W/o.txt"; pdftotext -layout "$mpdf" "$W/m.txt"
19echo "text: published PDF vs omtex PDF differing lines: $(diff "$W/o.txt" "$W/m.txt" | grep -c '^[<>]' || true)"
20echo "pages: published $(pages "$opdf") omtex $(pages "$mpdf")"
21cp "$otex" "$W/orig.tex"
22( cd "$W" && for i in 1 2; do $nice pdflatex -interaction=nonstopmode -halt-on-error -no-shell-escape orig.tex > /dev/null; done )
23pdftoppm -r 100 "$W/orig.pdf" "$W/l"; pdftoppm -r 100 "$mpdf" "$W/m"
24same=0 total=0
25for f in "$W"/l-*.ppm; do
26 total=$((total + 1)); g=$W/m-${f##*/l-}
27 if [ -f "$g" ] && cmp -s "$f" "$g"; then same=$((same + 1)); else echo "pixels: page ${f##*/l-} differs"; fi
28done
29echo "pixels: original .tex built here vs omtex PDF, 100 dpi: $same/$total pages identical"
30tr -s ' \n\t' '\n\n\n' < "$otex" > "$W/o.w"; tr -s ' \n\t' '\n\n\n' < "$mtex" > "$W/m.w"
31echo "source word diff (count, side, token):"
32diff "$W/o.w" "$W/m.w" | grep '^[<>]' | sort | uniq -c | sort -rn || echo " none"