LATEXDIFF(1)
okay so bestie, this is the latexdiff manual page, and it's literally the tool for determining and marking up differences between two latex files. Buckle up, because this one is thorough in the most iconic way ๐
.
๐ NAME ๐
latexdiff โ determine and markup differences between two latex files โจ
๐ธ SYNOPSIS ๐ธ
latexdiff [ OPTIONS ] old.tex new.tex > diff.tex
๐ฆ DESCRIPTION ๐ฆ
Briefly, latexdiff is a utility program that helps you manage 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. Note that old.tex and new.tex need to be real files (not pipes or similar) as they are opened twice (unless the --encoding option is used).
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 comment, %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.texandnew.texare valid LaTeX, then the resultingdiff.texshould also be valid LateX. (NB If a few plain TeX commands are used withinold.texornew.texthendiff.texis 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.texthrough 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.texshould follow the formatting ofnew.tex.
For differencing, the same algorithm as diff is used but words instead of lines are compared. An attempt is made to recognize blocks which are completely changed such that they can be marked up as a unit. 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 (but see --allow-spaces option which allows the second variety).
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 and DIFnomarkup environments; see --config option). The latter environment (DIFnomarkup) can be used to protect parts of the latex file where the markup results in illegal markup. You have to surround the offending passage in both the old and new file by \begin{DIFnomarkup} and \end{DIFnomarkup}. You must define the environment in the preambles of both old and new documents. I prefer to define it as a null-environment,
\newenvironment{DIFnomarkup}{}{}
but the choice is yours. Any markup within the environment will be removed, and generally everything within the environment will just be taken from the new file.
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 < .
๐ OPTIONS ๐
๐ง 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.
--type=markupstyle,-t markupstyleโ Add code to preamble for selected markup style. This option defines\DIFaddand\DIFdelcommands. Available styles:
UNDERLINE CTRADITIONAL TRADITIONAL CFONT FONTSTRIKE INVISIBLE
CHANGEBAR CCHANGEBAR CULINECHBAR CFONTCHBAR BOLD PDFCOMMENT
LUAUNDERLINE
Default: UNDERLINE
--subtype=markstyle,-s markstyleโ Add code to preamble for selected style for bracketing commands (e.g. to mark changes in margin). This option defines\DIFaddbegin,\DIFaddend,\DIFdelbeginand\DIFdelendcommands. Available styles:SAFE MARGIN COLOR DVIPSCOL ZLABEL ONLYCHANGEDPAGE (LABEL)*
Default: SAFE
โ ๏ธ Heads up: subtype LABEL is deprecated ๐
--floattype=markstyle,-f markstyleโ 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...FLcommands. Available styles:FLOATSAFE TRADITIONALSAFE IDENTICAL
Default: FLOATSAFE
--encoding=enc,-e encโ Specify encoding ofold.texandnew.tex. Typical encodings areascii,utf8,latin1,latin9. A list of available encodings can be obtained by executing
perl -MEncode -e 'print join ("\n",Encode-"encodings( ":all" )) ;'
>
If this option is used, then old.tex, new.tex are only opened once. Default encoding is utf8 unless the first few lines of the preamble contain an invocation \usepackage[..]{inputenc} in which case the encoding chosen by this command is assumed. Note that ASCII (standard latex) is a subset of utf8.
--preamble=file,-p fileโ 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-foptions are ignored.)--packages=pkg1,pkg2,..โ Tell latexdiff that .tex file is processed with the packages in list loaded. This is normally not necessary if the .tex file includes the preamble, as the preamble is automatically scanned for\usepackagecommands. Use of the--packagesoption disables automatic scanning, so if for any reason package specific parsing needs to be switched off, use--packages=none. The following packages trigger special behaviour:endfloatโ Ensure that\begin{figure}and\end{figure}always appear by themselves on a line.hyperrefโ Change name of\DIFaddand\DIFdelcommands to\DIFaddtexand\DIFdeltexand define new\DIFaddand\DIFdelcommands, which provide a wrapper for these commands, using them for the text but not for the link defining command (where any markup would cause errors).apacite,biblatexโ Redefine the commands recognised as citation commands.siunitxโ Treat\SIas equivalent to citation commands (i.e. protect with\mboxif markup style uses ulem package.cleverefโ Treat\cref,\Cref, etc as equivalent to citation commands (i.e. protect with\mboxif markup style uses ulem package.glossariesโ Define most of the glossaries commands as safe, protecting them with\mbox'es where neededmhchemโ Treat\ceas a safe command, i.e. it will be highlighted (note that\ceewill not be highlighted in equations as this leads to processing errors)chemformulaorchemmacrosโ Treat\chas a safe command outside equations, i.e. it will be highlighted (note that\chwill not be highlighted in equations as this leads to processing errors)
Default: scan the preamble for \usepackage commands to determine loaded packages.
๐ Configuration ๐
--exclude-safecmd=exclude-file,-A exclude-file,--exclude-safecmd="cmd1,cmd2,..."--replace-safecmd=replace-file--append-safecmd=append-file,-a append-file,--append-safecmd="cmd1,cmd2,..."
Okay so these three besties let you exclude from, replace, or append to the list of regular expressions (RegEx) that match commands which are safe to use inside the scope of a \DIFadd or \DIFdel command ๐
. The file has to contain one Perl-RegEx per line (comment lines starting with # or % get ignored, ngl they're just vibes). Heads up: the RegEx needs to match the whole of the token, i.e. /^regex$/ is implied, and the initial \ of the command is not included. The --exclude-safecmd and --append-safecmd options can be combined with the ---replace-safecmd option and can be used repeatedly to add cumulatively to the lists. โจ
--exclude-safecmd and --append-safecmd can also take a comma separated list as input. If a comma for one of the regex is required, escape it thus \,. In most cases it will be necessary to protect the comma-separated list from the shell by putting it in quotation marks ๐ซถ.
--exclude-textcmd=exclude-file,-X exclude-file,--exclude-textcmd="cmd1,cmd2,..."--replace-textcmd=replace-file--append-textcmd=append-file,-x append-file,--append-textcmd="cmd1,cmd2,..."
Same energy, but for the list of regular expressions matching commands whose last argument is text ๐. See the entry for --exclude-safecmd directly above for further details (it's literally the same rules, just a different list, iykyk).
--replace-context1cmd=replace-file--append-context1cmd=append-file,--append-context1cmd="cmd1,cmd2,..."
Replace or append to the list of regex matching commands whose last argument is text but which need a particular context to work โ like, \caption will only work within a figure or table, bestie ๐. These commands behave like text commands, except when they occur in a deleted section โ then they get disabled, but their argument is still shown as deleted text. Iconic behaviour honestly.
--replace-context2cmd=replace-file--append-context2cmd=append-file,--append-context2cmd="cmd1,cmd2,..."
As corresponding commands for context1. The only difference is that context2 commands are completely disabled in deleted sections, including their arguments ๐.
context2 commands are also the only commands in the preamble whose argument will be processed in word-by-word mode (which only works if they occur no more than once in the preamble). The algorithm currently cannot cope with repeated context2 commands in the preamble, as they occur e.g. for the \author argument in some journal styles (not in the standard styles, though). If such a repetition is detected, the whole preamble will be processed in line-by-line mode. In such a case, use the --replace-context2cmd option to just select the commands which should be processed and are not used repeatedly in the preamble ๐ญ.
--exclude-mboxsafecmd=exclude-file,--exclude-mboxsafecmd="cmd1,cmd2,..."--append-mboxsafecmd=append-file,--append-mboxsafecmd="cmd1,cmd2,..."
Define safe commands which additionally need to be protected by encapsulating in an \mbox{..} ๐. This is sometimes needed to get around incompatibilities between external packages and the ulem package, which is used for highlighting in the default style UNDERLINE as well as CULINECHBAR CFONTSTRIKE ๐ฆ.
--config var1=val1,var2=val2,...or-c var1=val1,..-c configfile
Set configuration variables ๐ . The option can be repeated to set different variables (as an alternative to the comma-separated list). Available variables (see below for further explanations):
ARRENV(RegEx)COUNTERCMD(RegEx)CUSTODIFCMD(RegEx)FLOATENV(RegEx)ITEMCMD(RegEx)LISTENV(RegEx)MATHARRENV(RegEx)MATHENV(RegEx)MATHREPL(String)MAXCHANGESLETTER(Integer)MINWORDSBLOCK(Integer)PICTUREENV(RegEx)SCALEDELGRAPHICS(Float)
--add-to-config varenv1=pattern1,varenv2=pattern2,...
For configuration variables that are a regular expression (essentially those ending in ENV, COUNTERCMD and CUSTOMDIFCMD, see list above), this option is an alternative way to modify them ๐ธ. Instead of setting the complete pattern, with this option it's possible to add an alternative pattern. varenv must be one of the variables listed above that take a regular expression as argument, and pattern is any regular expression (which might need to be protected from the shell by quotation). Several patterns can be added at once by using semi-colons to separate them, e.g. --add-to-config "LISTENV=myitemize;myenumerate,COUNTERCMD=endnote" ๐ง
--show-preambleโ Print generated or included preamble commands. ๐--show-safecmdโ Print list of RegEx matching and excluding safe commands.--show-textcmdโ Print list of RegEx matching and excluding commands with text argument.--show-configโ Show values of configuration variables. โจ--show-allโ Combine all--showcommands. ๐
NB For all--showcommands, the behaviour is different dependent whetherold.texornew.texfiles are specified ๐. If they are not specified, then the initial setup is shown. If they are specified, then the full configuration is shown, which includes some additions of internal commands, and modifications based on what packages are present on the system, or are used in the.texfiles. Either way, no differencing takes place. Periodt.
โจ Other configuration options โจ
--allow-spacesโ Allow spaces between bracketed or braced arguments to commands ๐. Note that this option might have undesirable side effects (unrelated scope might get lumped with preceding commands) so it should only be used if the default produces erroneous results ๐ซถ. (Default requires arguments to directly follow each other without intervening spaces.)--math-markup=levelโ Determine granularity of markup in displayed math environments ๐ฅ. Possible values for level are (both numerical and text labels are acceptable):offor0: suppress markup for math environments. Deleted equations will not appear in the diff file. This mode can be used if all the other modes cause invalid latex code.wholeor1: Differencing on the level of whole equations. Even trivial changes to equations cause the whole equation to be marked changed. This mode can be used if processing in coarse or fine mode results in invalid latex code.coarseor2: Detect changes within equations marked up with a coarse granularity; changes in equation type (e.g.displaymathtoequation) appear as a change to the complete equation. This mode is recommended for situations where the content and order of some equations are still being changed. [Default]fineor3: Detect small change in equations and mark up at fine granularity. This mode is most suitable if only minor changes to equations are expected, e.g. correction of typos. ๐ธ
--graphics-markup=levelโ Change highlight style for graphics embedded with\includegraphicscommands ๐. Possible values for level:none,offor0: no highlighting for figuresnew-onlyor1: surround newly added or changed figures with a blue frame [Default if graphicx package loaded]bothor2: highlight new figures with a blue frame and show deleted figures at reduced scale, and crossed out with a red diagonal cross. Use configuration variableSCALEDELGRAPHICSto set size of deleted figures.
Note that changes to the optional parameters will make the figure appear as changed to latexdiff, and this figure will thus be highlighted ๐.
In some circumstances Misplaced \noalign error can occur if there are certain types of changes in tables. In this case please use --graphics-markup=none as a work-around ๐.
--no-delโ Suppress deleted text from the diff. It is similar in effect to theBOLDstyle, but the deleted text is not just invisible in the output โ it is also not included in the diff text file. This can be more robust than just making it invisible ๐ญ.--disable-citation-markupor--disable-auto-mboxโ Suppress citation markup and markup of other vulnerable commands in styles usingulem(UNDERLINE,FONTSTRIKE,CULINECHBAR) (the two options are identical and are simply aliases ๐ซถ).--enable-citation-markupor--enforce-auto-mboxโ Protect citation commands and other vulnerable commands in changed sections with the\mboxcommand, i.e. use default behaviour forulempackage for other packages (the two options are identical and are simply aliases โจ).
๐ Miscellaneous ๐
--verboseor-Vโ Output various status information to stderr during processing ๐ . Default is to work silently (which, honestly, same).--driver=typeโ Choose driver for thechangebarpackage (only relevant for styles usingchangebar:CCHANGEBARCFONTCHBARCULINECHBARCHANGEBAR) ๐ฅ. Possible drivers are listed in the changebar manual, e.g.pdftex,dvips,dvitops[Default: pdftex]--ignore-warningsโ Suppress warnings about inconsistencies in length between input and parsed strings and missing characters ๐. These warning messages are often related to non-standard latex or latex constructions with a syntax unknown tolatexdiffbut the resulting difference argument is often fully functional anyway, particularly if the non-standard latex only occurs in parts of the text which have not changed. So like, don't panic ๐ซถ.--label=labelor-L labelโ Sets the labels used to describe the old and new files ๐. The first use of this option sets the label describing the old file and the second use of the option sets the label for the new file, i.e. set both labels like this-L labelold -L labelnew๐. [Default: use the filename and modification dates for the label]--no-labelโ Suppress inclusion of old and new file names as comment in output file ๐.--visible-labelโ Include old and new filenames (or labels set with the--labeloption) as visible output โญ.--flattenโ ok so this one goes in and replaces every\inputand\includecommand inside the body with the actual content of the files they point at ๐. If\includeonlyis chillin' in the preamble, then only those files get expanded into the document, no cap. Important bit though: no recursion is done โ meaning\inputand\includecommands sitting inside the included sections do not get expanded by this. The included files are assumed to be located in the same directories as the old and new master files respectively, which is what makes it possible to organise files into old and new directories ๐๏ธ. Oh and also,--flattenis applied recursively, so inputted files can contain further\inputstatements. It also handles files included by the import package (\importand\subimport), plus the\subfilecommand.
Heads up bestie: using this option might result in prohibitive processing times for larger documents, and the resulting difference document no longer reflects the structure of the input documents ๐ญ.
--filter-script=filterscriptโ runs files through this filterscript (full path preferred) before processing. The filterscript must take STDIN input and output to STDOUT. When you couple it with--flatten, each file gets run through the filter as it's brought in ๐ซถ.--ignore-filter-stderrโ when running with--filter-script, STDERR from the script may cause readability issues. Flip this flag on to just ignore STDERR from the filter script ๐.--helpor-hโ show help text โจ--versionโ show version number ๐
๐ ๏ธ Internal options
These ones are mostly for automated use by latexdiff-vc. You can use them directly, but ngl the API should be considered less stable than for the other options ๐
.
--no-linksโ suppress generation of hyperreferences, used for minimal diffs (option--only-changesoflatexdiff-vc).
๐ Predefined styles ๐
๐ Major types
The major type determines the markup of plain text and some selected latex commands outside floats, by defining the markup commands \DIFadd{...} and \DIFdel{...} โจ.
UNDERLINEโ added text is wavy-underlined and blue, discarded text is struck out and red (Requires color and ulem packages). Overstriking does not work in displayed math equations such that deleted parts of equation are underlined, not struck out (this is a shortcoming inherent to the ulem package) ๐ฌ.LUAUNDERLINEโ added text is underlined and blue, discarded text is struck out and red (Requires lua-ul package + LuaLaTeX) ๐ฆ.CTRADITIONALโ added text is blue and set in sans-serif, and a red footnote is created for each discarded piece of text (Requires color package).TRADITIONALโ likeCTRADITIONALbut without the use of color ๐ธ.CFONTโ added text is blue and set in sans-serif, and discarded text is red and very small size ๐.FONTSTRIKEโ added tex is set in sans-serif, discarded text small and struck out ๐.CCHANGEBARโ 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) ๐.CFONTCHBARโ likeCFONTbut with additional changebars (Requires color and changebar packages).CULINECHBARโ likeUNDERLINEbut with additional changebars (Requires color, ulem and changebar packages).CHANGEBARโ no mark up of text, but mark margins with changebars (Requires changebar package).INVISIBLEโ no visible markup (but generic markup commands will still be inserted ๐ป).BOLDโ added text is set in bold face, discarded is not shown (also see--no-deloption for another possibility to hide deleted text) ๐ช.PDFCOMMENTโ the pdfcomment package is used to underline new text, and mark deletions with a PDF comment. Note that this markup might appear differently or not at all based on the pdf viewer used ๐. The viewer with best support for pdf markup is probablyacroread. This style is only recommended if the number of differences is small.
๐ 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) ๐.
SAFEโ no additional markup (Recommended choice) โMARGINโ mark beginning and end of changed blocks with symbols in the margin nearby (using the standard\marginparcommand โ note that this sometimes moves somewhat from the intended position ๐ ).COLORโ an alternative way of marking added passages in blue, and deleted ones in red. (It is recommeneded to use instead the main types to effect colored markup, although in some cases coloring with dvipscol can be more complete, for example with citation commands).DVIPSCOLโ an alternative way of marking added passages in blue, and deleted ones in red. Note thatDVIPSCOLonly works with the dvips converter, e.g. not pdflatex โ ๏ธ. (it is recommeneded to use instead the main types to effect colored markup, although in some cases coloring with dvipscol can be more complete).ZLABELโ can be used to highlight only changed pages, but requires post-processing. It is recommend to not call this option manually but uselatexdiff-vcwith--only-changesoption. Alternatively, use the script given within preamble of diff files made using this style ๐ท๏ธ.ONLYCHANGEDPAGEโ also highlights changed pages, without the need for post-processing, but might not work reliably if there is floating material (figures, tables) ๐ฌ.LABELโ is similar toZLABEL, but does not need the zref package and works less reliably (deprecated) ๐.
๐ง 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 โจ.
FLOATSAFEโ 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 isMARGINas\marginpardoes not work properly within floats ๐ซถ.TRADITIONALSAFEโ mark additions the same way as in the main text. Deleted environments are marked by angular brackets\[and\]and the deleted text is set in scriptscript size. This float type should always be used with theTRADITIONALandCTRADITIONALmarkup types as the\footnotecommand does not work properly in floating environments ๐.IDENTICALโ make no difference between the main text and floats. Simple. Iconic. Periodt ๐ .
๐ง Configuration Variables
ARRENVโ if a match toARRENVis found within an inline math environment within a deleted or added block, then the inlined math is surrounded by\mbox{...}. This is necessary as underlining does not work within inlined array environments ๐งฎ.
[ Default: ARRENV="(?:array|[pbvBV]matrix)" ]
COUNTERCMDโ if a command in a deleted block which is also in the textcmd list matchesCOUNTERCMDthen an additional command\addtocounter{cntcmd}{-1}, where cntcmd is the matching command, is appended in the diff file such that the numbering in the diff file remains synchronized with the numbering in the new file ๐ข.
[ Default: COUNTERCMD="(?:footnote|part|section|subsection|subsubsection|paragraph|subparagraph)" ]
CUSTOMDIFCMDโ this option is for advanced users and allows definition of special versions of commands, which do not work as safe commands ๐งโโ๏ธ.
Commands in CUSTOMDIFCMD that occur in added or deleted blocks will be given an ADD or DEL prefix. The prefixed versions of the command must be defined in the preamble, either by putting them in the preamble of at least the new file, or by creating a custom preamble file (Option --preamble). For example the command \blindtext (from package blindtext) does not interact well with underlining, so that for the standard markup type, it is not satisfactory to define it as a safe command. Instead, a customised versions without underlining can be defined in the preamble:
\newcommand{\DELblindtext}{{\color{red}\blindtext}}
\newcommand{\ADDblindtext}{{\color{blue}\blindtext}}
and then latexdiff should be invoked with the option -c CUSTOMDIFCMD=blindtext.
[ Default: none ]
FLOATENVโ environments whose name matches the regular expression inFLOATENVare considered floats. Within these environments, the latexdiff markup commands are replaced by their FL variaties ๐.
[ Default: "(?:figure|table|plate)[\w\d*@]*" ]
ITEMCMDโ commands representing new item line with list environments ๐.
[ Default: \item ]
LISTENVโ environments whose name matches the regular expression inLISTENVare list environments ๐.
[ Default: "(?:itemize|enumerate|description)" ]
MATHENV,MATHREPLโ if both\beginand\endfor a math environment (environment name matchingMATHENVor\[and\]) are within the same deleted block, they are replaced by a\beginand\endcommands forMATHREPLrather than being commented out โ.
[ Default: MATHENV="(?:displaymath|equation)", MATHREPL="displaymath" ]
MAXCHANGESLETTERโ okay so whenlatexdiffclocks that a single word got swapped out, it tries to be extra and figure out the changes at letter level โจ. But here's the tea: if there are like, a lot of changes, the word was probably just replaced wholesale, and letter-level markup would be straight-up confusing instead of helpful. In that case,latexdifffalls back to showing the replacement at word level. The way it tells the two apart is lowkey simple: it counts the number of distinct additions and deletions (not the number of letters changed, bestie!), and only if they're less than or equal toMAXCHANGESLETTERdoes the letter-level markup get used. Sensible values are0,1, or2๐.0disables letter-level markup completely.1only allows a single addition or deletion โ perfect for a typo correction or changing singular/plural of a verb, but no substitution.2allows one substitution (or two additions or deletions) โ and this will sometimes result in different words being marked up at letter level, e.g.they->therewill show deleted"y"and added"re", which is often not desirable ๐.
[ Default: 1 ]
MINWORDSBLOCKโ the minimum number of tokens required to form an independent block ๐งฑ. This value gets used in the algorithm to detect changes of complete blocks by merging identical text parts of less thanMINWORDSBLOCKto the preceding added and discarded parts.
[ Default: 3 ]
PICTUREENVโ within environments whose name matches the regular expression inPICTUREENV, all latexdiff markup is removed ๐ (in pathologic cases this might lead to inconsistent markup, but that situation should be rare).
[ Default: (?:picture|DIFnomarkup)[\w\d*@]* ]
SCALEDELGRAPHICSโ if--graphics-markup=bothis chosen,SCALEDELGRAPHICSis the factor by which deleted figures will be scaled (i.e.0.5implies they're shown at half linear size) ๐ฆ.
[ Default: 0.5 ]
VERBATIMENVโ a RegEx describing environments like verbatim, whose contents should be taken verbatim. The content of these environments will not be processed in any way: deleted content is commented out, new content is not marked up ๐ธ.
[ Default: "comment" ]
VERBATIMLINEENVโ a RegEx describing environments like verbatim, whose contents should be taken verbatim. The content of environments described byVERBATIMLINEENVare compared in line mode, and changes are marked up using thelistingspackage ๐ฆ. The markup style is set based on the chosen main markup type (Option-t), or on an analysis of the preamble. Note that"listings.sty"must be installed โ if this file is not found, the fallback solution is to treatVERBATIMLINEENVenvironments exactly the same way asVERBATIMENVenvironments.
[ Default: (?:verbatim[*]?|lstlisting ]
๐ DIRECTIVES ๐
Sometimes the output latexdiff produces is just... not it ๐ญ, or some complicated constructions even lead to a difference tex file that leads to an error ๐. It is possible to give latexdiff some hints to control the markup by placing some special comments, termed directives, into the tex file ๐ซถ.
Directives mark blocks by paired BEGIN and END directives. It's important that the directives are written exactly as specified below, i.e., all letters need to be capitalised and there has to be exactly one space between BEGIN/END and the block type. However, after the directive arbitrary comments can be added ๐.
Nesting of blocks or overlapping blocks are not parsed correctly and will cause undefined behaviour โ ๏ธ.
Blocks can be spanning across scope boundaries; they can also be used in the last argument of text commands. If they appear in the arguments of other commands, then latexdiff will assume they were placed before or after the command; it's best to avoid this, though ๐.
โจ DIFADD block โจ
...
%BEGIN DIFADD
...
%END DIFADD
...
Everything enclosed between the %BEGIN DIFADD and %END DIFADD directives will be treated as atomistic addition to the text ๐. The interior will be marked up as added text following the normal rules for what is marked up. A use case for this directive is when a paragraph has been changed substantially but retains some of the phrasing of the original paragraph. As latexdiff prefers to find a minimal difference between two files, such a configuration will usually lead to a fragmented markup, with several added and deleted sentences or parts of sentences and a few remaining phrases marked as unchanged ๐ตโ๐ซ. With the use of this directive it's possible to mark the whole modified segment as new, which will then be marked-up en bloc as new, and the old part as one block of deleted material โ which is usually clearer than the fragmented default markup ๐ฅ. DIFADD block directives must be placed into the body of the new file. Those directives are ignored in the preamble or in the old file.
๐ DIFDEL block ๐
...
%BEGIN DIFDEL
...
%END DIFDEL
...
Everything enclosed between the %BEGIN DIFDEL and %END DIFDEL directives will be treated as atomistic deleted text ๐. The interior will be marked up as deleted text following the normal rules for what is marked up. DIFDEL block directives must be placed into the body of the old file. Those directives are ignored in the preamble or in the new file. The use case is similar to that of the DIFADD blocks, but the hint is placed in the old file ๐. In most cases, it is sufficient to either hint in the old file with a DIFDEL block or in the new file with a DIFADD block and latexdiff will take care of the rest โจ.
๐ฆ DIFNOMARKUP block ๐ฆ
...
%BEGIN DIFNOMARKUP
...
%END DIFNOMARKUP
...
The text between the markers will be included in the diff algorithm but no actual markup will be made in this part of the text. It will show the new text only and suppress the old text ๐. If the text immediately above the DIFNOMARKUP block has been added, a \DIFaddend will be placed directly above the %BEGIN DIFNOMARKUP line and any open \DIFadd command terminated โ equivalently for deleted blocks and for text added or deleted immediately after the %BEGIN DIFNOMARKUP ๐ซถ.
The main purpose of this command is to salvage the situation if latexdiff has produced invalid or visually unacceptable output โ markup in the offending passage can be suppressed by surrounding it with DIFNOMARKUP directives and rerunning latexdiff, thus enabling markup of the rest of the document (but please continue to report such failures of latexdiff as described below, so that latexdiff can be improved ๐). This pair of directives must be placed in the new file and will be ignored in the old file (or the preambles of either file) โญ.
๐ฌ COMMON PROBLEMS AND FAQ ๐ฌ
Bestie, this is the part where we get real about the stuff that will absolutely make you go "wait, why is it doing THAT ๐ญ". Every single one of these is a known thing, you're not broken, and there are fixes. Let's go ๐ซถ
Changed citations result in overfull boxes โ okay so here's the tea ๐ต: there's an incompatibility between the ulem package, which latexdiff uses for underlining and striking out in the UNDERLINE style (aka the default style), and the way citations are generated. To be able to mark up citations properly, they get enclosed with an \mbox command. And because mboxes can't be broken across lines, this procedure frequently results in overfull boxes, possibly obscuring the content as it extends beyond the right margin ๐ฌ. Same thing happens for some other packages too (e.g., siunitx). If this is a problem, you've got several possibilities:
- Use
CFONTtype markup (option-t CFONT): if this markup is chosen, then changed citations are no longer marked up with the wavy line (additions) or struck out (deletions), but are still highlighted in the appropriate color, and deleted text is shown with a different font. Other styles not using theulempackage will also work ๐ - Choose option
--disable-citation-markupwhich turns off the marking up of citations: deleted citations are no longer shown, and added citations are shown without markup. (This was the default behaviour of latexdiff at versions 0.6 and older, fyi.) For custom packages you can define the commands which need to be protected by\mboxwith--append-mboxsafecmdand--excludemboxsafecmdoptions (submit your lists of command as feature request at github page to set the default behaviour of future versions, see section 6 ๐ซถ) - If you are using
luatex >= 1.12.0you can use optionLUAUNDERLINEthat useslua-ulinstead ofulemfor underlining, which does not have this problem (experimental feature โจ)
Changes in complicated mathematical equations result in latex processing errors. โ try option --math-markup=whole. If even that fails, you can turn off mark up for equations with --math-markup=off. Crisis averted ๐
Deleted parts in equations are not struck out but underlined. โ this is a limitation of the ulem package that implements the strike-out, ngl. If you use the amsmath package, then the strike-out command is redefined in such a way that deleted passages are wrapped with \text command; adding \usepackage{amsmath} to your preamble will trigger this behaviour ๐. (If amsmath is not included directly, but imported by another package, latexdiff will not be able to detect its availability; in this case you can give latexdiff a hint with option --packages=amsmath.)
How can I just show the pages where changes had been made? โ use options --s ZLABEL (some postprocessing required) or -s ONLYCHANGEDPAGE. And latexdiff-vc --ps|--pdf with --only-changes option takes care of the post-processing for you (requires zref package to be installed) ๐
The character encoding breaks when running latexdiff from powershell. โ this problem is not limited to latexdiff and has to do with the default settings of powershell in Windows ๐. It is recommended to use cmd instead.
๐ KNOWN BUGS ๐
Option --allow-spaces is not implemented entirely consistently. It breaks the rules that number and type of white space does not matter, as different numbers of inter-argument spaces are treated as significant. Yeah, I know. It's giving "we know, it's on the list" ๐
Please submit bug reports using the issue tracker of the github repository page https://github.com/ftilmann/latexdiff.git, or send them to tilmann -- AT -- gfz-potsdam.de. Include the version 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. If your file relies on non-standard class files, you must include those. I will not look at examples where I have trouble to latex the original files. Fair enough fr fr ๐ซก
๐ SEE ALSO ๐
latexrevise, latexdiff-vc
๐ PORTABILITY ๐
latexdiff does not make use of external commands and thus should run on any platform supporting Perl 5.6 or higher โจ. If files with encodings other than ASCII or UTF-8 are processed, Perl 5.8 or higher is required.
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 ๐. latexdiff-fast requires the diff command to be present.
๐ AUTHOR ๐
Version 1.4.0 Copyright (C) 2004-2024 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 3
Contributors of fixes and additions: V. Kuhlmann, J. Paisley, N. Becker, T. Doerges, K. Huebner, T. Connors, Sebastian Gouezel and many others. Thanks to the many people who sent in bug reports, feature suggestions, and other feedback ๐
And that's a wrap on the whole page, bestie!! ๐ฆ This one shipped from perl v5.38.2, dated 2025-12-30, and it's the LATEXDIFF(1) man page. Now go diff some latex and slay โจ๐
๐ฆ where this page comes from
- alpine 3.24: texmf-dist-binextra-doc 2026.0-r0 ยท LPPL-1.0 AND LPPL-1.1 AND LPPL-1.2 AND LPPL-1.3a AND LPPL-1.3c AND GPL-2.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms