我正在尝试将子定义嵌套在使用子计数器的另一个定义中,如下所示:
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{amsthm}
\newtheoremstyle{théorème}{0pt}{20pt}{}{}{\bfseries}{}{\newline}
{\thmnumber{ #2} \thmname{#1} \textit{\thmnote{--- #3 }}}
\tcbset{barrenoire/.style={
boxrule=0pt,frame hidden,sharp corners,enhanced,borderline west={1pt}{0pt}{black},interior hidden
}
}
\theoremstyle{théorème}
\newtheorem{Thm}{Théorème}[section]
\newtheorem{Defi}[Thm]{Définition}
\tcolorboxenvironment{Thm}{barrenoire}
\tcolorboxenvironment{Defi}{barrenoire}
\begin{document}
\begin{Defi}[1. A]
A is B and C
\begin{Defi}[1.1 B]
B is this
\end{Defi}
\begin{Defi}[1.2 C]
C is that
\end{Defi}
\end{Defi}
\end{document}
我不想重新定义另一个定义环境,所以我正在寻找一种方法来检查定理环境是否在另一个环境中调用,比如在执行编号时测量块的嵌套级别。
但是我没有找到有关此内容的任何信息,欢迎提供任何线索!
谢谢!
答案1
使定义与主要定义相反,但定义Defi
使其使用两个“内部”定理之一,即xDefi
在外部层次和xxDefi
内部层次。
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{amsthm}
\newtheoremstyle
{theoreme}
{0pt}
{20pt}
{}
{}
{\bfseries}
{}
{\newline}
{\thmnumber{#2 }\thmname{#1}\thmnote{ --- \textit{#3}}}
\tcbset{
barrenoire/.style={
boxrule=0pt,
frame hidden,
sharp corners,
enhanced,
borderline west={1pt}{0pt}{black},
interior hidden,
},
}
\theoremstyle{theoreme}
\newtheorem{xDefi}{Définition}[section]
\newtheorem{Thm}[xDefi]{Théorème}
\newtheorem{xxDefi}{Définition}[xDefi]
\tcolorboxenvironment{Thm}{barrenoire}
\tcolorboxenvironment{xDefi}{barrenoire}
\tcolorboxenvironment{xxDefi}{barrenoire}
\newcounter{defidepth}
\makeatletter
\newenvironment{Defi}
{%
\addtocounter{defidepth}{1}%
\ifnum\value{defidepth}=1
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\begin{xDefi}}{\begin{xxDefi}}%
}
{%
\ifnum\value{defidepth}=1
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\end{xDefi}}{\end{xxDefi}}%
\addtocounter{defidepth}{-1}%
}
\makeatother
\begin{document}
\section{Test}
\begin{Defi}
A is B and C
\begin{Defi}
B is this
\end{Defi}
\begin{Defi}[What's this?]
C is that
\end{Defi}
\end{Defi}
\end{document}
注意标题部分的修正。我会避免在定理样式名称中使用特殊字符。