latexdiff - determine and markup differences between two latex files latexdiff [ OPTIONS ] old.tex new.tex > diff.tex Briefly, latexdiff is a utility program to aid in the management of revisions of latex documents. It compares two valid latex files, here called old.tex and new.tex, finds significant differences between them (i.e., ignoring the number of white spaces and position of line breaks), and adds special commands to highlight the differences. Where visual highlighting is not possible, e.g. for changes in the formatting, the differences are nevertheless marked up in the source. The program treats the preamble differently from the main document. Differences between the preambles are found using line-based differencing (similarly to the Unix diff command, but ignoring white spaces). A comments, "%DIF >" is appended to each added line, i.e. a line present in new.tex but not in old.tex. Discarded lines are deactivated by prepending "%DIF <". Changed blocks are preceded by comment lines giving information about line numbers in the original files. Where there are insignificant differences, the resulting file diff.tex will be similar to new.tex. At the end of the preamble, the definitions for latexdiff markup commands are inserted. In differencing the main body of the text, latexdiff attempts to satisfy the following guidelines (in order of priority): If both old.tex and new.tex are valid LaTeX, then the resulting diff.tex should also be valid LateX. (NB If a few plain TeX commands are used within old.tex or new.tex then diff.tex is not guaranteed to work but usually will). Significant differences are determined on the level of individual words. All significant differences, including differences between comments should be clearly marked in the resulting source code diff.tex. If a changed passage contains text or text-producing commands, then running diff.tex through LateX should produce output where added and discarded passages are highlighted. Where there are insignificant differences, e.g. in the positioning of line breaks, diff.tex should follow the formatting of new.tex For differencing the same algorithm as diff is used but words instead of lines words are compared. An attempt is made to recognize blocks which are completely changed such that they can be marked up as unit (otherwise readibility is reduced because common words such as "the" and "and" which can be found both in the discarded and added block are considered to be identical text parts and thus not marked up, and added and discarded text parts are interspersed between these common words). Comments are differenced line by line but the number of spaces within comments is ignored. Commands including all their arguments are generally compared as one unit, i.e., no mark-up is inserted into the arguments of commands. However, for a selected number of commands (for example, \caption and all sectioning commands) the last argument is known to be text. This text is split into words and differenced just as ordinary text (use options to show and change the list of text commands, see below). As the algorithm has no detailed knowledge of LaTeX, it assumes all pairs of curly braces immediately following a command (i.e. a sequence of letters beginning with a backslash) are arguments for that command. As a restriction to condition 1 above it is thus necessary to surround all arguments with curly braces, and to not insert extraneous spaces. For example, write \section{\textem{This is an emphasized section title}} and not \section {\textem{This is an emphasized section title}} or \section\textem{This is an emphasized section title} even though all varieties are the same to LaTeX. For environments whose content does not conform to standard LaTeX or where graphical markup does not make sense all markup commands can be removed by setting the PICTUREENV configuration variable (set by default to picture environments; (see --config option). It is also possible to difference files which do not have a preamble. In this case, the file is processed in the main document mode, but the definitions of the markup commands are not inserted. All markup commands inserted by latexdiff begin with "\DIF". Added blocks containing words, commands or comments which are in new.tex but not in old.tex are marked by \DIFaddbegin and \DIFaddend. Discarded blocks are marked by \DIFdelbegin and \DIFdelend. Within added blocks all text is highlighted with \DIFadd like this: \DIFadd{Added text block} Selected `safe' commands can be contained in these text blocks as well (use options to show and change the list of safe commands, see below). All other commands as well as braces "{" and "}" are never put within the scope of \DIFadd. Added comments are marked by prepending "%DIF > ". Within deleted blocks text is highlighted with \DIFdel. Deleted comments are marked by prepending "%DIF < ". Non-safe command and curly braces within deleted blocks are commented out with "%DIFDELCMD < ".

Preamble
The following options determine the visual markup style by adding the appropriate command definitions to the preamble. See the end of this section for a description of available styles. Add code to preamble for selected markup style. This option defines \DIFadd and \DIFdel commands. Available styles: UNDERLINE CTRADITIONAL TRADITIONAL CFONT INVISIBLE CHANGEBAR CCHANGEBAR CULINECHBAR CFONTCBHBAR [ Default: UNDERLINE ] Add code to preamble for selected style for bracketing commands (e.g. to mark changes in margin). This option defines \DIFaddbegin, \DIFaddend, \DIFdelbegin and \DIFdelend commands. Available styles: SAFE MARGINAL COLOR [ Default: SAFE ] Add code to preamble for selected style which replace standard marking and markup commands within floats (e.g., marginal remarks cause an error within floats so marginal marking can be disabled thus). This option defines all \DIF...FL commands. Available styles: FLOATSAFE IDENTICAL [ Default: FLOATSAFE ] Insert file at end of preamble instead of generating preamble. The preamble must define the following commands \DIFaddbegin, \DIFaddend, \DIFadd{..}, \DIFdelbegin,\DIFdelend,\DIFdel{..}, and varieties for use within floats \DIFaddbeginFL, \DIFaddendFL, \DIFaddFL{..}, \DIFdelbeginFL, \DIFdelendFL, \DIFdelFL{..} (If this option is set -t, -s, and -f options are ignored.) Print generated or included preamble commands to stdout.

Configuration
Exclude from, replace or append to the list of regular expressions (RegEx) matching commands which are safe to use within the scope of a \DIFadd or \DIFdel command. The file must contain one PERL-RegEx per line (Comment lines beginning with # or % are ignored). Note that the RegEx needs to match the whole of the token, i.e., /^regex$/ is implied and that the initial "\" of the command is not included. The --exclude-safecmd option can be combined with either of the other two. Exclude from, replace or append to the list of regular expressions matching commands whose last argument is text. See entry for --exclude-safecmd directly above for further details. Set configuration variables. Available variables (see below for further explanations):

MINWORDSBLOCK (integer)

FLOATENV (RegEx) PICTUREENV (RegEx) Print list of RegEx matching and excluding safe commands. Print list of RegEx matching and excluding commands with text argument. Show values of configuration variables NB For all --show commands, no old.tex or new.tex file needs to be specified, and no differencing takes place.

Miscellaneous
Output various status information to stderr during processing. Default is to work silently. Show help text Show version number

Predefined styles

Major types
The major type determine the markup of plain text and some selected latex commands outside floats by defining the markup commands \DIFadd{...} and \DIFdel{...} . Added text is underlined and blue, discarded text is struck out and red (Requires color and ulem packages). Added text is blue and set in sans-serif, and a red footnote is created for each discarded piece of text. (Requires color package) Like CTRADITIONAL but without the use of color. Added text is blue and set in sans-serif, and discarded text is red and very small size. Added text is blue, and discarded text is red. Additionally, the changed text is marked with a bar in the margin (Requires color and changebar packages). Like CFONT but with additional changebars (Requires color and changebar packages). Like UNDERLINE but with additional changebars (Requires color, ulem and changebar packages). No mark up of text, but mark margins with changebars (Requires changebar package). No visible markup (but generic markup commands will still be inserted.

Subtypes
The subtype defines the commands that are inserted at the begin and end of added or discarded blocks, irrespectively of whether these blocks contain text or commands (Defined commands: \DIFaddbegin, \DIFaddend, \DIFdelbegin, \DIFdelend) No additional markup (Recommended choice) Mark beginning and end of changed blocks with symbols in the margin nearby (using the standard \marginpar command - note that this sometimes moves somewhat from the intended position. An alternative way of marking added passages in blue, and deleted ones in red. Note that COLOR subtype creates fatal overflow errors with a number of dvi converters, and its use is thus discouraged (use instead the main types to effect colored markup).

Float Types
Some of the markup used in the main text might cause problems when used within floats (e.g. figures or tables). For this reason alternative versions of all markup commands are used within floats. The float type defines these alternative commands. Use identical markup for text as in the main body, but set all commands marking the begin and end of changed blocks to null-commands. You have to choose this float type if your subtype is MARGIN as \marginpar does not work properly within floats. Make no difference between the main text and floats.

Configuration Variables
Minimum number of tokens required to form an independent block. This value is used in the algorithm to detect changes of complete blocks by merging identical text parts of less than MINWORDSBLOCK to the preceding added and discarded parts. [ Default: 3 ] Environments whose name matches the regular expression in FLOATENV are considered floats. Within these environments, the latexdiff markup commands are replaced by their FL variaties. [ Default: S<figure|table|plate)[\w\d*@]* ] Within environments whose name matches the regular expression in PICTUREENV all latexdiff markup is removed (in pathologic cases this might lead to inconsistent markup but this condition should be rare). [ Default: S<picture)[\w\d*@]* ] The current version is a beta version which has not yet been extensively tested, but worked fine locally. Please send bug reports to tilmann@esc.cam.ac.uk. Include the serial number of latexdiff (from comments at the top of the source or use --version). If you come across latex files that are error-free and conform to the specifications set out above, and whose differencing still does not result in error-free latex, please send me those files, ideally edited to only contain the offending passage as long as that still reproduces the problem. the latexrevise manpage latexdiff does not make use of external commands and thus should run on any platform supporting PERL v5 or higher. The standard version of latexdiff requires installation of the PERL package Algorithm::Diff (available from www.cpan.org - http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15) but a stand-alone version, latexdiff-so, which has this package inlined, is available, too. Copyright (C) 2004 Frederik Tilmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 2