TransWikia.com

Latexdiff and biblatex citation commands

TeX - LaTeX Asked by avs on December 12, 2020

I’m having trouble getting latexdiff to work when using the biblatex citation commands parencite and textcite.

Take old.tex:

documentclass[a4paper]{article}
usepackage[utf8]{inputenc}
usepackage{filecontents}
begin{filecontents}{bibliography.bib}
@article{greenwade93,
    author  = "George D. Greenwade",
    title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
    year    = "1993",
    journal = "TUGBoat",
    volume  = "14",
    number  = "3",
    pages   = "342--351"
}
@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}
end{filecontents}
usepackage[style=apa,backend=biber]{biblatex}
addbibresource{bibliography.bib}
begin{document}

textcite{greenwade93} is the best article on LaTeX parencite{goossens93}.

printbibliography

end{document}

and new.tex:

documentclass[a4paper]{article}
usepackage[utf8]{inputenc}
usepackage{filecontents}
begin{filecontents}{bibliography.bib}
@article{greenwade93,
    author  = "George D. Greenwade",
    title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
    year    = "1993",
    journal = "TUGBoat",
    volume  = "14",
    number  = "3",
    pages   = "342--351"
}
@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}
end{filecontents}
usepackage[style=apa,backend=biber]{biblatex}
addbibresource{bibliography.bib}
begin{document}

textcite{goossens93} is the best book on LaTeX parencite{greenwade93}.

printbibliography

end{document}

Running latexdiff old.tex new.tex > diff.tex gives:

documentclass[a4paper]{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL old.tex   Sun Jul 26 18:28:46 2020
%DIF ADD new.tex   Sun Jul 26 18:28:55 2020
usepackage[utf8]{inputenc}
usepackage{filecontents}
begin{filecontents}{bibliography.bib}
@article{greenwade93,
    author  = "George D. Greenwade",
    title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
    year    = "1993",
    journal = "TUGBoat",
    volume  = "14",
    number  = "3",
    pages   = "342--351"
}
@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}
end{filecontents}
usepackage[style=apa,backend=biber]{biblatex}
addbibresource{bibliography.bib}
%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]{{protectcolor{blue}uwave{#1}}} %DIF PREAMBLE
providecommand{DIFdel}[1]{{protectcolor{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
%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

begin{document}

textcite{DIFdelbegin DIFdel{greenwade93}DIFdelend DIFaddbegin DIFadd{goossens93}DIFaddend } is the best DIFdelbegin DIFdel{article }DIFdelend DIFaddbegin DIFadd{book }DIFaddend on LaTeX DIFdelbegin %DIFDELCMD < parencite{goossens93}%%%
DIFdelend DIFaddbegin parencite{greenwade93}DIFaddend .

printbibliography

end{document}

which, when compiled with pdflatex yields:

enter image description here

The problem is that latexdiff puts the markup commands within the textcite command, which obvious doesn’t work. Adding natbib=true to the biblatex options and changing textcite to citet and parencite to citep gives the correct output:
enter image description here

The documentation (section 4) says:

The following packages trigger special behaviour:

apacite, biblatex
Redefine the commands recognised as citation commands.

Is this a bug in latexdiff or am I missing something?

I’d be happy to use the natbib commands instead, but I am using the code from this answer to to include the author name in the hyperlink.

EDIT: turns out that the code from moewe to include the author(s) in the citation links works perfectly fine when using the natbib command instead of the standard biblatex ones. I have no idea how that works, but it solves my immediate problem.

One Answer

You can add the option --exclude-textcmd=textcite to force latexdiff to treat the textcite command correctly (from latexdiff v1.3.2 this behaviour will be the default if biblatex package is used)

Answered by frederik on December 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP