Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing preamble for included packages fails for multiline commands #13

Closed
alexpacini opened this issue Feb 22, 2015 · 10 comments
Closed
Labels

Comments

@alexpacini
Copy link

Running latexdiff (LATEXDIFF 1.0.4 (Algorithm::Diff 1.1902, Perl v5.18.2)) with changes inside section or subsection I got:

Argument of \UL@word has an extra } ...begin\DIFadd{Some Text}\DIFaddend}

I found that applying what advised in http://tex.stackexchange.com/questions/87536/problem-using-latexdiff-and-pdflatex-with-custom-command
solves the problem.

In particular:

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{\DIFadd}[1]{{\protect\textcolor{blue}{\hwave{#1}}}}% DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\textcolor{red}{\hsout{#1}}}}% DIF PREAMBLE

Even --exclude-textcmd="section,subsection" works, but I lose the edits into the subsection.

Thanks, Alex

@ftilmann
Copy link
Owner

As you say the solution posted in Stack Exchange worked for you, is there still an issue I should try to look at? If so please clarify.

@alexpacini
Copy link
Author

Well, It worked for me but I think this should be automatic.
It is really annoying to be obliged to modify the latexdiff output each time by editing:

%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{\DIFadd}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\color{red}\sout{#1}}}                      %DIF PREAMBLE

with

% 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{\DIFadd}[1]{{\protect\textcolor{blue}{\hwave{#1}}}}% DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\textcolor{red}{\hsout{#1}}}}% DIF PREAMBLE

Thus, yes, I think would be better to look at the problem.

@ftilmann
Copy link
Owner

OK, I get your point and marked this as a feature request; might be a few weeks until fix due to other commitments. The solution will probably be to offer a special style UNDERLINE_HYPERREF (or similar) which you have to select with -t option, and print a warning to stderr if default style is combined with hyperref.
In the meantime you can copy/paste the preamble extension added by latexdiff into its own file, make the required modifications, and then use --preamble option to avoid having to do the edit each time.

@alexpacini
Copy link
Author

Do you mean to use --preamble=mypreamble.tex where mypreamble.tex is

% 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{\DIFadd}[1]{{\protect\textcolor{blue}{\hwave{#1}}}}% DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\textcolor{red}{\hsout{#1}}}}% DIF PREAMBLE
%DIF SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
%DIF FLOATSAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddFL}[1]{\DIFadd{#1}} %DIF PREAMBLE
\providecommand{\DIFdelFL}[1]{\DIFdel{#1}} %DIF PREAMBLE
\providecommand{\DIFaddbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFaddendFL}{} %DIF PREAMBLE
\providecommand{\DIFdelbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFdelendFL}{} %DIF PREAMBLE
%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF

Yep, waiting the -t option, it works. Thank you!

@ftilmann
Copy link
Owner

ftilmann commented Feb 23, 2015 via email

@ftilmann
Copy link
Owner

I looked into this but actually this should already be fixed in 1.0.4. If latexdiff detects the hyperref package, it should redefine the \DIFadd and \DIFdel formats along the lines outlined in the Stack Exchange answer.
You can force it to adopt these with the option --packages=hyperref.
In any case it would be very helpful if you could provide an MWE (minimum working example) for me to figure out what is going wrong, as I failed to reproduce this (maybe there is a package similar to hyperref but having a different name)

@alexpacini
Copy link
Author

I am trying to give a MWE, but it could be not the shortest one since I took it from the article I am writing.

First file: testold.tex

\documentclass[a4paper, 11pt]{article}
\addtolength{\textwidth}{3.6cm}
\addtolength{\hoffset}{-1.8cm}
\addtolength{\voffset}{-1.8cm}
\addtolength{\textheight}{1.8cm}
\usepackage[pdftex]{graphicx}
\usepackage[square, comma, sort&compress]{natbib}
\usepackage[utf8x]{inputenc}
\usepackage{amssymb, amsmath, mathtools, mathrsfs}
\usepackage[english]{babel}
\usepackage{microtype, url}
\usepackage[bookmarks=true, hidelinks, 
pdftitle={Title},
pdfauthor={Name Surname}, 
pdfkeywords={}]{hyperref}
\usepackage{hypernat}
\renewenvironment{abstract}[0]
{\noindent\normalfont\normalsize\itshape}{\par\vskip 9mm}
\renewcommand{\bibsection}{\section*{REFERENCES}}
\newcommand{\acknowledgements}{\section*{ACKNOWLEDGEMENTS}}
\newcommand{\appendices}{\section*{APPENDIX}}
\def\thesection {\Roman{section}}
\def\thesubsection {\Alph{subsection})}
\def\thesubsubsection {\arabic{subsubsection})}
\renewcommand{\cite}[1]{\citep{#1}}

\author{Name Surname}
\title{Title}

\begin{document}
    \section{INTRODUCTION1}
    test
\end{document}

Second file: testnew.tex

\documentclass[a4paper, 11pt]{article}
\addtolength{\textwidth}{3.6cm}
\addtolength{\hoffset}{-1.8cm}
\addtolength{\voffset}{-1.8cm}
\addtolength{\textheight}{1.8cm}
\usepackage[pdftex]{graphicx}
\usepackage[square, comma, sort&compress]{natbib}
\usepackage[utf8x]{inputenc}
\usepackage{amssymb, amsmath, mathtools, mathrsfs}
\usepackage[english]{babel}
\usepackage{microtype, url}
\usepackage[bookmarks=true, hidelinks, 
pdftitle={Title},
pdfauthor={Name Surname}, 
pdfkeywords={}]{hyperref}
\usepackage{hypernat}
\renewenvironment{abstract}[0]
{\noindent\normalfont\normalsize\itshape}{\par\vskip 9mm}
\renewcommand{\bibsection}{\section*{REFERENCES}}
\newcommand{\acknowledgements}{\section*{ACKNOWLEDGEMENTS}}
\newcommand{\appendices}{\section*{APPENDIX}}
\def\thesection {\Roman{section}}
\def\thesubsection {\Alph{subsection})}
\def\thesubsubsection {\arabic{subsubsection})}
\renewcommand{\cite}[1]{\citep{#1}}

\author{Name Surname}
\title{Title}

\begin{document}
    \section{INTRODUCTION2}
    test
\end{document}

Now: latexdiff testold.tex testnew.tex > testdiff.tex

The errors should come out.


Edit:
Forcing with --packages=hyperref it works

@ftilmann
Copy link
Owner

ftilmann commented Mar 2, 2015

The parser as it stands cannot cope with the \usepackage command being distributed over several lines (and is possibly additionally confused by the complex options; I have not tested this).
This is a legimitate use case, though, so I treat this as a bug, which will be fixed for the next release.

@ftilmann ftilmann added the bug label Mar 2, 2015
@ftilmann ftilmann changed the title Problem using latexdiff and pdflatex with changes inside sections Parsing preamble for included packages fails for multiline commands Mar 2, 2015
@alexpacini
Copy link
Author

Perfect. Will wait it.

Thanks again, Alex.

@ftilmann
Copy link
Owner

ftilmann commented Mar 8, 2015

Fixed with commit a8eb8d9

@ftilmann ftilmann closed this as completed Mar 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants