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
506 stars 72 forks source link

New glossary entry makes pdflatex fail #294

Open felixvuo opened 5 months ago

felixvuo commented 5 months ago

I have added a new entry to my glossary and although latexdiff still makes a changes.tex, the generated file no longer compiles to pdf with pdflatex. Here's a minimum (not)working example:

Old:

\documentclass{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[automake,toc,nopostdot,nogroupskip]{glossaries-extra}
\preto\chapter{\glsresetall}
\makeglossaries
\begin{document}
\newglossaryentry{dfs}{
name={depth first search (DFS)},
first={depth first search (DFS)},
text={DFS},
description={Diving headlong into the space.}
}
\frontmatter
\title{Searching}
\author{Me}
\date{Now}
\printglossary[title={Glossary}]
\mainmatter
\chapter{Introduction: Searching for something}
The only way is \gls{dfs}. It's great, \gls{dfs}.
\end{document}

New:

\documentclass{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[automake,toc,nopostdot,nogroupskip]{glossaries-extra}
\preto\chapter{\glsresetall}
\makeglossaries
\begin{document}
\newglossaryentry{dfs}{
name={depth first search (DFS)},
first={depth first search (DFS)},
text={DFS},
description={Diving headlong into the space.}
}
\newglossaryentry{bfs}{
name={breadth-first search (BFS)},
first={breadth-first search (BFS)},
text={BFS},
description={Cautiously exploring all options one step at a time.}
}
\frontmatter
\title{Searching}
\author{Me}
\date{Now}
\printglossary[title={Glossary}]
\mainmatter
\chapter{Introduction: Searching for something}
One way is \gls{dfs} and the other is \gls{bfs}.  They're both great, \gls{dfs} and \gls{bfs}.
\end{document}

Command: latexdiff --append-context2cmd=newglossaryentry mwe-old.tex mwe-new.tex > changes.tex which produces changes.tex with no errors reported

But then pdflatex changes.tex produces:

! Use of \@s@lective@sanitize doesn't match its definition.
\@ifnextchar ... \reserved@d =#1\def \reserved@a {
                                                  #2}\def \reserved@b {#3}\f...
l.64 }

line 64 is the last line, with closing brace, of this snippet:

\DIFaddbegin \newglossaryentry{bfs}{
\DIFadd{name=}{\DIFadd{breadth-first search (BFS)}}\DIFadd{,
first=}{\DIFadd{breadth-first search (BFS)}}\DIFadd{,
text=}{\DIFadd{BFS}}\DIFadd{,
description=}{\DIFadd{Cautiously exploring all options one step at a time.}}
}

Anything I can try to solve this? Many thanks.

ftilmann commented 4 months ago

latexdiff by default excludes from markup all commands except 'white-listed' ones known to contain only text. With the option --append-context2cmd=newglossaryentry you essentially tell latexdiff that \newglossaryentry's second argument is text (see the help page) but this is not true, as it uses some syntax specific to the glossaries-extra package. I am afraid this is not easy to fix. It would require introducing some special logic so that only the parts right of the "=" sign are processed and probably not for all parameters. Something like this would probably be most straightforwardly accomplished in the preprocess subroutine, where the glossary command could somehow be reshaped that those second parts appear as textual argument, and then backtransformed into the required from in the postprocess. I will not fix this, but leave it open in case anybody else feels inspired.

ftilmann commented 4 months ago

The only actual 'fix' is of course to remove the --append-context2cmd option but of course it leaves your changes in the glossary unmarked.