#!/bin/sh # Test driver for 'pwebmac.tex' in combination with various TeX engines. # Production tool for all major WEB programs in TeX Live (invoked as # './makeall --new --pdftocfront --tex={pdftex,xetex}'). # Public domain. Originally written by Andreas Scherer, 2020. LONGOPTS=changes,new,outdir:,pdftocfront,tex: SHRTOPTS=cno:pt: CHANGES=false # apply main changefile to WEB source NEW=false # '\input pwebmac' instead of '\input webmac' OUTDIR=. # path where the resulting tarballs are placed PDFTOCFRONT=false # push table-of-contents to front of PDF output TEX=tex # or 'pdftex' or 'xetex' getopt -T >/dev/null if [ $? -eq 4 ] # Check for Linux-getopt with extensions then OPTS=$(getopt -n downloadable-programs -o $SHRTOPTS -l $LONGOPTS -- "$@") else OPTS=$(getopt $SHRTOPTS $*) fi if [ $? -eq 0 ] # Check return code from getopt then eval set -- $OPTS else echo "Failed to parse options." >&2; exit 1 fi while true do case "$1" in -c | --changes ) CHANGES=true; shift ;; -n | --new ) NEW=true; shift ;; -o | --outdir ) OUTDIR="$2"; shift 2 ;; -p | --pdftocfront ) PDFTOCFRONT=true; shift ;; -t | --tex ) TEX=$2; shift 2 ;; -- ) shift; break ;; * ) break ;; esac done KNUTHWHERE=$(locate /bibtex.web) KNUTHWARE=$(dirname $KNUTHWHERE) export CWEBINPUTS=$KNUTHWARE//: export WEBINPUTS=$KNUTHWARE//: if [ xetex = $TEX ] then CWEAVE="cweave -f -lp+" else CWEAVE="cweave -f" fi CTWILL="ctwill -f +lpdf" # WEB and CWEB programs we want to get formatted for f in \ $KNUTHWARE/*.web pdftex.web xetex.web \ common ctangle cweave ctwill ctie tie do f=$(basename $f .web) if [ ctwill = $f ] then # amend TeX Live's 'prod-twill.w' for (c)twill'ing if [ ! -e prod-twill.w ] then tie -m prod-twill.w prod-twill.w prod-mini.ch fi # apply tons of editorial changes to 'ctwill.w' CWEBINPUTS=.:$CWEBINPUTS \ ctie -m $f.w cweave.w $f-w2c.ch $f-mini.ch cp -an $KNUTHWARE/cwebdir/*.bux . $CTWILL $f $CTWILL $f elif $CHANGES then # pdftex.ch and xetex.ch for TeX Live are assembled here WEBINPUTS=$KNUTHWARE/../../Work//:$WEBINPUTS: case $f in common ) $CWEAVE $f comm-w2c ;; ctangle ) $CWEAVE $f ctang-w2c ;; cweave ) $CWEAVE $f cweav-w2c ;; ctie ) $CWEAVE $f $f-k ;; tie ) $CWEAVE $f $f-w2c ;; * ) weave $f $f ;; esac # FIX: XeTeX uses '\pdfTeX' from section 114, which # is not changed and thus 'disappears' if [ xetex = $f ] then sed -i -e "s/\(\\\\let\\\\maybe\)/\\\\def\\\\pdfTeX{pdf\\\\TeX}\n\1/" \ $f.tex fi # only document changed modules/sections sed -i -e "s/\(\\\\let\\\\maybe=\)\\\\iftrue/\1\\\\iffalse/" \ $f.tex else case $f in c* | tie ) $CWEAVE $f ;; * ) weave $f ;; esac fi if $NEW then # use extended WEB macros for TeX Live PDF documentation sed -i -e "1 s/\\\\input webmac/\\\\input pwebmac/" $f.tex # timestamp on table-of-contents page or the first page case $f in c* | tie ) ;; # do nothing for CWEB programs bibtex | patgen | tangle | weave ) sed -i -e "s/\(\\\\def\\\\title\)/\\\\datecontentspage\n\1/" $f.tex ;; mf | tex | pdftex | xetex ) sed -i -e "s/\(\\\\def\\\\botofcontents\)/\\\\datethis\n\1/" $f.tex # amend '\N' redefinition for PDF outlines in # Metafont and TeX (also pdfTeX and XeTeX) # 'pwebmac' defines headers differently sed -i -e "s/\(\\\\outer\\\\def\\\\N.*{\)/\1%/" \ -e "s/\\\\def\\\\rhead\(.*}\)/\\\\gtitle=\1\\\\MN#1.\\\\vfill\\\\eject/" \ $f.tex # active links in PDF outlines/bookmarks cat > texmf-pdf.patch << FI \ifacro{\toksF={}\makeoutlinetoks{[#2] #3}\outlinedone\outlinedone}\fi FI sed -i -e "/\\\\outer\\\\def\\\\N/ { r texmf-pdf.patch }" $f.tex cat > texmf-pdf.patch << FI \ifpdf\special{pdf: outline 0 << /Title (\the\toksE) /Dest [ @thispage /FitH @ypos ] >>}\fi FI sed -i -e "/ \\\\edef\\\\next/ { r texmf-pdf.patch }" $f.tex rm texmf-pdf.patch ;; * ) sed -i -e "s/\(\\\\def\\\\botofcontents\)/%\1/" \ -e "s/ \\\\centerline{\(\\\\hsize\)/\\\\def\\\\covernote{\1/" \ -e "s/\(Publishing Company.}}\)}/\1\n\\\\datecontentspage/" \ -e "s/\(trademark of the American Mathematical Society.}}\)}/\1\n\\\\datecontentspage/" \ $f.tex ;; esac fi # replace former convention to indicate "not a title page" # to include page headers for table-of-contents # FIX: most of the WEB codes will be corrected. sed -i -e "s/\\\\def\\\\titlepage{F}/\\\\titlefalse/" $f.tex # special treatment for individual (C)WEB programs case $f in # purge conflict between bibtex.web and webmac.tex # 'E' no longer free to be active character # fix table-of-contents page for bibtex # FIX: don't wait for Oren Patashnik. bibtex ) sed -i -e "s/titlefalse/titletrue/" $f.tex if ! $CHANGES then sed -i -e "71,78d" $f.tex fi ;; # make room for new material in weave.web # FIX: should be fixed upstream. tangle ) sed -i -e "s/number{123}/number{125}/" $f.tex ;; # FIX: purge obsolete macros from XeTeX xetex ) sed -i -e "/\\\\input xewebmac/d" $f.tex ;; # Use nicer format for C comments and assignment common | ctangle | cweave | ctie | tie ) # sans ctwill sed -i -e "1 s/\(cwebmac\)/\1\n\\\\input Xcwebmac/" \ $f.tex ;; esac # shift table-of-contents pages to the front in PDF if $PDFTOCFRONT && [ ctwill != $f ] then sed -i -e "0,/\\\\N[1{]/s/\(\\\\N[1{]\)/\\\\input pdfwebtocfront\n\n\1/" \ $f.tex # only XeTeX can process XETEX.WEB if [ xetex = $f ] then $f $f # run TeX twice else $TEX $f # run TeX twice fi fi # only XeTeX can process XETEX.WEB if [ xetex = $f ] then $f $f else $TEX $f fi if [ ctwill = $f ] then # sort mini-indexes ctwill-refsort < $f.ref > $f.sref $TEX $f fi done # Finally, build the remaining documents # * TeX and Metafont test routines # * WEB and CWEB manuals if ! $CHANGES then export TEXINPUTS=./:$(kpsewhich --var-value=TEXMFDIST)//:$KNUTHWARE// # FIX: Prepare 'trapman' for automatic processing; several input # files are renamed in TeX Live (in fact, there are additional # files for MetaPost). rm -f trapman.tex cwebman.tex f=$(kpsewhich -engine tex trapman) tie -m $(basename $f) $f /opt/github/web/$(basename $f .tex).ch # Prepare 'cwebman' with footnotes describing the extended CWEB. f=$(kpsewhich -engine tex cwebman) tie -m $(basename $f) $f $(basename $f .tex)-w2c.ch for f in trip trap web cweb do $TEX ${f}man done fi if $PDFTOCFRONT then # create tarballs for publication if $CHANGES then for f in *.pdf do mv $f $(basename $f .pdf)-changes.pdf done pax vftovp-changes.pdf vptovf-changes.pdf \ -wvzf "$OUTDIR/etc-changes.tar.gz" -s ,^,etc/, pax mf-changes.pdf -wvzf "$OUTDIR/mf-changes.tar.gz" -s ,^,mf/, pax gftodvi-changes.pdf gftopk-changes.pdf \ gftype-changes.pdf mft-changes.pdf \ -wvzf "$OUTDIR/mfware-changes.tar.gz" -s ,^,mfware/, pax tex-changes.pdf -wvzf "$OUTDIR/tex-changes.tar.gz" -s ,^,tex/, pax dvitype-changes.pdf pltotf-changes.pdf \ pooltype-changes.pdf tftopl-changes.pdf \ -wvzf "$OUTDIR/texware-changes.tar.gz" -s ,^,texware/, pax tangle-changes.pdf weave-changes.pdf \ -wvzf "$OUTDIR/web-changes.tar.gz" -s ,^,web/, pax bibtex-changes.pdf \ -wvzf "$OUTDIR/bibtex-changes.tar.gz" -s ,^,bibtex/, pax dvicopy-changes.pdf patgen-changes.pdf \ pktogf-changes.pdf pktype-changes.pdf \ -wvzf "$OUTDIR/other-changes.tar.gz" -s ,^,other/, pax pdftex-changes.pdf \ -wvzf "$OUTDIR/pdftex-changes.tar.gz" -s ,^,pdftex/, pax xetex-changes.pdf \ -wvzf "$OUTDIR/xetex-changes.tar.gz" -s ,^,xetex/, pax ctie-changes.pdf \ -wvzf "$OUTDIR/ctie-changes.tar.gz" -s ,^,ctie/, pax tie-changes.pdf \ -wvzf "$OUTDIR/tie-changes.tar.gz" -s ,^,tie/, pax common-changes.pdf ctangle-changes.pdf cweave-changes.pdf \ -wvzf "$OUTDIR/cweb-changes.tar.gz" -s ,^,cweb/, else pax vftovp.pdf vptovf.pdf -wvzf "$OUTDIR/etc.tar.gz" -s ,^,etc/, pax mf.pdf trapman.pdf -wvzf "$OUTDIR/mf.tar.gz" -s ,^,mf/, pax gftodvi.pdf gftopk.pdf gftype.pdf mft.pdf \ -wvzf "$OUTDIR/mfware.tar.gz" -s ,^,mfware/, pax tex.pdf tripman.pdf -wvzf "$OUTDIR/tex.tar.gz" -s ,^,tex/, pax dvitype.pdf pltotf.pdf pooltype.pdf tftopl.pdf \ -wvzf "$OUTDIR/texware.tar.gz" -s ,^,texware/, pax webman.pdf tangle.pdf weave.pdf \ -wvzf "$OUTDIR/web.tar.gz" -s ,^,web/, pax bibtex.pdf -wvzf "$OUTDIR/bibtex.tar.gz" -s ,^,bibtex/, pax dvicopy.pdf patgen.pdf pktogf.pdf pktype.pdf \ -wvzf "$OUTDIR/other.tar.gz" -s ,^,other/, pax pdftex.pdf -wvzf "$OUTDIR/pdftex.tar.gz" -s ,^,pdftex/, pax xetex.pdf -wvzf "$OUTDIR/xetex.tar.gz" -s ,^,xetex/, pax ctie.pdf -wvzf "$OUTDIR/ctie.tar.gz" -s ,^,ctie/, pax tie.pdf -wvzf "$OUTDIR/tie.tar.gz" -s ,^,tie/, pax cwebman.pdf common.pdf ctangle.pdf cweave.pdf ctwill.pdf \ -wvzf "$OUTDIR/cweb.tar.gz" -s ,^,cweb/, fi fi exit 0