1

I have used the answer from Access the original label in cleveref's \crefformat to access the label of a cleveref reference. This worked fine until I through latexdiff into the game. Now, my highly simplified diff result looks like this:

\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{cleveref}

% https://tex.stackexchange.com/questions/319410/
\usepackage{xpatch}
\makeatletter
\apptocmd{\cref@getref}{\xdef\@lastusedlabel{#1}}{}{error}
\crefformat{section}{the #2``\nameref*{\@lastusedlabel}''#3 section}
\makeatother

% latexdiff preamble
\RequirePackage[normalem]{ulem}
\providecommand{\DIFadd}[1]{\texorpdfstring{\DIFaddtex{#1}}{#1}}
\providecommand{\DIFaddtex}[1]{\uwave{#1}}

\begin{document}
    \section{\DIFadd{Foo}}
    \label{foo}

    \DIFadd{\mbox{\cref{foo}}}
\end{document}

The error message is ! Dimension too large. \UL@on ...UL@height \advance \UL@height -\ULdepth

My guess is that I need to \protect one of the commands, but I can't really tell which one.

bers
  • 5,404

1 Answers1

1

You need to protect \DIFadd inside of \section. This is because \section writes its argument to the .aux file in order to allow support for things like a table of contents, but if you used any counters or local definitions in the argument to \section, you want those to be correctly defined when written into the table of contents. Thus, \section first recursively expands its argument before writing it to the .aux file. However, \DIFadd doesn't like to be recursively expanded. Saying \section{\protect\DIFadd{foo}} or defining \DIFadd using \DeclareRobustCommand will solve your problem.

Hood Chatham
  • 5,467
  • Replacing \section{\DIFadd{Foo}} by \section{\protect\DIFadd{Foo}} does not change anything (I had tried that - forgot to mention it). Also, replacing \providecommand{\DIFadd}[1]{\texorpdfstring{\DIFaddtex{#1}}{#1}} by \DeclareRobustCommand{\DIFadd}[1]{\texorpdfstring{\DIFaddtex{#1}}{#1}} (or the same with \DIFaddtex) does not help. Not even doing all three does anything, it seems. – bers Dec 01 '16 at 00:24
  • Try removing \DIFadd around \mbox{\cref{foo}}. – Hood Chatham Dec 01 '16 at 03:19
  • Yes, that might work. But this is what latexdiff puts. It would be hard for me to find out when to remove \DIFadd, automatically. – bers Dec 01 '16 at 03:21