# Problem using latexdiff and pdflatex with custom command

Using latexdiff I have the problem, that by adding new \section, I get the following error by trying to run pdflatex.

! Argument of \UL@word has an extra }.
<inserted text>
\par


Here you can see the redefined \section command...

\renewcommand{\section}{%
\@startsection{section}%
{1}     % Structure level
{0mm}   % Indention
{2ex plus 1ex minus 1ex}            % Pre-Margin
{0.5ex plus 0.5ex minus 0.5ex}      % Post-Margin
}
\renewcommand{\subsection}{%
\@startsection{subsection}%
{2}     % Structure level
{0mm}   % Indention
{1.5ex plus 1ex minus 0.5ex}        % Pre-Margin
{0.3ex plus 0.3ex minus 0.3ex}      % Post-Margin
}


How can I fix the problem? It would work for me also to ignore the changed section names.

(OPs answer, moved from the question.)

I thought it would be more complex, but I found a solution. Using --exclude-textcmd allows the ignoring of tags. It works now.

--exclude-textcmd="section,subsection"

• Where exactly did you put this text? – Veridian Feb 19 '16 at 20:48
• What does now mean? Version 1.1.1? – math Feb 23 '16 at 13:41
• @sphere: it is put as command line argument to latexdiff. – math Feb 23 '16 at 13:41
• would it also work with git latexdiff? – Homero Esmeraldo Jan 15 '20 at 19:26
• @Veridian this should be added as an option of latexdiff command – simona Aug 18 '20 at 23:14

It's difficult without an MWE, but I would assume that the difficulty is with hyperref, which tries to include underlined/crossed out text as hyperlink given that it is part of a chapter.

The solution is to use texorpdfstring, which tells hyperref to use plain text for the hyperlinks. I can't remember the exact commands that latexdiff definds, but try something like that:

% Redefine these commands for chapter/sections and change below
\DeclareRobustCommand{\hsout}[1]{\texorpdfstring{\sout{#1}}{#1}}
\DeclareRobustCommand{\hwave}[1]{\texorpdfstring{\uwave{#1}}{#1}}

%DIF PREAMBLE EXTENSION ADDED BY LATEXDIFF
%DIF UNDERLINE PREAMBLE %DIF PREAMBLE
\RequirePackage[normalem]{ulem}% DIF PREAMBLE
\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1}%DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\textcolor{red}{\hsout{#1}}}}% DIF PREAMBLE
...

• I've tried your solution, but it doesn't work. I get the same errors like before. – aphex Dec 18 '12 at 22:51
• @aphex Then please provide an MWE – Jörg Dec 19 '12 at 9:16
• @Jörg I seem to be suffering from the same issue. In my document i have a section "Conclusions". When i set this as a comment my latexdiff file compiles as normal. However if i have this as a section, the same error appears: Argument of \UL@word has an extra }. <inserted text> \par l.1411 \DIFaddbegin \section{\DIFadd{Conclusion}} – wierts Nov 22 '13 at 14:28

\section{\DIFdelbegin \DIFdel{Conclusion}\DIFdelend \DIFaddbegin \DIFadd{Conclusions}\DIFaddend }


and Jörg's solution did not work for me. What worked was a manual substitution:

\section{\texorpdfstring{\DIFdelbegin \DIFdel{Conclusion}\DIFdelend \DIFaddbegin \DIFadd{Conclusions}\DIFaddend }{Conclusions}}


I had the same problem on a very large document, and based on Jörg suggestion, I just removed the call to hyperref package (and \hypersetup ) in the difference tex file and it compiled fine. Just a fast workaround.

• Disagree. This answer worked better than the others for me. – Anonymous Physicist Sep 17 '16 at 7:07
• If autoref is used from hyperref package, then commenting out hyperref will disable autoref. So, commenting out hyperref is not the best option. – Chee Feb 11 '18 at 17:41

I have something like this: \subsection{\DIFadd{Experimental results added}}, then it got error with MiKTeX.

I change it to this:

\section*{\DIFadd{Experimental results added}}


or \subsection*{\DIFadd{Experimental results added}}, then it's ok but no section numbers.

So I change it again:

\section[]{\DIFadd{Experimental results added}}


or \subsection[]{\DIFadd{Experimental results added}}.

Hope this could solve your problem (not perfect: section number color is still black).

• I added some comments on how to Joeg's solution but they were deleted by Peer Review. Anyway, there seems to have been some misunderstanding on how to use Joeg's solution. So, I am writing on this again. The key to use his solution is to comment out the following two default commands generated by latexdiff: \providecommand{\DIFadd}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE; \providecommand{\DIFdel}[1]{{\protect\color{red}\sout{#1}}} %DIF PREAMBLE – Chee Feb 11 '18 at 18:04