有人能帮我为什么这两条警告信息在语法上不同(当它们似乎是以相同的方式生成时)?
\documentclass{article}
\usepackage{enumitem}
\usepackage{refcount}
\makeatletter
\newcommand\statuslabel[1]{%
\def\nref{\getrefnumber{#1}}
\@latex@warning{Not a number (\#3): \nref}
}
\makeatother
\makeatletter
\newcounter{enumerateof} % to create unique labels
\newenvironment{enumerateof}
{\stepcounter{enumerateof}
\begin{enumerate}[
label=\protect\statuslabel{enof@\arabic{enumerateof}},
ref=\arabic*]}
{\label{enof@\arabic{enumerateof}}%
\end{enumerate}}
\makeatother
\begin{document}
\begin{enumerateof}
\item example
\end{enumerateof}
\begin{table}
\caption{example}
\label{tab@ex}
\end{table}
\protect\statuslabel{tab@ex}
\end{document}
警告消息:
LaTeX Warning: Not a number (\#3): {1} on input line 27.
LaTeX Warning: Not a number (\#3): 1 on input line 35.
这些花括号从何而来?我该如何删除它们(定义与花括号内容相等的内容)?
答案1
似乎enumitem
软件包将它们添加到那里。要删除它们,您可以(非常安全地)执行以下操作:
\documentclass{article}
\usepackage{enumitem}
\usepackage{refcount}
\makeatletter
\newcommand\statuslabel[1]{%
\edef\nref{\getrefnumber{#1}}
\edef\nref{\expandafter\@firstofone\nref}
\@latex@warning{Not a number (\#3): \nref}
}
\makeatother
\makeatletter
\newcounter{enumerateof} % to create unique labels
\newenvironment{enumerateof}
{\stepcounter{enumerateof}
\begin{enumerate}[
label=\protect\statuslabel{enof@\arabic{enumerateof}},
ref=\arabic*]}
{\label{enof@\arabic{enumerateof}}%
\end{enumerate}}
\makeatother
\begin{document}
\begin{enumerateof}
\item example
\end{enumerateof}
\begin{table}
\caption{example}
\label{tab@ex}
\end{table}
\protect\statuslabel{tab@ex}
\end{document}
重点是,如果在第一步\nref
扩展为,则将其作为参数并返回,留在流中。如果是,则将其全部取出并删除括号。123
\@firstofone
1
1
23
{123}
\@firstofone