1

I got a brilliant solution to a question on how to manipulate the subsection to also be given by letters:

Numbering subsections, manually set letters or numbers

But, unfortunately I got an issue with the table of contents

\documentclass{article}

\usepackage{hyperref}

%\usepackage{letltxmacro}

\NewCommandCopy{\originalsubsection}{\subsection} %\LetLtxMacro{\originalsubsection}{\subsection} \RenewDocumentCommand{\subsection}{sd()O{#3}m}{% \IfBooleanTF{#1} {\originalsubsection*{#4}}% {% \IfNoValueTF{#2} {% no letter \renewcommand{\thesubsection}{\thesection.\arabic{subsection}}% } {% letter \addtocounter{subsection}{-1}% \renewcommand{\thesubsection}{\thesection.#2}% } \originalsubsection[#3]{#4}% }% }

\renewcommand{\theHsubsection}{\thesubsection}

\begin{document}

\tableofcontents

\section{First section}

\subsection(P){First subsection}

\subsubsection{First subsubsection}

\subsubsection{Second subsubsection}

\subsection(V){Second subsection}\label{v}

\subsubsection{First subsubsection}\label{1-v}

\section{First section}

\subsection{First subsection}

\ref{v} and \ref{1-v}

\end{document}

The table of content looks like this:

enter image description here

Where NoValue is shown in the subsections with letters.

Any idea how to fix this? Thank you!

nunatak
  • 577

1 Answers1

2

The third argument in the newly-defined \subsection should not use O{#3}, but instead o and then test whether #3 exists or not (using \IfValueTF{#3}{<true>}{<false>}). Here the <true> branch (if #3 was supplied) would use it as-is, otherwise (if #3) was not supplied) it should use #4.

enter image description here

\documentclass{article}

\usepackage{hyperref}

\NewCommandCopy{\originalsubsection}{\subsection} %\LetLtxMacro{\originalsubsection}{\subsection} \RenewDocumentCommand{\subsection}{s d() o m}{% \IfBooleanTF{#1} {\originalsubsection*{#4}}% {% \IfValueTF{#2} {% letter \addtocounter{subsection}{-1}% \renewcommand{\thesubsection}{\thesection.#2}% } {% no letter \renewcommand{\thesubsection}{\thesection.\arabic{subsection}}% }% \originalsubsection[\IfValueTF{#3}{#3}{#4}]{#4}% }% }

\renewcommand{\theHsubsection}{\thesubsection}

\begin{document}

\tableofcontents

\section{First section}

\subsection(P){First subsection}

\subsubsection{First subsubsection}

\subsubsection{Second subsubsection}

\subsection(V){Second subsection}\label{v}

\subsubsection{First subsubsection}\label{1-v}

\section{First section}

\subsection{First subsection}

\ref{v} and \ref{1-v}

\end{document}

Werner
  • 603,163