# Chapter and Section numbering

## Depth of Section numbering and Table Of Content

`Dblatex` relies on latex to automatically compute the chapter and section numbers. It also relies on latex to produce the headings with these numbers, and to produce the Table Of Content containing these entries.

Some specific sections like preface, colophon, or dedication are not numbered because they are displayed in front and back matters, but they can be listed in the TOC if the related parameters are set (dedication.tocdepth, preface.tocdepth, colophon.tocdepth).

More generally you can configure the depth of the chapter and section numbering with the parameter doc.section.depth, and the depth of the entries in the TOC with the parameter toc.section.depth

.

Note however that an unumbered section becomes an informal component, and therefore you can only link to such a section by using a specific xrefstyle because their label built with the automatic number does not exist anymore. The other drawback is that all the sections included in an unnumbered section or chapter are unnumbered.

## Using the latex style for section numbering

A well customized latex style can be a powerfull yet versatile alternative to the use of section and/or TOC depth parameter. With some latex packages you can easily format the headings to remove the numbers, or transform them. See to know how to use your own latex style with `dblatex`.

The benefit of this method is that you can fully control how the titles must be displayed, you do not have to play with latex counters to have the right depth, and the sections do not lost their formal number label.

The following example shows how you can customize the chapter title by using the latex package titlesec, and shows how to remove the chapter label in the Table Of Content with the package titletoc. Look in particular in the listing where text is emphasized.

    \usepackage{titlesec}

    %% Example 1: Redefines the heading to remove the chapter label
    %% The 2nd parameter only contains \filcenter without any label
    \titleformat{\chapter}[block]
    {\filcenter\huge}{\filcenter}{20pt}{\Huge}

    %% Example 2: Put the chapter number in word
    %% The title of the first chapter is then displayed like this:
    %% "Chapter One <chapter title>"
    \newcommand\makeletterof[1]{%
    \ifthenelse{\equal{#1}{1}}{ONE}{%
    \ifthenelse{\equal{#1}{2}}{TWO}{%
    \ifthenelse{\equal{#1}{3}}{THREE}{%
    \ifthenelse{\equal{#1}{4}}{FOUR}{%
    \ifthenelse{\equal{#1}{5}}{FIVE}{%
    \ifthenelse{\equal{#1}{6}}{SIX}{%
    \ifthenelse{\equal{#1}{7}}{SEVEN}{%
    \ifthenelse{\equal{#1}{8}}{EIGHT}{%
    \ifthenelse{\equal{#1}{9}}{NINE}{%
    \ifthenelse{\equal{#1}{10}}{TEN}{%
    \ifthenelse{\equal{#1}{11}}{ELEVEN}{%
    \ifthenelse{\equal{#1}{12}}{TWELVE}{%
    #1}}}}}}}}}}}}}

    \titleformat{\chapter}[block]
    {\filcenter\ttfamily\huge}%
    {\filcenter\MakeUppercase{\chaptertitlename} \makeletterof{\thechapter}}{20pt}{\Huge}

    %% Make TOC entries for chapters without label
    \usepackage{titletoc}

    \titlecontents{chapter} %
    [1.5em] %
    {\addvspace{1em plus 0pt}\bfseries} %
    {\hspace{-1.3em}} % no number, remove room reserved for it
    {\hspace{-1.3em}} %
    {\hfill \contentspage} %
    [\addvspace {0pt}]

## Using the label attribute

If you need to mix numbered and not numbered chapters, the numbering depth parameters will not help. The latex style will not easily detect that for some chapters the number should be displayed and for others it should not.

To mix numbered and unnumbered chapters you can use a label with an empty string for the chapters that must not be numbered, as shown by the example below.

    <chapter id="intro" label=""><title>Introduction</title>
      <!-- This chapter must be displayed with no number, like a preface -->
    </chapter>
    <chapter id="before" label=""><title>Pre-requisite</title>
      <!-- This chapter must be displayed with no number, like a preface -->
    </chapter>
    <chapter id="chap1"><title>First chapter</title>
      <!-- First numbered chapter -->
    </chapter>
    ...
    <chapter id="after" label=""><title>Conclusion</title>
      <!-- This chapter must be displayed with no number, like a colophon -->
    </chapter>
    ...

You can also set a label to a specific integer to force a section counter. In this case there is no more automatic numbering. The automatic numbering then applies to the following sections that increment the counter set for this section if there is no label.

    <chapter id="intro" label="2"><title>Introduction</title>
      <!-- This chapter is forced to have number 2 (it should be 1) -->
      <section id="s1" label="3"><title>Section 2.3</title>
        <!-- This section is forced to have number 3 (it should be 1) -->
        <section id="s11" label="4"><title>Section 2.3.4</title>
          <!-- This section is forced to have number 4 (it should be 1) -->
        </section>
      </section>
    </chapter>