Using the code below, I want to be able to change the numbering in the toc just by changing the value passed to the command
\newcommand*{\CPHHeadingLevelIINumberStyle}{Decimal}
In the code,
- when I use
\renewcommand{\thechapter}{\HeadingNumberStyleDisplay{chapter}{\CPHHeadingLevelIINumberStyle}}
, I see 0 in the TOC without an error raised- when I use
\renewcommand{\thechapter}{\arabic{chapter}}
, it worksI think I'm missing something about expanding args but my tests are not conclusive.
Does anyone know what my code is missing?
Thanks in advance.
Code: Select all
\documentclass{book}
% Allows usage of "\IfStrEq"
\usepackage{xstring}
% Allows usage of "\NewDocumentCommand"
\usepackage{xparse}
\usepackage{titletoc}
\usepackage{lipsum}
\titlecontents{chapter}% <section-type>
[0pt]% <left>
{\addvspace{0.25pc}\normalsize}% <above-code>
{\thecontentslabel~:\,}% <numbered-entry-format>
{}% <numberless-entry-format>
{\normalfont\dotfill\contentspage}% <filler-page-format>
%%%%% Sections counter style
\NewDocumentCommand{\HeadingNumberStyleDisplay}{m m}{%
\IfStrEq{#2}{Decimal}{\arabic{#1}}{\relax}%
\IfStrEq{#2}{LowerRoman}{\roman{#1}}{\relax}%
\IfStrEq{#2}{UpperRoman}{\Roman{#1}}{\relax}%
}
%% Heading level 2 options
\newcommand*{\CPHHeadingLevelIINumberStyle}{Decimal}
\renewcommand{\thechapter}{\HeadingNumberStyleDisplay{chapter}{\CPHHeadingLevelIINumberStyle}}% This does not work
%\renewcommand{\thechapter}{\arabic{chapter}} % This works
\begin{document}
\setcounter{tocdepth}{1}
\tableofcontents
\chapter{Test chapter}
\lipsum[1]
\end{document}