latexdiff icon indicating copy to clipboard operation
latexdiff copied to clipboard

achemso class + multiple authors, latexdiff misses revisions to title

Open dwsideriusNIST opened this issue 7 years ago • 5 comments

I've discovered a rather specific bug in latexdiff:

If using the "achemso" class in a document with multiple authors, latexdiff will fail to highlight revisions to the title block. For example, start with this document:

\documentclass[journal = langd5, manuscript=article]{achemso} \setkeys{acs}{articletitle = true} \title{This is the NEW title.} \author{Author T. One}\email{[email protected]} \altaffiliation{Corresponding Author} \affiliation{First Affiliation} \author{Writer B. Two} \affiliation{Second Affiliation} \date{\today} \begin{document} \begin{abstract} The abstract. \end{abstract} \maketitle \newpage \section{Introduction}\label{sec:intro} A paragraph. \end{document}

Make a change to the \title{} block, then run latexdiff on the two files and the title changes will be not be caught or marked in the diff file. On the other hand, comment out the "\author{Writer B. Two}" and "\affiliation{Second Affiliation}" lines, then latexdiff works just fine.

This seems specific to achemso, as using latexdiff on the following RevTeX document works just fine:

\documentclass[preprint,pre,showkeys,12pt,superscriptaddress,nofootinbib]{revtex4-1} \begin{document} \title{This is the NEW title.} \author{Author T. One}\email{[email protected]} \affiliation{First Affiliation} \author{Writer B. Two} \affiliation{Second Affiliation} \date{\today} \begin{abstract} The abstract. \end{abstract} \maketitle \newpage \section{Introduction}\label{sec:intro} A paragraph. \end{document}

Anyone have a clue as to why this is happening? Perhaps there is some interaction with the achemso class behind the scenes that I'm missing?

EDIT: I've tracked this a bit deeper. The achemso-specificity is due to the fact that the achemso class puts the \author{} blocks in the preamble, not after \begin{document}.

EDIT 2: Newer releases give the following error:

WARNING: author is used twice in preamble of old file. Reverting to pure line diff mode for preamble. This should not occur for standard styles, but can occur for some specifiy styles, document classes, e.g. journal house styles. Workaround: Use --replace-context2cmd option to specifically set those commands, which are not repeated.

I can suppress the error by including the flag --replace-context2cmd="\author", but the diff still fails to catch the title change.

dwsideriusNIST avatar Dec 08 '17 15:12 dwsideriusNIST

I also recently came across the same issue. I posted in on stackexchange too, in case there is another workaround. My questions is here:

Latexdiff and achemso not showing changes to the title

michemistry avatar Apr 05 '22 23:04 michemistry

Something very similar seems to happen with wlpeerj.cls, the current PeerJ latex template:

$ latexdiff new.tex old.tex > diff.tex
WARNING: author is used twice in preamble of old file. Reverting to pure line diff mode for preamble.
     This should not occur for standard styles, but can occur for some specific styles, document classes,
     e.g. journal house styles.
     Workaround: Use --replace-context2cmd option to specifically set those commands, which are not repeated.

As above, this silences the warning:

$ latexdiff --replace-context2cmd="\author" new.tex old.tex > diff.tex

However in both cases I am not seeing the changes to my abstract (in my case the title was unchanged) in the resulting PDF.

peterjc avatar May 15 '23 09:05 peterjc

Same problem here with wlpeerj.cls https://github.com/rstudio/rticles/blob/main/inst/rmarkdown/templates/peerj/skeleton/wlpeerj.cls

Using --replace-context2cmd="\author" silences the warning but there is no changes traced in the title nor in the abstract.

When I suppress all authors except one, I don't have the warning anymore and the changes appear in the title but not in the abstract. So maybe, there is more than one problem here ?

GillesSanMartin avatar Sep 18 '23 12:09 GillesSanMartin

There is also a problem in that this warning should be output on stderr and not on stdout, which means the outputted tex file is corrupted.

stain avatar Nov 16 '23 00:11 stain

@stain, what version of latexdiff are you using? I'm using latexdiff 1.3.1a and it prints the warning to stderr.

I don't think this behaviour is a bug, but is in fact "by design". You should be seeing the differences annotated in the generated tex diff file -- they just don't show up in a pdf generated by compiling the diff.

Citing the manual (p.7):

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 cur- rently 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 --replace-context2cmd option to just select the commands, which should be processed and are not used repeatedly in the preamble.

So the problem is that latexdiff doesn't do word-by-word processing (which produces the pdf markup) on commands that appear in the preamble more than once. It tries to process only the preamble commands that are in the "context2" list; if it sees any command in this list repeated, it switches to a line diff mode for the entire preamble, which means it won't compare and mark up the text arguments of any those commands (e.g., the title). Instead, you'll only find the changed lines marked up in tex with it's diff comment format (much like what's produced by the diff command):

%DIF 8c8
%DIF < \title{Old title}
%DIF -------
\title{New title} %DIF > 
%DIF -------

These being comments, they disappear when the diff tex is compiled.

The workaround is to use --replace-context2cmd to specify the commands that do not appear more than once in the preamble and thus latexdiff can process word-by-word (you can use --show-textcmd to print out the list). With wlpeerj.cls something like this should do the trick:

latexdiff --replace-context2cmd='title,date,institute,corrauthor' old.tex new.tex > diff.tex

This results in changes to the arguments of \title, \date, etc. to be marked up with \DIFadd, \DIFdel etc. to produce the markup in the compiled diff file.

Unfortunately, for repeated other commands, such as \author and \affil in wlpeerj.cls, the only solution I've found is to mark them up manually in the diff.tex before compiling the final pdf. An even bigger problem I have is getting latexdiff to process word-by-word the content of an environment in the preamble (specifically the abstract in wlpeerj).

ilveroluca avatar Nov 30 '23 11:11 ilveroluca