2 # Gadget to take two LaTeX files and produce a third which
3 # has changebars highlighting the difference between them.
7 # Don Ward, Careful Computing (don@careful.co.uk)
9 # v1.1 Feb 93 Amended to use changebar.sty (v3.0) and dvips
12 # chbar file1 file2 [output]
13 # (default output is stdout)
15 # (new file on stdin, output on stdout)
18 # 1 Use diff to get an ed script to go from file1 to file2.
19 # 2 Breathe on it a bit (with sed) to insert changebar commands.
20 # 3 Apply modified ed script to produce (nearly) the output.
21 # 4 Use awk to insert the changebars option into the \documentstyle
22 # and to handle changebar commands inside verbatim environments.
23 # 5 Remove changebars before \begin{document} with sed
27 chbars old new [output]
32 # Strictly speaking, should check that $TMP doesn't exist already.
37 then NEW="-"; # arg is old file, take new from stdin
41 # sed commands to edit ed commands to edit old file
47 /^[0-9][0-9]*,[0-9][0-9]*[ac]$/a\
53 /^[0-9][0-9]*,[0-9][0-9]*d$/a\
58 diff -b -e $OLD $NEW | ( sed -f $TMP ; echo w ${TMP}1 ; echo q ) | ed - $OLD
59 # awk commands to insert Changebars style and to protect
60 # changebar commands in verbatim environments
61 # and to tell what driver is in use
64 if (index($0, "changebar") == 0 ) {
67 printf "%schangebar,%s",substr($0,1,opts),substr($0,opts+1)
69 printf "\\documentstyle[changebar]%s\n", substr($0,15)
73 /\\begin{document}/ {print "%\\driver{dvips}"}
74 /\\begin{verbatim}/{++nesting}
75 /\\end{verbatim}/{--nesting}
76 /\\cbstart{}%|\\cbend{}%|\cbdelete{}%/ {
78 # changebar command in a verbatim environment: Temporarily exit,
79 # do the changebar command and reenter.
81 # The obvious ( printf "\\end{verbatim}%s\\begin{verbatim} , $0 )
82 # leaves too much vertical space around the changed line(s).
83 # The following magic seeems to work
85 print "\\end{verbatim}\\nointerlineskip"
86 print "\\vskip -\\ht\\strutbox\\vskip -\\ht\\strutbox"
87 printf "\\vbox to 0pt{\\vskip \\ht\\strutbox%s\\vss}\n", $0
88 print "\\begin{verbatim}"
94 awk -f $TMP ${TMP}1 >${TMP}2
95 # sed commands to clean up unwanted changebars
96 # (those before \begin{document})
98 # 1,/\\begin{document}/s/\\\\cb[sed][tne][adl][^{}]*{}%$/%/
100 # if test $# -le 2 || test $3 = '-'
101 # then sed -f $TMP ${TMP}2
102 # else sed -f $TMP ${TMP}2 >$3