Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Amsmath breaks hyperref's autoref when equations under items

125 views
Skip to first unread message

Ted Pavlic

unread,
Mar 19, 2008, 2:34:15 PM3/19/08
to
Consider the following minimal example:

%=====
\documentclass{article}

\usepackage{amsmath}
\usepackage{hyperref}

\begin{document}

\begin{enumerate}
\item Here is an item

\item Here is another item with an equation
\begin{equation}
x=5
\label{eq:mine}
\end{equation}
\end{enumerate}

The equation is \autoref{eq:mine}.

\end{document}
%=====

The last line of the DVI/PDF generated says

The equation is item 1.

If I remove amsmath, I get:

The equation is Equation 1.

The tag "1" is always correct, but the AUX file shows:

\newlabel{eq:mine}{{1}{1}{\relax }{Item.3}{}}

That is, "Item" is written out instead of "equation."

Ted Pavlic

unread,
Mar 19, 2008, 3:08:23 PM3/19/08
to
It seems to be a problem with hyperref. Adding this line before the
equation:

\makeatletter
\@hyper@itemfalse
\makeatother

and this line after the equation:

\makeatletter
\@hyper@itemtrue
\makeatother

SEEMS to fix things. So, I guess I just have to patch the math
environments so they ensure that hyper@item is false before their
entrance (and make sure it's set back to whatever it was after exiting
the math environment).

Ted Pavlic

unread,
Mar 19, 2008, 4:02:25 PM3/19/08
to
From what I understand, all that is required is the first half... That
is:

> It seems to be a problem with hyperref. Adding this line before the
> equation:
>
>                         \makeatletter
>                         \@hyper@itemfalse
>                         \makeatother
>

In fact, can't \@hyper@itemfalse can't be asserted JUST AFTER an
enumerate item's counter has been stepped in hyperref.sty.

Can hyperref.sty be fixed to do this?

--Ted

Mariano Suárez-Alvarez

unread,
Mar 26, 2008, 4:52:28 PM3/26/08
to

Any news on this front?

-- m

Ted Pavlic

unread,
Mar 27, 2008, 9:26:11 AM3/27/08
to
> > In fact, can't \@hyper@itemfalse can't be asserted JUST AFTER an
> > enumerate item's counter has been stepped in hyperref.sty.
>
> > Can hyperref.sty be fixed to do this?
>
> > --Ted
>
>  Any news on this front?

I thought I posted this message earlier, but it hasn't shown up
overnight, so I'll post it again.

I e-mailed the author of hyperref, and I have not yet received a
response.

My working fix for the problem is to insert

% Fixes a problem with how hyperref records item labels
\makeatletter
\let\oldequation\equation
\renewcommand{\equation}{\@hyper@itemfalse\oldequation}
\let\oldgather\gather
\renewcommand{\gather}{\@hyper@itemfalse\oldgather}
\let\oldalign\align
\renewcommand{\align}{\@hyper@itemfalse\oldalign}
\makeatother

just AFTER I include hyperref. That is, I include amsmath (or
mathtools) and then hyperref and then issues those commands.

From my meager understanding of how hyperref's refstepcounter stuff
works, I don't think that will break anything. My items are still
getting "Item" in front of them, and now all of my numbered equations
are getting "Equation" in front of them, even if they're buried within
an item.

I don't *THINK* that I have tested nested items, but I *think* those
will work fine too.

--Ted

Ted Pavlic

unread,
Mar 31, 2008, 12:34:58 PM3/31/08
to
>  Any news on this front?

I just realized that there are plenty of other AMS math environments
that might also need this fix (other than equation, gather, and
align), and so I now use the following (included after loading
amsmath);

%=====
\makeatletter
\newcommand{\AMShreffix}[1]{%
\expandafter\let\csname old#1\expandafter\endcsname%
\csname #1\endcsname%
\expandafter\renewcommand\csname #1\endcsname{%
\@hyper@itemfalse\csname old#1\endcsname}}
\makeatother
\AMShreffix{equation}
\AMShreffix{align}
\AMShreffix{alignat}
\AMShreffix{flalign}
\AMShreffix{gather}
\AMShreffix{multline}
%=====

If you'd like to add another environment, say xxalignat, then do:

\AMShreffix{xxalignat}

That works for me.

Heiko Oberdiek

unread,
Apr 12, 2008, 1:38:57 PM4/12/08
to
Ted Pavlic <ted.p...@gmail.com> wrote:

I came to the same conclusion and fixed it in hyperref 6.77m.

Yours sincerely
Heiko <ober...@uni-freiburg.de>

0 new messages