例如,假设A \iff B \iff C
。有什么方法可以为每个符号加上数字(如方程式编号)\iff
,并给它们贴上标签,以后再分别引用它们?
答案1
更新:经过一番探索后,它现在可以与旧的\ref
兼容hyperref
(避免在标签内使用,equation
因为\refstepcounter
弄乱了标签计数器)
\documentclass{article}
\usepackage{mathtools}
\usepackage{hyperref}
\makeatletter
\newcounter{iffcount}
\@ifpackageloaded{hyperref}{
\newcommand{\liff}[1]{
\refstepcounter{iffcount}
\def\Hy@AnchorName{iff.\theiffcount}
\underset{(\theiffcount)}{\iff}
\newcounter{#1}
\setcounter{#1}{\theiffcount}
\@bsphack
\protected@write\@auxout{}{%
\string\newlabel{#1}{{\theiffcount}{\thepage}{}{\Hy@AnchorName}{}}%
}%
\@esphack
\hyper@@anchor{\Hy@AnchorName}{\relax}%
}
}{
\newcommand{\liff}[1]{
\refstepcounter{iffcount}
\underset{(\theiffcount)}{\iff}
\newcounter{#1}
\setcounter{#1}{\theiffcount}
\@bsphack
\protected@write\@auxout{}%
{\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
\@esphack
}
}
\makeatother
\begin{document}
I claim that \[A\liff{iff:1} B\liff{iff:2} C.\]
I am going to prove \ref{iff:1} here, and prove \ref{iff:2} there.
I also claim that \[C\liff{iff:3} D\liff{iff:4} E.\]
I am going to prove \ref{iff:3} here, and prove \ref{iff:4} there.
\end{document}
旧版本:
这是一个粗略的做法......(不支持hyperref
!)
\documentclass{article}
\usepackage{mathtools}
\newcounter{iffcount}
\setcounter{iffcount}{1}
\newcommand{\liff}[1]{
\underset{(\theiffcount)}{\iff}
\newcounter{#1}
\setcounter{#1}{\theiffcount}
\stepcounter{iffcount}
}
\newcommand{\riff}[1]{\arabic{#1}}
\begin{document}
I claim that \[A\liff{iff:1} B\liff{iff:2} C.\]
I am going to prove \riff{iff:1} here, and prove \riff{iff:2} there.
I also claim that \[C\liff{iff:3} D\liff{iff:4} E.\]
I am going to prove \riff{iff:3} here, and prove \riff{iff:4} there.
\end{document}