1

Here's my current code:

\documentclass{article}

\usepackage{varwidth}
\usepackage{thmtools}
\usepackage[most,many,breakable]{tcolorbox}

\newtcbtheorem[number within=section]{Definition}{Definition}{
  enhanced,
  before skip=2mm,
  after skip=2mm,
  colback=red!5,
  colframe=red!80!black,
  colbacktitle=red!75!black,
  boxrule=0.5mm,
  attach boxed title to top left={
    xshift=1cm,
    yshift*=1mm-\tcboxedtitleheight
  },
  varwidth boxed title*=-3cm,
  boxed title style={
    interior engine=empty,
    frame code={
      \path[fill=tcbcolback]
      ([yshift=-1mm,xshift=-1mm]frame.north west)
      arc[start angle=0,end angle=180,radius=1mm]
      ([yshift=-1mm,xshift=1mm]frame.north east)
      arc[start angle=180,end angle=0,radius=1mm];
      \path[left color=tcbcolback!60!black,right color=tcbcolback!60!black,
      middle color=tcbcolback!80!black]
      ([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
      [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
      -- (frame.south east) -- (frame.south west)
      -- ([xshift=-1mm,yshift=-1mm]frame.north west)
      [sharp corners]-- cycle;
    },
  },
  fonttitle=\bfseries,
  title={#2},
  #1
}{def}

\NewDocumentEnvironment{definition}{O{}O{}}
  {\begin{Definition}{#1}{#2}}{\end{Definition}}

\newcounter{lecturecounter}

\makeatletter

\newcommand\resetcounters{
  % Reset the counters for subsection, subsubsection and the definition
  % all the custom environments.
  \setcounter{subsection}{0}
  \setcounter{subsubsection}{0}
  \setcounter{paragraph}{0}
  \setcounter{subparagraph}{0}
}

\usepackage{xifthen}

\def\@lecture{}
\newcommand\lecture[3][\arabic{lecturecounter}]{
  \addtocounter{lecturecounter}{1}
  \setcounter{section}{#1}
  \renewcommand\thesubsection{#1.\arabic{subsection}}
  \resetcounters
  \ifthenelse{\isempty{#3}}{
    \def\@lecture{Lecture \arabic{lecturecounter}}
  }{
    \def\@lecture{Lecture \arabic{lecturecounter}: #3}
  }
  \hfill\footnotesize{#2}
  \hrule
  \vspace*{-0.3cm}
  \section*{\@lecture}
  \addcontentsline{toc}{section}{\@lecture}
}
\makeatother

\begin{document}
  \lecture{Oct 22 2022 Sat (15:56:41)}{Lecture Title}

  \begin{definition}[Definition]
    \label{def:definition}

    hello.
  \end{definition}

  \lecture{Oct 22 2022 Sat (15:56:41)}{Lecture Title 2 now}

  \begin{definition}[Definition]
    \label{def:definition}

    hello.
  \end{definition}
\end{document}

Here's the output:

enter image description here

How can I reset the definition environment counter?

1 Answer 1

1

It suffices to

  • move the declaration \newcounter{lecturecounter} to before the \newtcbtheorem instruction

  • change

    \newtcbtheorem[number within=section]{Definition}{Definition}{
    

    to

    \newtcbtheorem[number within=lecturecounter]{Definition}{Definition}{
    
  • in the definition of \lecture, change

      \addtocounter{lecturecounter}{1}
    

    to

      \stepcounter{lecturecounter}
    

enter image description here

\documentclass{article}

\usepackage{varwidth}
\usepackage{thmtools}
\usepackage[most,many,breakable]{tcolorbox}
\newcounter{lecturecounter}


\newtcbtheorem[number within=lecturecounter]{Definition}{Definition}{
  enhanced,
  before skip=2mm,
  after skip=2mm,
  colback=red!5,
  colframe=red!80!black,
  colbacktitle=red!75!black,
  boxrule=0.5mm,
  attach boxed title to top left={
    xshift=1cm,
    yshift*=1mm-\tcboxedtitleheight
  },
  varwidth boxed title*=-3cm,
  boxed title style={
    interior engine=empty,
    frame code={
      \path[fill=tcbcolback]
      ([yshift=-1mm,xshift=-1mm]frame.north west)
      arc[start angle=0,end angle=180,radius=1mm]
      ([yshift=-1mm,xshift=1mm]frame.north east)
      arc[start angle=180,end angle=0,radius=1mm];
      \path[left color=tcbcolback!60!black,right color=tcbcolback!60!black,
      middle color=tcbcolback!80!black]
      ([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
      [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
      -- (frame.south east) -- (frame.south west)
      -- ([xshift=-1mm,yshift=-1mm]frame.north west)
      [sharp corners]-- cycle;
    },
  },
  fonttitle=\bfseries,
  title={#2},
  #1
}{def}

\NewDocumentEnvironment{definition}{O{}O{}}
  {\begin{Definition}{#1}{#2}}{\end{Definition}}


\makeatletter

\newcommand\resetcounters{
  % Reset the counters for subsection, subsubsection and the definition
  % all the custom environments.
  \setcounter{subsection}{0}
  \setcounter{subsubsection}{0}
  \setcounter{paragraph}{0}
  \setcounter{subparagraph}{0}
}

\usepackage{xifthen}

\def\@lecture{}
\newcommand\lecture[3][\arabic{lecturecounter}]{
  \stepcounter{lecturecounter}
  \setcounter{section}{#1}
  \renewcommand\thesubsection{#1.\arabic{subsection}}
  \resetcounters
  \ifthenelse{\isempty{#3}}{
    \def\@lecture{Lecture \arabic{lecturecounter}}
  }{
    \def\@lecture{Lecture \arabic{lecturecounter}: #3}
  }
  \hfill\footnotesize{#2}
  \hrule
  \vspace*{-0.3cm}
  \section*{\@lecture}
  \addcontentsline{toc}{section}{\@lecture}
}
\makeatother

\begin{document}
  \lecture{Oct 22 2022 Sat (15:56:41)}{Lecture Title}

  \begin{definition}[Definition] \label{def:definition}

    hello.
  \end{definition}

  \lecture{Oct 22 2022 Sat (15:56:41)}{Lecture Title 2 now}

  \begin{definition}[Definition] \label{def:definition2}
    hello again.
  \end{definition}
  
   \begin{definition}[Definition] \label{def:definition3}
    next.
  \end{definition}
\end{document}
1
  • @SingularisArt -- There are a number of additional issues with your code. For instance, cross-referencing a definitiion via, say, \ref{def:definition}, doesn't work at present. If I may say this without sounding needlessly harsh, you may want to think about re-doing large parts of your code in order to get some basic mechaniisms working.
    – Mico
    Commented Oct 23, 2022 at 8:44

You must log in to answer this question.

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