我希望声明、子声明、子子声明等的编号能够按层次进行编号。有没有办法做到这一点而不必创建那些额外的“子声明”环境?例如:
\documentclass{article}
\usepackage{amsmath,amsthm,amssymb}
\newtheorem{thm}{Theorem}
\newtheorem{claim}{Claim}[thm]
\begin{document}
\begin{thm}
this has a long proof. i break it up into smaller claims.
\end{thm}
\begin{claim}
i prove a smaller piece of the theorem.
this proof makes its own even smaller claims.
\end{claim}
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\end{document}
此示例产生以下编号:
定理 1
权利要求1.1
权利要求1.2
理想情况下,我希望编号如下:
定理 1
权利要求1.1
权利要求1.1.1
因为最后一个主张“属于”它之前的主张。
我见过的一些解决方案通过创建额外的“子定理”包装器环境来实现这一点。有没有更简单的方法?
答案1
维护这样的堆栈levels
并不容易。我尝试将其设置为六级,如果需要,可以自动备份等并上下调平。
使用时,声明环境的重复使用存在问题\holdlevelfalse
。我会尝试解决此问题。
使用命令\claimhierarchies{claim}{6}{thm}
,表示六个级别,‘父’级别是thm
。然后。
\documentclass{article}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{xparse}
\usepackage{xpatch}
\usepackage{chngcntr}%
\newtheorem{thm}{Theorem}
\newcounter{claimlevel}[thm]
\newtheorem{claim}{Claim}[thm]
\ExplSyntaxOn
\newcommand{\claimhierarchies}[3]{%
\newcounter{#1i}
\expandafter\renewcommand\csname the#1i\endcsname{\bfseries \csname the#3\endcsname.\arabic{#1i}}%
\int_step_inline:nnnn {2}{1}{#2}{%
\newcounter{#1\romannumeral##1}[#1\romannumeral\numexpr##1-1]
\expandafter\renewcommand\csname the#1\romannumeral##1\endcsname{\csname the#1\romannumeral\numexpr ##1-1\endcsname.\arabic{#1\romannumeral\numexpr##1}}
}
}
\seq_new:N \g_claimcounter_stack_seq
\newcommand{\pushcounter}[1]{%
\seq_gpush:Nn \g_claimcounter_stack_seq {#1}
}
\newcommand{\popcounter}[1]{%
\seq_pop:NN \g_claimcounter_stack_seq \l_tmpa_tl
\setcounter{#1}{\l_tmpa_tl}%
}
\newcommand{\getcounter}[1]{%
\seq_get:NN \g_claimcounter_stack_seq \l_tmpa_tl
\setcounter{#1}{\l_tmpa_tl}%
}
\ExplSyntaxOff
\makeatletter
\newif\ifholdlevel
\newif\iflevelup
\newif\ifverbose
\verbosetrue
\newcommand{\levelup}{%
\ifnum\c@claimlevel > 1
\addtocounter{claimlevel}{\m@ne}
\ifverbose
Level up to Level \Roman{claimlevel}
\fi
\leveluptrue
\fi
}
\AtBeginEnvironment{claim}{%
\iflevelup
\csletcs{theclaim}{theclaim\romannumeral\numexpr\c@claimlevel}
\csletcs{c@claim}{c@claim\romannumeral\c@claimlevel}
\else
\ifholdlevel
\ifverbose
Hold Level on Level \Roman{claimlevel}
\fi
\csletcs{theclaim}{theclaim\romannumeral\numexpr\c@claimlevel}
\csletcs{c@claim}{c@claim\romannumeral\c@claimlevel}
\else
\addtocounter{claimlevel}{1}%
\ifverbose
Level down to Level \Roman{claimlevel}
\fi
\pushcounter{\number\value{claim}}%
\csletcs{theclaim}{theclaim\romannumeral\numexpr\c@claimlevel} %
\csletcs{c@claim}{c@claim\romannumeral\c@claimlevel}
\fi
\fi
}
\makeatother
\claimhierarchies{claim}{6}{thm}
\begin{document}
\begin{thm}
this has a long proof. i break it up into smaller claims.
\end{thm}
\begin{claim}
i prove a smaller piece of the theorem.
this proof makes its own even smaller claims.
\end{claim}
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\holdleveltrue
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\levelup
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\levelup
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\holdleveltrue
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\holdlevelfalse
\levelupfalse
\begin{claim}
i prove a claim made in the previous claim environment.
\end{claim}
\end{document}
答案2
环境claim
接受一个可选参数 default =
,用于向上或向下攀升。使用 可向上+
攀升一级,使用 可向下攀升一级;使用和-
也可向下跳升两到三级。--
---
\documentclass{article}
\usepackage{amsthm,xparse,etoolbox}
\newtheorem{theorem}{Theorem}
\newtheorem{Claim}{Claim}[theorem]
\newtheorem{ClaimI}{Claim}[Claim]
\newtheorem{ClaimII}{Claim}[ClaimI]
\newtheorem{ClaimIII}{Claim}[ClaimII]
\newcounter{claimlevel}[theorem]
\ExplSyntaxOn
\NewDocumentEnvironment{claim}{O{=}}
{
\str_case:nn { #1 }
{
{=} { }
{+} { \stepcounter{claimlevel} }
{-} { \addtocounter{claimlevel}{-1} }
{--} { \addtocounter{claimlevel}{-2} }
{---}{ \addtocounter{claimlevel}{-3} }
}
\begin{ Claim \int_to_Roman:n { \value{claimlevel} } }
}
{
\end{ Claim \int_to_Roman:n { \value{claimlevel} } }
}
\ExplSyntaxOff
\begin{document}
\begin{theorem}
This has a long proof. I break it up into smaller claims.
\end{theorem}
\begin{claim}
I prove a smaller piece of the theorem.
This proof makes its own even smaller claims.
\end{claim}
\begin{claim}[+]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[+]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[-]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[-]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[+]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[-]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{theorem}
This has a long proof. I break it up into smaller claims.
\end{theorem}
\begin{claim}
I prove a smaller piece of the theorem.
This proof makes its own even smaller claims.
\end{claim}
\begin{claim}[+]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[+]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[--]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[+]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[+]
I prove a claim made in the previous claim environment.
\end{claim}
\begin{claim}[--]
I prove a claim made in the previous claim environment.
\end{claim}
\end{document}