Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor position for AMS subequations #73

Open
RuixiZhang42 opened this issue Oct 23, 2018 · 0 comments
Open

Anchor position for AMS subequations #73

RuixiZhang42 opened this issue Oct 23, 2018 · 0 comments

Comments

@RuixiZhang42
Copy link

From TeX.SX: Hyperref with align inside subequations.

Due to the way subequations was implemented, the hyperlink anchor for the main label is positioned on the baseline of the previous last line of text, then raised by \HyperRaiseLinkDefault. However, it is desired to have the anchor positioned at the same spot as that of the first line of the subequations.

I came up with a possible patch:

% Code reproduced from https://tex.stackexchange.com/q/453821
%                  and https://tex.stackexchange.com/a/456282
\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{cleveref}

% Let's patch \HyOrg@subequations from hyperref
\usepackage{etoolbox}
\makeatletter
% Change \HyperRaiseLinkLength for the main anchor in subequations
\preto\HyOrg@subequations{%
  \renewcommand*\HyperRaiseLinkHook{%
    % Drop the main anchor from the baseline of previous text by \abovedisplayskip
    \setlength\HyperRaiseLinkLength{-\abovedisplayskip}%
    % Then, raise the main anchor by 3pt
    % (The 3pt is to cancel the -\lineskip from \displ@y, see amsldoc.tex)
    \addtolength\HyperRaiseLinkLength{3pt}%
    % To see the default position of the main anchor, uncomment the following line:
    %\setlength\HyperRaiseLinkLength{0pt}%
  }%
}
% Change nothing for the other anchors in subequations
\appto\HyOrg@subequations{%
  \let\HyperRaiseLinkHook\@empty
}
\makeatother

\begin{document}
    Some text before the subequations.
    \begin{subequations}\label{eq:arithmetic}
        \begin{align}
            a + b &= c \label{eq:arithmetic-a} \\
            a + b &= c \label{eq:arithmetic-b} \\
            a + b &= c \nonumber \\
            a + b &= c \label{eq:arithmetic-c}
        \end{align}
    \end{subequations}
    Testing:
    \Cref{eq:arithmetic,eq:arithmetic-a} bring me to the \emph{exact} same place,
    while \cref{eq:arithmetic-b,eq:arithmetic-c} bring me to the correct subequations.
    \begin{equation}
        e^{i\pi} = -1 \label{eq:euler}
    \end{equation}
    Testing:
    \Cref{eq:euler} bring me to Euler's identity.
\end{document}

Is it possible to make this the default behavior for anchoring subequations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant