mathtools 和 hyperref 交互不良?

mathtools 和 hyperref 交互不良?

我想要:(a)对于非引用方程,不添加方程编号;(b)在方程和其他构造(引理/定理/等等)上有超链接;(c)使用 autoref,这样相关引用(方程、引理等)的字符串就会自动添加。下面的代码不起作用,没有出现“方程 1/2”。

\documentclass[10pt]{article} % For LaTeX2e



\usepackage{hyperref}

\usepackage{mathtools}

\mathtoolsset{showonlyrefs,showmanualtags}


\makeatletter
\newcommand\Autoref[1]{\@first@ref#1,@}
\def\@throw@dot#1.#2@{#1}% discard everything after the dot
\def\@set@refname#1{%    % set \@refname to autoefname+s using \getrefbykeydefault
    \edef\@tmp{\getrefbykeydefault{#1}{anchor}{}}%
    \xdef\@tmp{\expandafter\@throw@dot\@tmp.@}%
    \ltx@IfUndefined{\@tmp autorefnameplural}%
         {\def\@refname{\@nameuse{\@tmp autorefname}}}%
         {\def\@refname{\@nameuse{\@tmp autorefnameplural}}}%
}
\def\@first@ref#1,#2{%
  \ifx#2@\autoref{#1}\let\@nextref\@gobble% only one ref, revert to normal \autoref
  \else%
    \@set@refname{#1}%  set \@refname to autoref name
    \@refname~\ref{#1}% add autoefname and first reference
    \let\@nextref\@next@ref% push processing to \@next@ref
  \fi%
  \@nextref#2%
}
\def\@next@ref#1,#2{%
   \ifx#2@ and~\ref{#1}\let\@nextref\@gobble% at end: print and+\ref and stop
   \else, \ref{#1}% print  ,+\ref and continue
   \fi%
   \@nextref#2%
}
\makeatother

\providecommand*{\equationautorefname}{Equation}


\begin{document}

\begin{equation}
referenced \label{eq:1}
\end{equation}

\begin{align}
referenced too \label{eq:2}
\end{align}

\begin{equation}
unreferenced
\end{equation}

Consider \autoref{eq:1} and \autoref{eq:2}. It is referenced.

\end{document}

编辑:我读到 autonum 包可能会有所帮助,但是下面的方法也不起作用(我想要的只是引用时只用数字标记的超链接方程式):

\documentclass[10pt]{article} % For LaTeX2e


\usepackage{amsmath}



\usepackage{autonum}
\usepackage{hyperref}
\usepackage{cleveref}


\makeatletter
\newcommand\Autoref[1]{\@first@ref#1,@}
\def\@throw@dot#1.#2@{#1}% discard everything after the dot
\def\@set@refname#1{%    % set \@refname to autoefname+s using \getrefbykeydefault
    \edef\@tmp{\getrefbykeydefault{#1}{anchor}{}}%
    \xdef\@tmp{\expandafter\@throw@dot\@tmp.@}%
    \ltx@IfUndefined{\@tmp autorefnameplural}%
         {\def\@refname{\@nameuse{\@tmp autorefname}}}%
         {\def\@refname{\@nameuse{\@tmp autorefnameplural}}}%
}
\def\@first@ref#1,#2{%
  \ifx#2@\autoref{#1}\let\@nextref\@gobble% only one ref, revert to normal \autoref
  \else%
    \@set@refname{#1}%  set \@refname to autoref name
    \@refname~\ref{#1}% add autoefname and first reference
    \let\@nextref\@next@ref% push processing to \@next@ref
  \fi%
  \@nextref#2%
}
\def\@next@ref#1,#2{%
   \ifx#2@ and~\ref{#1}\let\@nextref\@gobble% at end: print and+\ref and stop
   \else, \ref{#1}% print  ,+\ref and continue
   \fi%
   \@nextref#2%
}
\makeatother

\providecommand*{\equationautorefname}{Equation}

\begin{document}

\begin{equation}
referenced \label{eq:a}
\end{equation}

\begin{align}
referenced too \label{eq:b}
\end{align}

\begin{equation}
unreferenced 
\end{equation}

Consider \autoref{eq:a} and \autoref{eq:b}. It is referenced.

\ref{eq:a}

\eqref{eq:a}

\ref{eq:b}

\eqref{eq:b}

\ref{eq:a}


\end{document}

答案1

我知道这是一个老问题,但我刚刚遇到了它。无论如何,zref-clever支持 的mathtools选项showonlyrefs。因此,您可以获得类似以下内容的内容:

\documentclass[10pt]{article}

\usepackage{zref-clever}
\usepackage{mathtools}
\mathtoolsset{showonlyrefs,showmanualtags}
\usepackage{hyperref}

\begin{document}

\begin{equation}
referenced \label{eq:a}
\end{equation}

\begin{align}
referenced too \label{eq:b}
\end{align}

\begin{equation}
unreferenced
\end{equation}

Consider \zcref{eq:a, eq:b}. They are referenced.

\end{document}

在此处输入图片描述

相关内容