# Why does manually loading hyperref change the font size for captions in Tufte documents?

I'm using Tufte document classes and need to manually load hyperref rather than have it loaded by the Tufte class. So I'm using the nohyper option with the document class, and later use \usepackage{hyperref} in code.

When I do this, the font size for captions (though not footnotes) changes to that of body text:

\documentclass[nohyper]{tufte-handout}
\usepackage{inputenc}
\usepackage{graphicx}

\usepackage[pdftex,hyperfootnotes=false]{hyperref}

\begin{document}
Body text.
\begin{marginfigure}
\includegraphics[width=1\columnwidth]{agraphic}\caption{Caption text}
\end{marginfigure}

\end{document}


If I remove the \usepackage[...]{hyperref} line, the caption font size is correct (whether I specify nohyper or not). As near as I can tell, except for some link coloring details and metadata assignment, I'm doing exactly the same thing that the Tufte class would do without the nohyper option.

-
Is the option hyperfootnotes=false the reason why you would load hyperref yourself? – Herbert Mar 5 '12 at 15:03
Two great answers, each with a different emphasis. My needs are to preserve Tufte while getting as much of hyperref as I can get, so my choose is Altermundus's; but Werner's is more concise and appropriate for other uses. – raxacoricofallapatorius Mar 5 '12 at 19:15
then always use \PassOptionsToPackage{...}{hyperref} before \documentclass, then you do not need all that tricks – Herbert Mar 5 '12 at 19:17

I know where the problem comes from but I'm not sure if my workaround is correct. Hyperref modifies \caption

Update code with diabonas's comment

\documentclass[nohyper]{tufte-handout}
\usepackage{inputenc}
\usepackage{graphicx}
\makeatletter
\let\tufte@caption\@caption
\usepackage[hyperfootnotes=false]{hyperref}
\let\@caption\tufte@caption
\begin{document}
Body text.
\begin{marginfigure}
\includegraphics[width=1\columnwidth]{guilloche.png}\caption{Caption text}
\end{marginfigure}

\end{document}


-
I think you shouldn't restore \caption as it isn't changed by tufte-handout (only locally in a float environment) and you will lose the hyperref-specific change like this. (You can check yourself by using \show\caption both with and without the noyper option.) Otherwise, this workaround (i.e. restoring only \@caption) is fine. – diabonas Mar 5 '12 at 11:22
Werner's answer (and the support for it) suggests that that "minimal intervention" is preferred; but this seems to do a better job of ensuring I get the Tufte captions intact. Is that true? What features of hyperref do I disable by taking this approach (vs. the one in Werner's answer)? – raxacoricofallapatorius Mar 5 '12 at 14:40
@raxacoricofallapatorius I agree that a minimal intervention is preferable but it's difficult to know if hyperref makes others modifications. You need to look at the complete code of \@caption. In one case you need to load "etoolbox" it's a fine package but some users prefer to load a "minimal" number of pacakges. You can use the minimal one (from Werner) and if you need other modifications, you can always use the second. – Alain Matthes Mar 5 '12 at 14:53
@raxacoricofallapatorius Altermundus' solution is closer to what tufte-handout does itself: You get exactly the same definition of \@caption if you load hyperref implicitly in the document class (i.e. without the nohyper option). So as things work (or break) exactly the same way as they do in the unmodified version, there is no additional source of error here. – diabonas Mar 5 '12 at 15:02

hyperref does indeed modify \@caption. If font is the only concern, then the following patch is sufficient:

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd
{\@caption}% <cmd>
{\normalsize}% <search>
{\@tufte@caption@font\@tufte@caption@justification}% <replace>
{\typeout{caption patched}}% <success>
{}% <failure
\makeatother


It stems from hyperref issuing \normalsize within \@caption (a subsidiary macro called from within \caption) which resets the font. The above patch replaces that with the regular Tufte-class components.

Why is this required even though you do "exactly the same as loading hyperref at class-level? Because the class loads hyperref first, and then redefines its own \caption and \@caption macros, overwriting that of hyperref. In that sense, @Altermundus' answer is sufficient as well.

-
Thanks! You say "if font is the only concern"; are there other (insidious, not readily apparent) things I should be concerned about if I load hyperref before Tufte? – raxacoricofallapatorius Mar 5 '12 at 14:38
@Altermundus: It looks like there might be. – raxacoricofallapatorius May 23 '12 at 1:06