2

At my work place we have an official LaTeX document class that we are supposed to use. I am writing a report using this class and biblatex for my references. It works great, except for one quirk: in the list of figures, citations appearing within captions are replaced by the label of the corresponding bibtex entry. To illustrate, consider the following MWE, with the class file stripped down to the very bare minimum:

\begin{filecontents*}{\jobname.bib}
@Article{foo1970,
  author =   {Foo, B. and others},
  title =    {Frobtzing the frob},
  journal =      "J.\ Frob.",
  year =     1970}
\end{filecontents*}

\begin{filecontents*}{mweclass.cls}
\def\fileversion{2.0}
\def\filedate{2010/06/15}
\def\docdate {2010/06/15}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mweclass}[\filedate\space v\fileversion\space MWE class]

\ProcessOptions\relax

\LoadClassWithOptions{article}

\AtBeginDocument{
  \listoffigures
  \clearpage
}
\end{filecontents*}

\documentclass{mweclass}

\usepackage[backend=biber,style=authoryear]{biblatex}
\usepackage[demo]{graphicx}

\addbibresource{\jobname.bib}

\begin{document}

\begin{figure}
  \centering
  \includegraphics{test}
  \caption{This cites \textcite{foo1970}.}
\end{figure}

\printbibliography[heading=bibnumbered]

\end{document}

If I compile this (with pdflatex), I get this:

the label appears instead of the text citation

However, if I move the \AtBeginDocument command out of the class file and I put it right before \begin{document}, I get the expected result:

expected result

I have tried \protecting the \textcite command, but it does not make any difference.

As per @moewe's suggestion, I also tried adding the following snippet to the class file (from his/her answer to this question):

\AtEndPreamble{%
  \addtocontents{toc}{%
    \booltrue{citerequest}\relax}%
  \addtocontents{lof}{%
    \booltrue{citerequest}\relax}%
  \addtocontents{lot}{%
    \booltrue{citerequest}\relax}}

but unfortunately it makes no difference as long as the \AtBeginDocument command appears in the class file (and actually results in some undefined references).

What's up with this? How do I convince pdflatex to put the same text in the list of figures and in the figure caption?

Arek' Fu
  • 123

1 Answers1

2

You may fix your class using etoolbox package (to use \AtEndPreamble):

\begin{filecontents*}{\jobname.bib}
@Article{foo1970,
  author =   {Foo, B. and others},
  title =    {Frobtzing the frob},
  journal =      "J.\ Frob.",
  year =     1970}
\end{filecontents*}

\begin{filecontents*}{mweclass.cls}
\def\fileversion{2.0}
\def\filedate{2010/06/15}
\def\docdate {2010/06/15}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mweclass}[\filedate\space v\fileversion\space MWE class]

\ProcessOptions\relax

\LoadClassWithOptions{article}

\RequirePackage{etoolbox}
\AtEndPreamble{
  \AtBeginDocument{
    \listoffigures
    \clearpage
  }
}

\end{filecontents*}

\documentclass{mweclass}

\usepackage[demo]{graphicx}

\usepackage[backend=biber,style=authoryear]{biblatex}

\AtEndPreamble{%
  \addtocontents{toc}{%
    \booltrue{citerequest}\relax}%
  \addtocontents{lof}{%
    \booltrue{citerequest}\relax}%
  \addtocontents{lot}{%
    \booltrue{citerequest}\relax}}

\addbibresource{\jobname.bib}

\begin{document}

\begin{figure}
  \centering
  \includegraphics{test}
  \caption{This cites \protect\textcite{foo1970}.}
\end{figure}

\printbibliography[heading=bibnumbered]

\end{document}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
  • This works! I had to move around some \newcolumntype commands in the original class file and I do not really understand why, but it solved my problem. – Arek' Fu Oct 20 '16 at 11:06
  • Incidentally, I don't need the \addtocontents{*}{\booltrue{citerequest}\relax} commands. It works fine without them. – Arek' Fu Oct 20 '16 at 14:59