Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm stumped by an error I'm getting, when I try to render a Tufte-LaTeX document using hypcap and hyperref. For example, even a minimal document consisting of

\documentclass[nohyper]{tufte-handout}

\makeatletter
\let\tufte@caption\@caption    % Protect caption from hyperref 
\RequirePackage{hyperref}   
\let\@caption\tufte@caption    % See -- http://tex.stackexchange.com/a/46838 
\makeatother
\RequirePackage[all]{hypcap}   % See -- http://tex.stackexchange.com/a/27349

\begin{document}

\begin{figure}\caption{An empty figure.}\end{figure}

\end{document}

causes an error:

Package hypcap Error: You have forgotten to use \caption.

What is causing this error, and how can I avoid it?


If it comes to it, I'd settle for giving up some features provided by either hypcap of hyperref (e.g., linking to figures) if that's what it takes to keep things stable. I don't want to give up the visible effects of the Tufte style.

share|improve this question
    
I suspect that hypcap is upset about \caption not being defined as expected. –  egreg May 22 '12 at 20:18
    
@egreg: Does hypcap not work with Tufte at all then? Or has hyperref done something? –  raxacoricofallapatorius May 22 '12 at 23:50
    
hypcap uses the interface of hyperref located in the definition of \@caption patched by hyperref, so hypcap is dependent on this redefinition. But your code prevents the redefinition of \@caption by the hyperref package and therefore the hypcap package is doomed to fail. Remedy: Do not suppress the redefinition of \@caption but offer a new definition of \@caption which works with both, tufte and hyperref. (Unfortunately I'm too short on time at the moment to code this for you, but I'm confident that someone here will...) –  Axel Sommerfeldt May 23 '12 at 4:27
1  
I just took a look at tex.stackexchange.com/a/46838: Try out the solution from Werner (instead the one from Altermundus which drops the modifications of \@caption done by the hyperref package) –  Axel Sommerfeldt May 23 '12 at 4:31
2  
@raxacoricofallapatorius: I just tried it out, Werners solution does not help here, too. So one need to write its very own version of \@caption here. I could do that, but will not able to code it until week-end. –  Axel Sommerfeldt May 24 '12 at 5:24
show 2 more comments

1 Answer 1

Can you check the following on something larger? I'm certain we lose nameref support with this (because I wanted to avoid the parameters-of-@caption thing), but there might be more side effects, and I'm not familiar enough with tufte to spot if something's wrong from a single caption on an empty page:

\documentclass[nohyper]{tufte-handout}

\makeatletter
\let\mytufte@@caption\@caption    % Protect caption from hyperref 
\RequirePackage{hyperref}   

\RequirePackage[all]{hypcap}   % See -- http://tex.stackexchange.com/a/27349

\let\mytufte@caption\@tufte@caption
\def\@tufte@caption{%
  \global\@capstartfalse\mytufte@caption
}
% this should be highly conditional on presence
% of the right versions of hyperref et al.
\def\@caption{%
  \expandafter\ifx\csname if@capstart\expandafter\endcsname
                  \csname iftrue\endcsname
    \global\let\@currentHref\hc@currentHref
  \else
    \hyper@makecurrent{\@captype}%
  \fi
  \mytufte@@caption
}
\makeatother

\begin{document}
\begin{figure}
  \caption{An empty figure.}
\end{figure}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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