0

On my document, I have defined a new trivfloat environment in order to make a list of equations. To add elements to this list I use \captionlistentry (in order to avoid the caption appearing under the equation). However, I've realized that when using hyperref, all links appearing in the list of equations link to the first page. I've looked in hyperref's documentation and over the Internet but couldn't find anything that help me solve this problem.

Here's a minimal example of what I've done:

\documentclass{report}

\usepackage{trivfloat}
\usepackage{hyperref}
\usepackage{subcaption}

\trivfloat{Equation}

\begin{document}

\listof{Equation}{List of Equations}

\chapter*{}
\begin{Equation}[!htb]
\begin{equation}
6 \times 9 = 42
\end{equation}
\captionlistentry{Life, the universe and everything}
\end{Equation}

\end{document}

EDIT:

I've manage to find a solution to the minimal example thanks to the answer of John Kormylo:

\documentclass{report}

\usepackage{trivfloat}
\usepackage{hyperref}
\usepackage{caption}
\usepackage{environ}

\trivfloat{Equation}

\newsavebox{\tempbox}

\begin{document}

\let\oldEquation=\Equation
\let\oldendEquation=\endEquation
\let\Equation\relax
\let\endEquation\relax
\NewEnviron{Equation}[1][hbtp]%
{\oldEquation[#1]%
 \savebox{\tempbox}{\begin{minipage}{\textwidth}%
   \BODY
   \end{minipage}}%
 \hypertarget{Equation.\thechapter.\theequation}{\usebox{\tempbox}}%
 \oldendEquation}

\listof{Equation}{List of Equations}

\chapter*{}
\begin{Equation}[!htb]
\begin{equation}
6 \times 9 = 42
\end{equation}
\captionlistentry{Life, the universe and everything}
\end{Equation}

\end{document}

However, this solution doesn't work if the Equation is inside a \chapter (instead of being inside \chapter*). Any idea of what I'm doing wrong?

  • Linking to the first page is the default when \hyperlink can't find the target. – John Kormylo Jul 22 '15 at 15:44
1

Hyperref modifies \caption to add the \hypertarget, but it does not modify \captionlistentry. To link to the equation (as opposed to beneath it) one needs to put the entire equation environment inside the \hypertarget, which is before the equation counter is incremented.

Interestingly, the Equation environment is not defined until \begin{document}.

\documentclass{report}

\usepackage{trivfloat}
\usepackage{hyperref}
\usepackage{caption}
\usepackage{environ}

\trivfloat{Equation}

\newsavebox{\tempbox}

\begin{document}

\let\oldEquation=\Equation
\let\oldendEquation=\endEquation

\makeatletter
\RenewEnviron{Equation}[1][hbtp]%
{\oldEquation[#1]%
 \savebox{\tempbox}{\begin{minipage}{\textwidth}%
   \BODY
   \end{minipage}}%
 \hypertarget{\@currentHref}{\usebox{\tempbox}}%
 \oldendEquation}
\makeatother

\listof{Equation}{List of Equations}

\chapter*{}
\begin{Equation}[!htb]
\begin{equation}
6 \times 9 = 42
\end{equation}
\captionlistentry{Life, the universe and everything}
\end{Equation}

\end{document}
  • Thanks for your answer. However, your implementation gives me an error with the use of \RenewEnviron. I've manage to solve this error using \NewEnviron instead. The problem now is that although this solution works for the minimal example, it doesn't work if the Equation is inside a \chapter. I'm going to update the post with the new information. – midobal Jul 23 '15 at 14:22
  • Sorry about that. Long story short, hyperref uses \@currentHref for the hypertarget, so this should always work. BTW, you might try updating your packages. – John Kormylo Jul 23 '15 at 16:15
  • This works great, thank you. The only detail is that \RenewEnviron is still giving me issues, but I've managed to solve them by using \NewEnviron (as in my previous example). – midobal Jul 23 '15 at 16:42

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.