4

I'm trying to make subdefinition nested inside another definition that use a sub-counter, like this :

\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}

I would like not to have to redefine another definition environment, so I'm looking for a way to check if the theorem environment is called inside another one, like measuring the nestedness level of the block when performing the numbering.

However I didn't find anything about this, any clue would be welcome!

Thank's!

2
  • Welcome to TeX.SE!
    – Mensch
    Dec 6, 2023 at 17:14
  • @Mensch Thank you! :) Dec 6, 2023 at 17:35

1 Answer 1

4

Make the definition counter the main one, but define Defi so it uses one of two “inner” theorems, namely xDefi at the outer level and xxDefi at the inner level.

\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}

Note the fixes to the header part. I'd avoid special characters in the theorem style name.

enter image description here

1
  • wow, thanks a lot, I'm not sure how it works, but it works! :) it's beautiful! Dec 6, 2023 at 19:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .