See EDIT below if you are returning to this question, the question is still unanswered albeit some progress
I am writing lecture notes for a course I'm taking. I'm trying to create a table of contents for a set of theorem environments that are not the usual ones from tcolorbox
.
I had an annoyance before using tcolorbox
theorems requiring two {}{}
after the \begin{}
part for every theorem environment defined by newtcbtheorem
In another post I made, a user was cleverly able to define an external betternewtcbtheorem
using expl3 that circumvented the need for the options and rather now, titles and labels are optional.
I have in my preamble five betternewtcbtheorem
environments:
- Theorem
- Definition
- Corollary
- Proposition
- Lemma
Some have titles but not all, and some have labels but not all. Some are in sections within chapters and sometimes they are in chapters but not sections
Goal: I am trying to make it so the table of contents lists each theorem, definition, corollary, definition, lemma under each chapter or section it is held within along with the page number. I want to include the title of the object if it has one, and just the theorem number if it doesn't have a title. I also want to make the ToC clickable (preferably using the hyperref
package so that one can navigate through easily).
I have tried the other solutions posted online but I do not understand how to modify them in order for it to work with this external definition because they are made with the regular theorem
environments
An example (mimicking the code later in the post) would be like:
Lecture 1... Pg#
Theorem 1.1: Test Theorem 1...
Prop 1.1: Test Prop 2...
Section 1... Pg#
Theorem 1.2...
Lemma 1.1: Test Lemma 1...
Definition 1.1: Definition 1...
Lecture 2... Pg#
Theorem 2.1: Test Theorem 3
Corollary 2.1
I give a working example of the structure below:
\documentclass[12pt]{report}
\usepackage[dvipsnames]{xcolor}
\usepackage[parfill]{parskip}
\usepackage[margin=1in]{geometry}
\usepackage{empheq}
\usepackage[most]{tcolorbox}
\usepackage{amsmath , amsthm , amssymb, mathtools}
\usepackage[all]{xy}
\usepackage{titlesec}
\usepackage{hyperref}
\hypersetup{
colorlinks,
linkcolor={blue!80!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}
\titleformat{\chapter}[display]
{\normalfont\bfseries\centering}{}{0pt}{\LARGE}
\titlespacing{\chapter}{0pt}{-75pt}{\parskip}
\tcbuselibrary{theorems}
\setcounter{secnumdepth}{0}
%This is where betternewtcbtheorem definition starts
\ExplSyntaxOn
\NewDocumentCommand{\betternewtcbtheorem}{O{}mmmm}
{
\newtcbtheorem[#1]{#2inner}{#3}{#4}{#5}
\NewDocumentEnvironment{#2}{O{}}
{
\keys_set:nn { hushus/tcb } { ##1 }
%Start of where I add to the table of contents
\phantomsection
\addcontentsline{toc}{subsection}{#3: \hspace{0.4em}\l__hushus_tcb_title_tl}
%End of where I add to table of contents
\hushus_tcb_begin:nVV {#2inner} \l__hushus_tcb_title_tl \l__hushus_tcb_label_tl
}
{
\end{#2inner}
}
\cs_if_exist:cF { c@#5} { \newcounter{#5} }
}
\cs_new_protected:Nn \hushus_tcb_begin:nnn
{
\begin{#1}{#2}{#3}
}
\cs_generate_variant:Nn \hushus_tcb_begin:nnn { nVV }
\keys_define:nn { hushus/tcb }
{
title .tl_set:N = \l__hushus_tcb_title_tl,
label .tl_set:N = \l__hushus_tcb_label_tl,
}
\ExplSyntaxOff
%This is where betternewtcbtheorem definition ends.
\betternewtcbtheorem[number within = chapter]{dfn}{Definition}%
{
enhanced,
before title = {\stepcounter{dfn}},
colback=blue!10,
colframe=blue!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=blue!35!black}
}{dfn}
\betternewtcbtheorem[number within = chapter]{thm}{Theorem}%
{
enhanced,
before title = {\stepcounter{thm}},
colback=green!10,
colframe=green!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=green!35!black}
}{thm}
\betternewtcbtheorem[number within = chapter]{prop}{Proposition}%
{
enhanced,
before title = {\stepcounter{thm}},
colback=cyan!10,
colframe=cyan!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=cyan!35!black}
}{prop}
\betternewtcbtheorem[number within = chapter]{lem}{Lemma}%
{
enhanced,
before title = {\stepcounter{thm}},
colback=Dandelion!10,
colframe=Dandelion!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=Dandelion!35!black}
}{lem}
\betternewtcbtheorem[number within= chapter]% init options
{crl}% name environment
{Corollary}% Title
{enhanced,
before title = {\stepcounter{co}},
colback=red!10,
colframe=red!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=red!35!black}
}% options
{co}% label prefix
\begin{document}
\tableofcontents
\chapter{Lecture 1}
\begin{thm}[title = Test Theorem 1,label=thm1]
abc
\end{thm}
\begin{prop}[title = Test Prop 2,label=prop1]
abc
\end{prop}
\section{Section 1}
\begin{thm}
abc
\end{thm}
\begin{lem}[title = Test Lemma 1]
abc
\end{lem}
\begin{dfn}[title = Definition 1]
abc
\end{dfn}
\chapter{Lecture 2}
\begin{thm}[title=Test Theorem 3]
\end{thm}
\begin{crl}
abc
\end{crl}
\end{document}
EDIT:
I got some resemblence of what I want working as you can see, by adding to the \newdocumentenvironment
part a \addcontentsline
which references the environment name and its optional title. The current issues are: Not being able to display the envionment number (like Theorem 1.1) and not including a colon if the environment does not have a title (like in the second theorem).
\addcontentsline{toc}{section}{\protect\numberline{\thethm}#1}
. Maybe this answer could help you.