我希望有相同定理或定义的不同版本。因此,定义 1 的版本 0 将被称为“定义 1.0”,版本 1 将被称为“定义 1.1”。下面的文件TeX capacity exceeded, sorry [input stack size=5000].
在编译时返回错误。我做错了什么?
我从中复制了相关代码这里并改变了一些细节:
\documentclass[12pt]{article}
\usepackage{amsthm}
\usepackage{amsmath}
\newcounter{dfn}[section]
\newcounter{dfnv}
\makeatletter
\@namedef{thedfnv}{\@nameuse{thedfn}.\arabic{dfnv}}
\makeatother
\newtheorem{dfn}[dfnv]{Definition}
\begin{document}
\section{First section}
\begin{dfn}% Should display as Definition 1.0
Version 0 of the definition of foo.
\end{dfn}
\begin{dfn}% Should display as Definition 1.1
Version 1 of the definition of foo.
\end{dfn}
\stepcounter{dfn}
\begin{dfn}% Should display as Definition 2.0
Version 0 of the definition of bar.
\end{dfn}
\begin{dfn}% Should display as Definition 2.1
Version 1 of the definition of bar.
\end{dfn}
\stepcounter{dfn}
\end{document}
答案1
当然,您不能混合使用版本定义。我建议使用两种环境:dfn
将步进主编号,而dfn*
仅步进版本编号。
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amsthm}
\newcounter{dfnmain}[section]
\newtheorem{dfninner}{Definition}[dfnmain]
\makeatletter
\renewcommand{\thedfninner}{%
\arabic{dfnmain}.\@arabic{\numexpr\value{dfninner}-1\relax}%
}
\makeatother
\newenvironment{dfn}
{\stepcounter{dfnmain}\dfninner}
{\enddfninner}
\newenvironment{dfn*}
{\dfninner}
{\enddfninner}
\begin{document}
\section{First section}
\begin{dfn}
Version 0 of the definition of foo.
\end{dfn}
\begin{dfn*}
Version 1 of the definition of foo.
\end{dfn*}
\begin{dfn}
Version 0 of the definition of bar.
\end{dfn}
\begin{dfn*}
Version 1 of the definition of bar.
\end{dfn*}
\section{Second section}
\begin{dfn}
Version 0 of the definition of foo.
\end{dfn}
\begin{dfn*}
Version 1 of the definition of foo.
\end{dfn*}
\begin{dfn}
Version 0 of the definition of bar.
\end{dfn}
\begin{dfn*}
Version 1 of the definition of bar.
\end{dfn*}
\end{document}
如果您希望数字也引用章节编号,请添加\arabic{section}.
定义\thedfninner
。