ntheorem 包似乎不遵循 LaTeX 内核的旧保护机制

ntheorem 包似乎不遵循 LaTeX 内核的旧保护机制

这个问题与我对这个问题的回答有关
从引用构建数学上标/下标 (\ref使用 hyperref 和 cleveref 加载

[...]
在下面的例子中,这是通过根据 定义事物来实现的\protected\def。(由于某些不为人知的原因,当将 thm 文件的条目写入 aux 文件\DeclareRobustCommand时,无法正常工作。)\@writefile


\DeclareRobustCommand属于 LaTeX 内核的旧保护机制/属于 LaTeX 内核的旧扩展预防机制。

当使用\addcontentsline将条目放入辅助文件中时,要遵守\@writefile根据定义的宏的稳健性。\DeclareRobustCommand

加载 ntheorem 包时,可以用它\listtheorems{...}来创建定理列表。
内部通过放置在 .aux 文件中的条目\jobname.thm创建一个文件。\@writefile

由于根据 定义的环境,当将 -entries 放入 .aux 文件时,根据 定义的宏的稳健性似乎\DeclareRobustCommand不受遵守:\@writefile{thm}\newtheorem

\documentclass{article}

\usepackage{ntheorem}

\newtheorem{MyTheorem}{Some theorem}
\renewcommand{\theMyTheorem}{\theMyTheoremformatting{\number\value{MyTheorem}}}%
\makeatletter
\DeclareRobustCommand\theMyTheoremformatting{\@arabic}
%\protected\def\theMyTheoremformatting{\@arabic}
\newcommand\somethingexpandable{somethingexpandable}
\makeatother

\begin{document}

\addcontentsline{thm}{undef}{\somethingexpandable}

\addcontentsline{thm}{undef}{\theMyTheoremformatting}

\begin{MyTheorem}[Testing]
\label{Testing}%
Testing things is funnny.
\end{MyTheorem}

\end{document}

这是生成的 aux 文件的内容:

\relax 
\@writefile{thm}{\contentsline {undef}{somethingexpandable}{1}{}\protected@file@percent }
\@writefile{thm}{\contentsline {undef}{\theMyTheoremformatting  }{1}{}\protected@file@percent }
\@writefile{thm}{\contentsline {MyTheorem}{{Some theorem}{1}{Testing}}{1}{}\protected@file@percent }
\newlabel{Testing}{{\theMyTheoremformatting  {1}}{1}}
\gdef \@abspage@last{1}

对于第一个\@writefile-entry,由于第一个\addcontentsline-command,\somethingexpandable它按预期进行了扩展。

对于第二个\@writefile-entry,由于第二个\addcontentsline-command,\theMyTheoremformatting不会展开。这是预料之中的,因为\theMyTheoremformatting是根据 定义的\DeclareRobustCommand

对于第三个\@writefile-entry,由于MyTheorem-environment,\theMyTheoremformatting被扩展。这是意料之外的,因为\theMyTheoremformatting是根据 定义的\DeclareRobustCommand

\newlabel在-entry内\theMyTheoremformatting没有展开。这是预料之中的,因为\theMyTheoremformatting是根据 定义的\DeclareRobustCommand

我希望辅助文件看起来\theMyTheoremformatting与定义时的样子一样\protected\def

\relax 
\@writefile{thm}{\contentsline {undef}{somethingexpandable}{1}{}\protected@file@percent }
\@writefile{thm}{\contentsline {undef}{\theMyTheoremformatting }{1}{}\protected@file@percent }
\@writefile{thm}{\contentsline {MyTheorem}{{Some theorem}{\theMyTheoremformatting {1}}{Testing}}{1}{}\protected@file@percent }
\newlabel{Testing}{{\theMyTheoremformatting {1}}{1}}
\gdef \@abspage@last{1}

问题:

我是否忽略了\@writefile定理环境生成的条目不遵守旧保护机制的一个重要原因?
这可以被视为一个错误/事情吗?ntheorem 的维护者应该被告知这一点吗?


.log 文件摘录:

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex-dev 2021.2.27)  15 FEB 2022 18:20
entering extended mode
[...]
LaTeX2e <2021-05-01> pre-release-1 (develop 2021-2-27 branch)
L3 programming layer <2021-02-18>
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/base/article.cls
Document Class: article 2020/11/23 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/base/size10.clo
File: size10.clo 2020/11/23 v1.4m Standard LaTeX file (size option)

(/usr/local/texlive/2020/texmf-dist/tex/latex/ntheorem/ntheorem.sty
Style `ntheorem', Version 1.33 <2011/08/15>
Package: ntheorem 2011/08/15 1.33
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/base/ifthen.sty
Package: ifthen 2020/11/24 v1.1c Standard LaTeX ifthen package (DPC)

答案1

内部宏代替\thm@@thmcaption了。\edef\protected@edef

\documentclass{article}

\usepackage{ntheorem}
\usepackage{xpatch}

\newtheorem{MyTheorem}{Some theorem}
\renewcommand{\theMyTheorem}{\theMyTheoremformatting{\number\value{MyTheorem}}}%
\makeatletter
% use \protected@edef, not \edef
\xpatchcmd{\thm@@thmcaption}{\edef}{\protected@edef}{}{}

\DeclareRobustCommand\theMyTheoremformatting{\@arabic}
\makeatother

\begin{document}

\begin{MyTheorem}[Testing]
\label{Testing}
Testing things is funnny.
\end{MyTheorem}

\end{document}

.aux文件现在有

\relax 
\@writefile{thm}{\contentsline {MyTheorem}{{Some theorem}{\theMyTheoremformatting  {1}}{Testing}}{1}{}\protected@file@percent }
\newlabel{Testing}{{\theMyTheoremformatting  {1}}{1}}
\gdef \@abspage@last{1}

相关内容