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

latexdiff with hyperref does not work #198

Closed
nail1962 opened this issue May 8, 2020 · 9 comments
Closed

latexdiff with hyperref does not work #198

nail1962 opened this issue May 8, 2020 · 9 comments

Comments

@nail1962
Copy link

nail1962 commented May 8, 2020

I use package hyperref. Then made "latexdiff --packages=hyperref --no-links old.tex new.tex >diff.tex" and then the compiling diff.tex gives error "TeX capacity exceeded, sorry [input stack size=5000]. ...add{http://dx.doi.org/10.1007/bf02959697}}". The error appears where \href and \DIFadd appears together.

@ftilmann
Copy link
Owner

Sorry, this is not quite enough information. Could you post a minimal example.

@nail1962
Copy link
Author

Ok, step by step.

  1. old file old.tex

\documentclass{article}
\usepackage[hidelinks]{hyperref}
\begin{document}
Bla-bla \cite{p1}
\bibliography{self}
\bibliographystyle{elsarticle-num}
\end{document}

  1. New file with added one reference

\documentclass{article}
\usepackage[hidelinks]{hyperref}
\begin{document}
Bla-bla \cite{p1,p2} new Bla-bla
\bibliography{self}
\bibliographystyle{elsarticle-num}
\end{document}

  1. self.bib file

@book{p1,
author = {Hawking, S W and Ellis, G F R},
publisher = {Cambridge University Press},
title = {{The Large Scale Structure of Space-Time}},
year = {1973},
}
@Article{p2,
author = {Thomson, J J},
journal = {Philos. Mag.},
number = {68},
pages = {229--249},
publisher = {Informa {{}UK{}} Limited},
title = {{On the electric and magnetic effects produced by the
motion of electrified bodies}},
volume = {11},
year = {1881},
doi = {10.1080/14786448108627008},
}

  1. latexdiff --packages=hyperref old.tex new.tex >diff-no-bbl.tex gives good file, which is compiled without error, but has no mark changes in references

  2. The way with errors. I include bbl in tex file:
    5.1) latexpand --expand-bbl old.bbl old.tex -o old-bbl.tex
    5.2) latexpand --expand-bbl new.bbl new.tex -o new-bbl.tex

File old-bbl.tex

\documentclass{article}
\usepackage[hidelinks]{hyperref}
\begin{document}
Bla-bla \cite{p1}
\begin{thebibliography}{1}
\expandafter\ifx\csname url\endcsname\relax
\def\url#1{\texttt{#1}}\fi
\expandafter\ifx\csname urlprefix\endcsname\relax\def\urlprefix{URL }\fi
\expandafter\ifx\csname href\endcsname\relax
\def\href#1#2{#2} \def\path#1{#1}\fi
\bibitem{p1}
S.~W. Hawking, G.~F.~R. Ellis, {The Large Scale Structure of Space-Time},
Cambridge University Press, 1973.
\end{thebibliography}
\bibliographystyle{elsarticle-num}
\end{document}

File new-bbl.tex

\documentclass{article}
\usepackage[hidelinks]{hyperref}
\begin{document}
Bla-bla \cite{p1,p2} new Bla-bla
\begin{thebibliography}{1}
\expandafter\ifx\csname url\endcsname\relax
\def\url#1{\texttt{#1}}\fi
\expandafter\ifx\csname urlprefix\endcsname\relax\def\urlprefix{URL }\fi
\expandafter\ifx\csname href\endcsname\relax
\def\href#1#2{#2} \def\path#1{#1}\fi
\bibitem{p1}
S.~W. Hawking, G.~F.~R. Ellis, {The Large Scale Structure of Space-Time},
Cambridge University Press, 1973.
\bibitem{p2}
J.~J. Thomson, {On the electric and magnetic effects produced by the motion of
electrified bodies}, Philos. Mag. 11 (68) (1881) 229--249.
\newblock \href {http://dx.doi.org/10.1080/14786448108627008}
{\path{doi:10.1080/14786448108627008}}.
\end{thebibliography}
\bibliographystyle{elsarticle-num}
\end{document}

  1. Difference with references: latexdiff --packages=hyperref old-bbl.tex new-bbl.tex >diff-with-bbl.tex
    File diff-with-bbl.tex

\documentclass{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL old-bbl.tex Fri May 15 11:18:01 2020
%DIF ADD new-bbl.tex Fri May 15 11:32:32 2020
\usepackage[hidelinks]{hyperref}
%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{\DIFaddtex}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE
\providecommand{\DIFdeltex}[1]{{\protect\color{red}\sout{#1}}} %DIF PREAMBLE
%DIF SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
\providecommand{\DIFmodbegin}{} %DIF PREAMBLE
\providecommand{\DIFmodend}{} %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 HYPERREF PREAMBLE %DIF PREAMBLE
\providecommand{\DIFadd}[1]{\texorpdfstring{\DIFaddtex{#1}}{#1}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{\texorpdfstring{\DIFdeltex{#1}}{}} %DIF PREAMBLE
%DIF LISTINGS PREAMBLE %DIF PREAMBLE
\RequirePackage{listings} %DIF PREAMBLE
\RequirePackage{color} %DIF PREAMBLE
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE
%DIF DIFCODE_UNDERLINE %DIF PREAMBLE
moredelim=[il][\color{red}\sout]{%DIF\ <\ }, %DIF PREAMBLE
moredelim=[il][\color{blue}\uwave]{%DIF\ >\ } %DIF PREAMBLE
} %DIF PREAMBLE
\lstdefinestyle{DIFverbatimstyle}{ %DIF PREAMBLE
language=DIFcode, %DIF PREAMBLE
basicstyle=\ttfamily, %DIF PREAMBLE
columns=fullflexible, %DIF PREAMBLE
keepspaces=true %DIF PREAMBLE
} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim}{\lstset{style=DIFverbatimstyle}}{} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim*}{\lstset{style=DIFverbatimstyle,showspaces=true}}{} %DIF PREAMBLE
%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF
\begin{document}
Bla-bla \DIFdelbegin \DIFdel{\mbox{%DIFAUXCMD
\cite{p1}
}\hspace{0pt}%DIFAUXCMD
}\DIFdelend \DIFaddbegin \DIFadd{\mbox{%DIFAUXCMD
\cite{p1,p2} }\hspace{0pt}%DIFAUXCMD
new Bla-bla
}\DIFaddend \begin{thebibliography}{1}
\expandafter\ifx\csname url\endcsname\relax
\def\url#1{\texttt{#1}}\fi
\expandafter\ifx\csname urlprefix\endcsname\relax\def\urlprefix{URL }\fi
\expandafter\ifx\csname href\endcsname\relax
\def\href#1#2{#2} \def\path#1{#1}\fi
\bibitem{p1}
S.~W. Hawking, G.~F.~R. Ellis, {The Large Scale Structure of Space-Time},
Cambridge University Press, 1973.
\DIFaddbegin
\bibitem{p2}
\DIFadd{J.~J. Thomson, }{\DIFadd{On the electric and magnetic effects produced by the motion of
electrified bodies}}\DIFadd{, Philos. Mag. 11 (68) (1881) 229--249.
}\newblock \href {\DIFadd{http://dx.doi.org/10.1080/14786448108627008}}
{\path{doi:10.1080/14786448108627008}}\DIFadd{.
}\DIFaddend
\end{thebibliography}
\bibliographystyle{elsarticle-num}
\end{document}

  1. Compilation with pdflatex gives error

TeX capacity exceeded, sorry [input stack size=5000]. ...p://dx.doi.org/10.1080/14786448108627008}}

in line 69:

}\newblock \href {\DIFadd{http://dx.doi.org/10.1080/14786448108627008}}

If delete \DIFadd in this line, then compilation works well and show differences in references. Taking this into account I made simple string sed -i 's/\href {\DIFadd/\href {/g' diff.tex which delete \DIFadd where \href appears. But I think the problem must be solved in latefdiff itself. Could you please take your attention on this problem? In fact I use git-latexdiff, but error appears and I found this error by applying step-by-step all operators without git.

@nail1962 nail1962 reopened this May 15, 2020
@nail1962
Copy link
Author

nail1962 commented May 15, 2020

Sorry, I accidentally closed issue. I reopen now once more.

@ftilmann
Copy link
Owner

Duplicate of #178

@ftilmann ftilmann marked this as a duplicate of #178 May 22, 2020
@nail1962
Copy link
Author

But could you please fix this problem?

@ftilmann
Copy link
Owner

The problem is the space between \href and its argument that is being used by the citation style. This goes against the constraint defined in the latexdiff manual. You can use --allow-spaces option to work around this but it might cause some undesired side effects. As a better fix I am planning to introduce an option to apply this option only to the bibliography but it might take some time, as my work on latexdiff is only a hobby, and I am quite busy otherwise. Instead of using latexexpand you could probably do this

latexdiff old.tex new.tex > diff.tex
latexdiff --allow-spaces old.bbl new.bbl > diff.bbl
xelatex diff.tex
xelatex diff.tex

@nail1962
Copy link
Author

Thank you, it works.

@nail1962
Copy link
Author

nail1962 commented May 23, 2020

I just verified in bitbucket, the following
git latexdiff -t CFONT HEAD~1 --allow-space --bibtex --main proba.tex
is working without problem with adding and deleting references. In fact the key --allow-space solves the problem.

@ftilmann
Copy link
Owner

Should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants