aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/tools/typesetting/tex/nix/run-latex.sh
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
committerMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
commitc4625b175f8200f643fd6e11010932ea44c78433 (patch)
treebce3f89888c8ac3991fa5569a878a9eab6801ccc /infra/libkookie/nixpkgs/pkgs/tools/typesetting/tex/nix/run-latex.sh
parent49f735974dd103039ddc4cb576bb76555164a9e7 (diff)
parentd661aa56a8843e991261510c1bb28fdc2f6975ae (diff)
Add 'infra/libkookie/' from commit 'd661aa56a8843e991261510c1bb28fdc2f6975ae'
git-subtree-dir: infra/libkookie git-subtree-mainline: 49f735974dd103039ddc4cb576bb76555164a9e7 git-subtree-split: d661aa56a8843e991261510c1bb28fdc2f6975ae
Diffstat (limited to 'infra/libkookie/nixpkgs/pkgs/tools/typesetting/tex/nix/run-latex.sh')
-rw-r--r--infra/libkookie/nixpkgs/pkgs/tools/typesetting/tex/nix/run-latex.sh167
1 files changed, 167 insertions, 0 deletions
diff --git a/infra/libkookie/nixpkgs/pkgs/tools/typesetting/tex/nix/run-latex.sh b/infra/libkookie/nixpkgs/pkgs/tools/typesetting/tex/nix/run-latex.sh
new file mode 100644
index 000000000000..7a5767f9c063
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/tools/typesetting/tex/nix/run-latex.sh
@@ -0,0 +1,167 @@
+source $stdenv/setup
+
+mkdir -p $out
+
+export VARTEXFONTS=$TMPDIR/texfonts
+export TEXMFCNF=$TMPDIR:
+echo 'max_print_line = 8192' >> $TMPDIR/texmf.cnf
+
+mkdir root
+cd root
+
+startDir=$(perl $copyIncludes $includes)
+cd $startDir
+
+for i in $extraFiles; do
+ if test -d $i; then
+ ln -s $i/* .
+ else
+ ln -s $i $(stripHash $i)
+ fi
+done
+
+rootName=$(basename $(stripHash "$rootFile"))
+
+rootNameBase=$(echo "$rootName" | sed 's/\..*//')
+
+if test -n "$generatePDF"; then
+ latex=pdflatex
+else
+ latex=latex
+fi
+
+latexFlags="-file-line-error"
+tmpFile=$out/log
+
+showError() {
+ echo
+ echo "LATEX ERROR (LAST LOG LINES SHOWN):"
+ tail -n 20 $tmpFile
+ bzip2 $tmpFile
+ exit 1
+}
+
+runLaTeX() {
+ if ! $latex $latexFlags $rootName >$tmpFile 2>&1; then showError; fi
+ runNeeded=
+ if fgrep -q \
+ -e "LaTeX Warning: Label(s) may have changed." \
+ -e "Rerun to get citations correct." \
+ -e "Please rerun LaTeX." \
+ "$tmpFile"; then
+ runNeeded=1
+ fi
+}
+
+echo
+
+
+if test -n "$copySources"; then
+ cp -prd $TMPDIR/root $out/tex-srcs
+fi
+
+
+echo "PASS 1..."
+runLaTeX
+echo
+
+
+for auxFile in $(find . -name "*.aux"); do
+ # Run bibtex to process all bibliographies. There may be several
+ # when we're using the multibib package.
+ if grep -q '\\citation' $auxFile; then
+ auxBase=$(basename $auxFile .aux)
+ if [ -e $auxBase.bbl ]; then
+ echo "SKIPPING BIBTEX ON $auxFile!"
+ else
+ echo "RUNNING BIBTEX ON $auxFile..."
+ bibtex --terse $auxBase
+ cp $auxBase.bbl $out
+ runNeeded=1
+ fi
+ echo
+ fi
+
+ # "\pgfsyspdfmark" in the aux file seems to indicate that PGF/TikZ
+ # requires a second run (e.g. to resolve arrows between pictures).
+ if grep -q pgfsyspdfmark $auxFile; then
+ runNeeded=1
+ fi
+done
+
+
+if test "$runNeeded"; then
+ echo "PASS 2..."
+ runLaTeX
+ echo
+fi
+
+
+if test -f $rootNameBase.idx; then
+ echo "MAKING INDEX..."
+ if test -n "$compressBlanksInIndex"; then
+ makeindexFlags="$makeindexFlags -c"
+ fi
+ makeindex $makeindexFlags $rootNameBase.idx
+ runNeeded=1
+ echo
+fi
+
+
+if test "$runNeeded"; then
+ echo "PASS 3..."
+ runLaTeX
+ echo
+fi
+
+
+if test "$runNeeded"; then
+ echo "PASS 4..."
+ runLaTeX
+ echo
+fi
+
+
+if test "$runNeeded"; then
+ echo "Hm, still not done :-("
+ echo
+fi
+
+
+if test -n "$generatePDF"; then
+ cp $rootNameBase.pdf $out
+else
+ cp $rootNameBase.dvi $out
+ if test -n "$generatePS"; then
+ echo "CONVERTING TO POSTSCRIPT..."
+ dvips $rootNameBase.dvi -o $out/$rootNameBase.ps
+ echo
+ fi
+fi
+
+
+echo "WARNINGS:"
+cat $tmpFile | grep "Warning:" | grep -v "Citation.*undefined" || true
+
+echo
+echo "OVERFULL/UNDERFULL:"
+cat $tmpFile | egrep "Overfull|Underfull" || true
+
+echo
+echo "UNDEFINED REFERENCES:"
+cat $tmpFile | grep "Reference.*undefined" || true
+
+echo
+echo "UNDEFINED CITATIONS:"
+cat $tmpFile | grep "Citation.*undefined" || true
+
+echo
+echo "STATS:"
+printf "%5d overfull/underfull h/vboxes\n" $(cat $tmpFile | egrep -c "Overfull|Underfull" || true)
+printf "%5d undefined references\n" $(cat $tmpFile | grep -c "Reference.*undefined" || true)
+printf "%5d undefined citations\n" $(cat $tmpFile | grep -c "Citation.*undefined" || true)
+printf "%5d pages\n" \
+ $(cat $tmpFile | grep "Output written.*(.*pages" | sed "s/.*(\([0-9]*\) pages.*/\1/" || true)
+echo
+
+bzip2 $tmpFile