![取消使用标签的环境](https://linux22.com/image/394985/%E5%8F%96%E6%B6%88%E4%BD%BF%E7%94%A8%E6%A0%87%E7%AD%BE%E7%9A%84%E7%8E%AF%E5%A2%83.png)
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}