我有一个包含 20 个左右案例的定义,并且关于该定义的证明对该定义的每个案例都有一个案例。我希望当我重新排列定义中的案例时,证明案例能够自动重新排序。我正在尝试使用关于排序的答案按照它们引用的标签对证明案例进行排序,但遇到了一些麻烦。一个最简单的错误示例是:
\documentclass{article}
\usepackage{etoolbox}
\begin{document}
\newcounter{foo}
\refstepcounter{foo}\label{a}
\refstepcounter{foo}\label{b}
\ifnumcomp\ref{a}<\ref{b}{A}{B}
\end{document}
这会产生很多错误:
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 2 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty
(/usr/share/texlive/texmf-dist/tex/latex/etex-pkg/etex.sty)) (./test.aux)
! Missing \endcsname inserted.
<to be read again>
\relax
l.7 \ifnumcomp\ref{a}<
\ref{b}{A}{B}
! Missing number, treated as zero.
<to be read again>
\protect
l.7 \ifnumcomp\ref{a}<
\ref{b}{A}{B}
! Missing = inserted for \ifnum.
<to be read again>
\gdef
l.7 \ifnumcomp\ref{a}<
\ref{b}{A}{B}
! Missing number, treated as zero.
<to be read again>
\gdef
l.7 \ifnumcomp\ref{a}<
\ref{b}{A}{B}
LaTeX Warning: Reference `\endcsname ' on page 1 undefined on input line 7.
! You can't use `\numexpr' in horizontal mode.
\ifnumcomp ...\ifnum \numexpr #1\relax #2\numexpr
#3\relax \expandafter \@fi...
l.7 \ifnumcomp\ref{a}<
\ref{b}{A}{B}
LaTeX Warning: Reference `A' on page 1 undefined on input line 7.
[1{/usr/share/texlive/texmf-dist/fonts/map/pdftex/updmap/pdftex.map}]
(./test.aux)
LaTeX Warning: There were undefined references.
)
(see the transcript file for additional information)</usr/share/texlive/texmf-d
ist/fonts/type1/public/amsfonts/cm/cmbx10.pfb></usr/share/texlive/texmf-dist/fo
nts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on test.pdf (1 page, 19390 bytes).
Transcript written on test.log.
为了试图用死鸡来掩盖它,我还尝试了以下咒语来进行比较:
\ifnumcomp{\ref{a}}<{\ref{b}}{A}{B}
\ifnumcomp\protect\ref{a}<\protect\ref{b}{A}{B}
\ifnumcomp{\protect\ref{a}}<{\protect\ref{b}}{A}{B}
这些都会产生各自的长错误。有没有一种方法可以比较适合用于上述排序机制的引用?
答案1
您需要一些支持,由refcount
:
\documentclass{article}
\usepackage{etoolbox,refcount}% http://ctan.org/pkg/{etoolbox,refcount}
\begin{document}
\newcounter{foo}
\refstepcounter{foo}\thefoo\label{a}
\refstepcounter{foo}\thefoo\label{b}
\ifnumcomp{\getrefnumber{a}}{<}{\getrefnumber{b}}{A}{B}
\end{document}
refcount
提供\getrefnumber
了参考编号的可扩展版本,可用于诸如的计算/比较\ifnumcomp
。