我有一个包含许多命名规则的方程式环境。我想给这些规则贴上标签,并有一个引用规则名称的命令。这应该与 hyperref 包一起使用;理想情况下也与命令一起使用\autoref
。
梅威瑟:
\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{proof}
\usepackage{hyperref}
\newcommand{\rulelabel}[2]{#2}
\newcommand{\ruleref}[1]{#1}
\begin{document}
\begin{equation}
\infer[\rulelabel{rule:conjI}{\mathrm{ConjI}}]
{A \land B}
{A & B}
\qquad
\infer[\rulelabel{rule:conjE}{\mathrm{ConjE}}]
{C}
{A \land B & A \implies B \implies C}
\end{equation}
Note that the rules \ruleref{rule:conjI} and \ruleref{rule:conjE} are complementary.
\end{document}
该\rulelabel
命令应创建一个标签并在第二个参数中显示文本。该\ruleref
命令应提供指向标签的链接并在的第二个参数中显示文本。如果能正常工作并显示“规则 #2”,\rulelabel
那就太好了。\autoref{rule:conjI}
这个问题类似于“引用方程的“名称”,同时使用这些名称生成方程列表“,但那里的解决方案不适用于 hyperref 包。
答案1
诀窍在于使用\ltx@label
(amsmath 将其定义为显示环境中的默认 \label);我们还需要添加一些帮助,hyperref
以便它为方程编号分配正确的自动引用名称。
\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{proof}
\usepackage{etoolbox}
\usepackage[colorlinks]{hyperref}
\newcounter{rulelabel}
\makeatletter
\newcommand{\rulelabel}[2]{%
\renewcommand{\therulelabel}{\ensuremath{#2}}%
\refstepcounter{rulelabel}%
\ltx@label{#1}%
#2
}
\appto\equation{\let\saved@currentHref\@currentHref}
\AtEndEnvironment{equation}{\let\@currentHref\saved@currentHref}
\makeatother
\newcommand{\rulelabelautorefname}{Rule}
\begin{document}
\begin{equation}\label{test}
\infer[\rulelabel{rule:conjI}{\mathrm{ConjI}}]
{A \land B}
{A & B}
\qquad
\infer[\rulelabel{rule:conjE}{\mathrm{ConjE}}]
{C}
{A \land B & A \implies B \implies C}
\end{equation}
Note that the rules \ref{rule:conjI} and \ref{rule:conjE} are complementary.
Note that \autoref{rule:conjI} and \autoref{rule:conjE} are complementary;
they are in \autoref{test}.
\begin{align}
\label{testA}
&\infer[\rulelabel{rule:conjI-1}{\mathrm{ConjI}}]
{A \land B}
{A & B}
\\
\label{testB}
&\infer[\rulelabel{rule:conjE-1}{\mathrm{ConjE}}]
{C}
{A \land B & A \implies B \implies C}
\end{align}
Note that the rules \ref{rule:conjI-1} and \ref{rule:conjE-1} are complementary.
Note that \autoref{rule:conjI-1} and \autoref{rule:conjE-1} are complementary;
they are in \autoref{testA} and \autoref{testB}.
\end{document}