ftilmann / latexdiff

Compares two latex files and marks up significant differences between them. Releases on www.ctan.org and mirrors
GNU General Public License v3.0
513 stars 72 forks source link

Bug: \hspace{0pt} after \mbox{..} causes error with newer versions of LaTeX and ulem #218

Closed gpelouze closed 3 years ago

gpelouze commented 3 years ago

Summary

As described in this Stackexchange post, using latexdiff with latest versions of LaTeX and citation commands produces the following error:

ERROR: Extra }, or forgotten \endgroup.

Steps to reproduce

The bug can be reproduced with pdfTeX 3.14159265-2.6-1.40.21, ulem 2019/11/18, and the following files:

old.tex

\documentclass{article}
\usepackage{hyperref}
\begin{document}
Some text \cite{reference}, and some more text.

\bibliography{my_bib}
\end{document}

new.tex

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\bibliography{my_bib}
\end{document}

Running latexdiff old.tex new.tex > diff.tex produces the following diff.tex file (unused parts of the header have been removed for clarity):

\documentclass{article}
\usepackage{hyperref}

\RequirePackage[normalem]{ulem} %DIF PREAMBLE
\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} %DIF PREAMBLE
\providecommand{\DIFdeltex}[1]{{\protect\color{red}\sout{#1}}}                      %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{\texorpdfstring{\DIFdeltex{#1}}{}} %DIF PREAMBLE

\begin{document}
\DIFdelbegin \DIFdel{Some text \mbox{%DIFAUXCMD
\cite{reference}}\hspace{0pt}%DIFAUXCMD
, and some more text.
}\DIFdelend 

\bibliography{my_bib}
\end{document}

Upon compilation, it produces the following error:

! Extra }, or forgotten \endgroup.
\UL@stop ...z@ \else \UL@putbox \fi \else \egroup 
                                                  \egroup \UL@putbox \fi \if...
l.15 }
      \DIFdelend

Reason for the bug

The culprit seems to be the \hspace{0pt}. (Removing it from diff.tex suppresses the error and results in the expected document.)

It was added in latexdiff v1.2.1: “introduce an invisible space (\hspace{0pt} after \mbox{..} auxiliary commands (not in math mode), to allow line breaks between added and deleted citations” (changelog).

Proposed solution

Replacing the \hspace{0pt} statement with its TeX equivalent \hskip0pt seems to fix the issue, while still allowing line breaks between added and deleted citations.

This can be implemented by replacing the following line:

push(@$retval,"\\mbox{$AUXCMD\n\\" . $1 . $2 . $3 ."}\\hspace{0pt}$AUXCMD\n" );

by

push(@$retval,"\\mbox{$AUXCMD\n\\" . $1 . $2 . $3 ."}\\hskip0pt$AUXCMD\n" );
xiang-yu commented 2 years ago

@gpelouze has this issue been fixed? As long as the "\cite{}" exists regardless of \hsapce{0pt} from Latexdiff, the complilation fails. I am using Overleaf with TexLive 2021 (2020, 2019, and 2018 does not work neither).

ftilmann commented 2 years ago

@xiang-yu can you provide an MWE. The merge request from @gpelouze is supposed to have fixed this, and worked at least for me (on TexLive 2019/Debian). Have you verified that your version of latexdiff contains the fix?

xiang-yu commented 2 years ago

@ftilmann Thanks. latexdiff 1.3.2 did the trick.