我想打电话
\setcounter{theorem}{0}
每次之后\section
无论是否\section{something}
被\section*{something}
调用。
我怎样才能做到这一点?
答案1
\section
这是一个开始,使用覆盖xparse
:
\documentclass{article}
\usepackage{amsthm,xparse}
\newtheorem{theorem}{Theorem}
\let\oldsection\section
\RenewDocumentCommand{\section}{s o m}{%
\setcounter{theorem}{0}% Reset theorem counter
\IfBooleanTF{#1}%
{\oldsection*{#3}}% \section*[.]{..}
{\IfNoValueTF{#2}
{\oldsection{#3}}% \section{..}
{\oldsection[#2]{#3}}% \section[.]{..}
}%
}
\begin{document}
\section{A section}
\begin{theorem}[Something]
Some theorem.
\end{theorem}
\begin{theorem}[Something]
Some theorem.
\end{theorem}
\section*{Another section}
\begin{theorem}[Something]
Some theorem.
\end{theorem}
\begin{theorem}[Something]
Some theorem.
\end{theorem}
\section{A section}
\begin{theorem}[Something]
Some theorem.
\end{theorem}
\begin{theorem}[Something]
Some theorem.
\end{theorem}
\end{document}
答案2
这会在代码中添加重置 — — 但是,我已将定理编号中\section
删除。\thesection
如果这个要求不成立的话,事情就会变得更容易\section*
。
\documentclass{article}
\usepackage{amsthm}
\usepackage{xpatch}
\newtheorem{theorem}{My Theorem}
%\renewcommand{\thetheorem}{\arabic{theorem}} % it's the default
\xpretocmd{\section}{\setcounter{theorem}{0}}{}{}
\begin{document}
\section{First}
\begin{theorem}[Theorem of everything]
A theorem
\end{theorem}
\section*{First unnumbered section}
\begin{theorem}[A new theorem]
Another theorem
\end{theorem}
\section{Second}
\begin{theorem}[Another important theorem]
Yet another important stuff in her
\end{theorem}
\end{document}