考虑以下最小示例:
\documentclass[a4paper,12pt]{article}
\begin{document}
\section{First Section}\label{sect_1}
Question: Is this Section \ref{sect_1}?
IFX Answer:
\ifx\ref{sect_1}1 YES \else NO\fi.
IF Answer:
\if\ref{sect_1}1 YES \else NO\fi.
\end{document}
两个答案都是“否”。我假设在评估条件时,的值\ref{sect_1}
是未知的(或未\ref
扩展)。有没有办法得到正确的答案(也许,使用文件.aux
)?
答案1
该refcount
包允许您访问标签中存储的数字。您可以使用它将其与硬编码值或当前部分等计数器进行比较。(非常感谢@GuM 建议使用\getrefnumber
而不是\setcounterref
)
\documentclass[a4paper,12pt]{article}
\usepackage{refcount}
\begin{document}
\section{First Section}\label{sect_1}
Question: Is this Section \ref{sect_1}?
\ifnum\value{section}=\getrefnumber{sect_1}
yes
\else
no
\fi
\section{Second Section}\label{sect_2}
Question: Is this Section \ref{sect_1}?
\ifnum\value{section}=\getrefnumber{sect_1}
yes
\else
no
\fi
\end{document}