Text FormattingCustomization of a section number in the table of contents

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
fsoedjede
Posts: 3
Joined: Sat Jun 25, 2022 11:12 pm

Customization of a section number in the table of contents

Post by fsoedjede »

Hello Everyone,

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 works

I 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

Code, edit and compile here:
\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}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply