label
为什么只有当我不包含该包时,用于使命令操作无效的以下代码才有效amsmath
?
\documentclass{article}
% \usepackage{amsmath}
\usepackage{amsthm}
\usepackage{showkeys}
\newtheorem{thm}{Theorem}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentEnvironment{nolabel}{}{
\cs_set_eq:NN \label \use_none:n
}{}
\ExplSyntaxOff
%
\begin{document}
\begin{nolabel}
\begin{thm}
\begin{equation} \label{a_label}
a = b
\end{equation}
\end{thm}
\end{nolabel}
%
\begin{thm}
\begin{equation} \label{a_label}
b = a
\end{equation}
\end{thm}
\end{document}
如果我不评论,则会amsmath
显示两个标签。
答案1
amsmath 将标签映射到 \ltx@label,因此您也必须将其取消:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{showkeys}
\newtheorem{thm}{Theorem}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentEnvironment{nolabel}{}{
\cs_set_eq:NN \label \use_none:n
\cs_set_eq:cN { ltx@label} \use_none:n
}{}
\ExplSyntaxOff
%
\begin{document}
\begin{nolabel}
\begin{thm}
\begin{equation} \label{a_label}
a = b
\end{equation}
\end{thm}
\end{nolabel}
%
\begin{thm}
\begin{equation} \label{a_label}
b = a
\end{equation}
\end{thm}
\end{document}