2

How can biblatex citations used in captions of the tufte-book document class?

The following MWE does not work since the \autocite command in the image caption does not properly handled by tufte-book. I assume the marginnote needs to be queued somewhere in tufte-common.def.

% !TeX program = pdflatex
% !TeX encoding = UTF-8
% !TeX spellcheck = en-US
% !BIB program = biber
\documentclass[a4paper,twoside,justified,marginals=raggedright,nobib]{tufte-book}
\usepackage{graphicx}

\usepackage[%
    backend=biber,
    bibstyle=authoryear,
    citestyle=authortitle-icomp,    
    ]{biblatex}%

\addbibresource{biblatex-examples.bib}

\begin{document}
    Citation in text.\autocite{westfahl:space}
    \begin{figure}
        \includegraphics{example-grid-100x100pt}
        \caption{Citation in caption.\autocite{westfahl:space}}
    \end{figure}
\end{document}
  • The problem is that biblatex's footnote detection does not work with the tufte classes (with the tufte classes one should probably consider a caption to be a footnote as well). So \autocite (which branches depending on whether we're in a footnote or not) goes miss, just use \cite and everything is tickety-boo. – moewe Feb 13 '16 at 18:54
2

By default, the Tufte classes are not too fond of you using a \footnote from within a \caption. Since biblatex doesn't know we are using \autocite from within a \caption it defaults to \footcite; indeed since patching the \footnote command failed, biblatex can't even detect it is in a footnote and use \parencite there.

With

\makeatletter
\long\def\@caption#1[#2]#3{%
  \expandafter\ifx\csname if@capstart\expandafter\endcsname
                  \csname iftrue\endcsname
    \global\let\@currentHref\hc@currentHref
  \else
    \hyper@makecurrent{\@captype}%
  \fi
  \@ifundefined{NR@gettitle}{%
    \def\@currentlabelname{#2}%
  }{%
    \NR@gettitle{#2}%
  }%
  \par\addcontentsline{\csname ext@#1\endcsname}{#1}{%
    \protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}%
  }%
  \begingroup
    \toggletrue{blx@footnote}%
    \@parboxrestore
    \if@minipage
      \@setminipage
    \fi
    \@tufte@caption@font\@tufte@caption@justification%
    \expandafter\ifx\csname if@capstart\expandafter\endcsname
                    \csname iftrue\endcsname
      \global\@capstartfalse
      %\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces#3}%
      \noindent\csname fnum@#1\endcsname: \ignorespaces#3%
    \else
      %\@makecaption{\csname fnum@#1\endcsname}{%
      \noindent\csname fnum@#1\endcsname:
        \ignorespaces
        \ifHy@nesting
          \expandafter\hyper@@anchor\expandafter{\@currentHref}{#3}%
        \else
          \Hy@raisedlink{%
            \expandafter\hyper@@anchor\expandafter{%
              \@currentHref
            }{\relax}%
          }%
          #3%
        \fi
      %}%
    \fi
    \par
  \endgroup
}

\renewcommand\@footnotetext[2][0pt]{%
  \marginpar{%
    \hbox{}\vspace*{#1}%
    \def\baselinestretch {\setspace@singlespace}%
    \reset@font\footnotesize%
    \@tufte@margin@par% use parindent and parskip settings for marginal text
    \vspace*{-1\baselineskip}\noindent%
    \protected@edef\@currentlabel{%
       \csname p@footnote\endcsname\@thefnmark%
    }%
    \color@begingroup%
       \toggletrue{blx@footnote}%
       \@makefntext{%
         \ignorespaces#2%
       }%
    \color@endgroup%
  }%
}%
\makeatother

a bastardisation of tufte-common.def's definitions, bits of what hyperref.sty does and patching done by biblatex, footnote detection will work and \captions will be treated as if they were sidenotes by biblatex's tracker.

MWE

\documentclass[a4paper,twoside,justified,marginals=raggedright,nobib]{tufte-book}
\usepackage{graphicx}
\usepackage{mwe}

\usepackage[%
    backend=biber,
    bibstyle=authoryear,
    citestyle=authortitle-icomp,    
    ]{biblatex}%

\addbibresource{biblatex-examples.bib}

\makeatletter
\long\def\@caption#1[#2]#3{%
  \expandafter\ifx\csname if@capstart\expandafter\endcsname
                  \csname iftrue\endcsname
    \global\let\@currentHref\hc@currentHref
  \else
    \hyper@makecurrent{\@captype}%
  \fi
  \@ifundefined{NR@gettitle}{%
    \def\@currentlabelname{#2}%
  }{%
    \NR@gettitle{#2}%
  }%
  \par\addcontentsline{\csname ext@#1\endcsname}{#1}{%
    \protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}%
  }%
  \begingroup
    \toggletrue{blx@footnote}%
    \@parboxrestore
    \if@minipage
      \@setminipage
    \fi
    \@tufte@caption@font\@tufte@caption@justification%
    \expandafter\ifx\csname if@capstart\expandafter\endcsname
                    \csname iftrue\endcsname
      \global\@capstartfalse
      %\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces#3}%
      \noindent\csname fnum@#1\endcsname: \ignorespaces#3%
    \else
      %\@makecaption{\csname fnum@#1\endcsname}{%
      \noindent\csname fnum@#1\endcsname:
        \ignorespaces
        \ifHy@nesting
          \expandafter\hyper@@anchor\expandafter{\@currentHref}{#3}%
        \else
          \Hy@raisedlink{%
            \expandafter\hyper@@anchor\expandafter{%
              \@currentHref
            }{\relax}%
          }%
          #3%
        \fi
      %}%
    \fi
    \par
  \endgroup
}

\renewcommand\@footnotetext[2][0pt]{%
  \marginpar{%
    \hbox{}\vspace*{#1}%
    \def\baselinestretch {\setspace@singlespace}%
    \reset@font\footnotesize%
    \@tufte@margin@par% use parindent and parskip settings for marginal text
    \vspace*{-1\baselineskip}\noindent%
    \protected@edef\@currentlabel{%
       \csname p@footnote\endcsname\@thefnmark%
    }%
    \color@begingroup%
       \toggletrue{blx@footnote}%
       \@makefntext{%
         \ignorespaces#2%
       }%
    \color@endgroup%
  }%
}%
\makeatother

\begin{document}
    Citation in text.\autocite{westfahl:space}
    \begin{figure}
        \includegraphics{example-grid-100x100pt}
        \caption{Citation in caption. \autocite{westfahl:space}}
    \end{figure}
\end{document}

example output

1

I found a manual workaround based on Using \footnote in a figure's \caption, but I would prefer an automated solution.

% !TeX program = pdflatex
% !TeX encoding = UTF-8
% !TeX spellcheck = en-US
% !BIB program = biber
\documentclass[a4paper,twoside,justified,marginals=raggedright,nobib]{tufte-book}
\usepackage{graphicx,lipsum}

\usepackage[%
    backend=biber,
    bibstyle=authoryear,
    citestyle=authortitle-icomp,    
    ]{biblatex}%

\addbibresource{biblatex-examples.bib}

\usepackage{ftnxtra}
\begin{document}
    Citation in text.\autocite{westfahl:space}
    \begin{figure}
        \includegraphics{example-grid-100x100pt}
        \caption{Citation in caption.\footnotemark}
    \end{figure}
    \footnotetext{\cite{westfahl:space}}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.