Since \item
does not have a mandatory argument this is not easy. But with \RenewDocumentCommand
from xparse
it's possible to provide an optional argument
using {}` (other arguments could be done with the d-type)
The item entry which should go to the ToC as well is to be specified with {...}
, otherwise the item entry is typeset only but not included in the ToC.
Please note that in case of \item[]{}
there must be no space between []
and {}
to make this work.
I restricted this feature to enumerate
and nesting depth of 1
\documentclass{article}
\usepackage{letltxmacro}
\usepackage{xparse}
\makeatletter
\LetLtxMacro\latex@std@item\item
\RenewDocumentCommand{\item}{og}{%
\ifnum \@enumdepth = \@ne
\IfValueTF{#1}{%
\IfValueTF{#2}{%
\latex@std@item[#1] \addcontentsline{toc}{section}{#2}#2%
}{%
\latex@std@item[#1]
}%
}{%
\IfValueTF{#2}{%
\latex@std@item \addcontentsline{toc}{section}{#2}#2%
}{%
\latex@std@item%
}%
}%
\else
\latex@std@item \IfValueTF{#2}{#2}%
\fi
}
\makeatother
\begin{document}
\tableofcontents
\begin{enumerate}
\item {PARTIES}
\begin{enumerate}
\item \textbf{Party A} (Buyers) and
\item \textbf{Party B} (Sellers)
\begin{enumerate}
\item \textbf{Party C} Deeper nested
\end{enumerate}
\end{enumerate}
\item {Groups}
\item {Categories}
\item[\textbullet]{Types}
\end{enumerate}
\end{document}
