自动定理列表的问题

自动定理列表的问题

我从此主题并对其进行了少许修改以满足我的个人需求。一切都运行正常,直到我添加了第二个定理环境,在我发布的 MWE 中它是引理环境。

我已经尝试修复这个问题一段时间了,但没有成功。代码如下:

\documentclass{book}
\usepackage{amsthm, chngcntr, environ, etoolbox, hyperref, showkeys, xparse}
% ---------------------------
\hypersetup{colorlinks, linkcolor=[RGB]{117, 17, 17}, citecolor=[RGB]{0, 0, 0}}
%
\ExplSyntaxOn
%
\NewDocumentCommand{\newtheoremx}{momo}
{
  \IfValueTF{#2}
  {
    \newtheorem{#1@inner}[#2@inner]{#3}
    \theoremstyle{linked}
    \newtheorem{#1@innerlinked}[#2@inner]{#3}
    \prop_gput:Nnn \g_riccardo_theorems_prop { #1 } { #2 }
  }
  {
    \IfValueTF{#4}
    {
      \newtheorem{#1@inner}{#3}[#4]
      \theoremstyle{linked}
      \newtheorem{#1@innerlinked}{#3}[#4]
    }
    {
      \newtheorem{#1@inner}{#3}
      \theoremstyle{linked}
      \newtheorem{#1@innerlinked}{#3}
    }
    \prop_gput:Nnn \g_riccardo_theorems_prop { #1 } { #1 }
    \seq_gput_right:Nn \g_riccardo_theorems_counters_seq { #1 }
  }
  \NewEnviron{#1}[1][]
  {
    \tl_if_empty:nTF { ##1 }
    { \begin{#1@inner} }
    { \begin{#1@inner}[##1] }
    \label{#3\thechapter.\arabic{#1@inner}}
    \tl_gset:Nx \g__riccardo_theorems_number_tl { \use:c {@currentlabel} }
    \BODY
    \end{#1@inner}
    \seq_gput_right:Nx \g_riccardo_theorems_seq
    {
      { #1 }
      { \g__riccardo_theorems_number_tl }
      { \exp_not:n { ##1 } }
      { \exp_not:V \BODY }
      { \thechapter }
    }
  }
  \AtBeginEnvironment{#1}{\ifnum\arabic{#1@inner}=0 \begin{noeqnumber}\printtheorems\end{noeqnumber} \fi\clearpage}
  \counterwithin{equation}{#1@inner}
  \counterwithin{footnote}{#1@inner}
  \theoremstyle{mytheorem}
}
%
\prop_new:N \g_riccardo_theorems_prop
\seq_new:N \g_riccardo_theorems_seq
\tl_new:N \g__riccardo_theorems_number_tl
\iow_new:N \g_riccardo_theorems_stream
\seq_new:N \g_riccardo_theorems_counters_seq

\NewDocumentCommand{\printtheorems}{}
 {
  \group_begin:
  \cs_set_eq:NN \label \use_none:n
  \file_if_exist_input:n { \c_sys_jobname_str.thm }
  \group_end:
  \seq_map_inline:Nn \g_riccardo_theorems_counters_seq
   {
    \setcounter{##1@inner}{0}
   }
   \newpage
 }
%
\cs_new_protected:Nn \riccardo_theorems_save:
 {
  \seq_map_function:NN \g_riccardo_theorems_seq \__riccardo_theorems_save:n
 }
\cs_new_protected:Nn \__riccardo_theorems_save:n
 {
  \iow_now:Nn \g_riccardo_theorems_stream
   {
    \savedtheorem #1
   }
 }
\AtEndDocument
 {
  \iow_open:Nn \g_riccardo_theorems_stream { \c_sys_jobname_str.thm }
  \riccardo_theorems_save:
  \iow_close:N \g_riccardo_theorems_stream
 }
%
\NewDocumentCommand{\savedtheorem}{mmmmm}
{
  \cs_set:cpn { the \prop_item:Nn \g_riccardo_theorems_prop {#1} @innerlinked } { #2 }
  \int_compare:nNnT {\thechapter} = {#5} {
    \tl_if_empty:nTF { #3 } 
    {
      \begin{#1@innerlinked} #4 \end{#1@innerlinked}
    }
    {
      \begin{#1@innerlinked}[#3] #4 \end{#1@innerlinked}
    }
  }  
} 
%
\ExplSyntaxOff
% ---------------------------
\newtheoremstyle{linked}{0pt}{10pt}{\itshape}{}{\bfseries}{\space}{0pt}{\hyperref[\thmname{#1}\thmnumber{#2}]{\thmname{#1}~\thmnumber{#2}}~\thmnote{\normalfont(#3)}}
\newtheoremstyle{mytheorem}{0pt}{10pt}{\itshape}{}{\bfseries}{\space}{0pt}{\thmname{#1}~\thmnumber{#2}~\thmnote{\normalfont(#3)}}
\theoremstyle{mytheorem}
%
\newtheoremx{thm}{Theorem}[chapter]
\newtheoremx{lemma}[thm]{Lemma}
%
\renewenvironment{proof}{\pushQED{\qed}\trivlist\item[\hskip\labelsep\hspace{7pt}\textit{Proof.}]\mbox{}\vspace{2pt}\\}{\popQED}
\newenvironment{noeqnumber}{\renewenvironment{equation}{\[}{\]}}{}
%
\counterwithout{equation}{chapter}
\counterwithout{footnote}{chapter}
% --------------------------------
\begin{document}
%
\chapter{A test chapter}
\begin{thm}
A very important theorem è.
\end{thm}

\begin{lemma}
A very important lemma.
\end{lemma}

\begin{thm}
Another theorem.
\end{thm}
%
\end{document}

我认为主要问题是它lemma@inner没有被识别为引理环境的计数器,从而导致代码失败。

相关内容