1

I have to typeset a document with some unorthodox section numbering. Some section levels are numbered in a way that one can't put a dot after the numbering, others require the dot.

It's not a problem to implement this in the document itself. Yet, with regards to hyperref bookmarks I only know of \renewcommand*{\Hy@numberline}[1]{#1. } which just puts dots everywhere. When I could have hyperref use exactly the numbering (including the dots) as in the document, that would solve the problem.

This is a working minimal example:

\documentclass[paper=a5]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{bookmark}
\hypersetup{
    bookmarksnumbered=true
}
\makeatletter
\renewcommand*{\Hy@numberline}[1]{#1. }% for dots in bookmarks
\makeatother

\newcommand*{\partnum}[1]{% the (unorthodox) part numbering
    \ifcase \value{#1}%
        VALUE INCORRECT%
    \or%
        A.%
    \or%
        B.%
    \or%
        C. (AA)%
    \or%
        (BB)%
    \or%
        (CC)%
    \or%
        (DD)%
    \else%
        VALUE INCORRECT%
    \fi%
}

\renewcommand*{\thepart}{\partnum{part}}
\renewcommand*{\thechapter}{\Roman{chapter}}
\renewcommand*{\thesection}{\alph{section}}
\RedeclareSectionCommand[tocdynnumwidth]{part}

\begin{document}

\tableofcontents

\part{Example}
\chapter{Example}
\section{Example}
\part{Example}
\part{Example}
\part{Example}
\part{Example}
\part{Example}

\end{document}

The deviation (no dots) is only required for the part level.

3
  • 1
    I have no idea if it is possible but without a small complete example I won't even start to look at it. Jun 9 '20 at 17:52
  • @UlrikeFischer You're right. Sorry for that. See above.
    – keth-tex
    Jun 9 '20 at 19:06
  • Try changing \renewcommand*{\thepart}{\partnum{part}} to \renewcommand*{\thepart}{\protect\partnum{part}}
    – Don Hosek
    Jun 9 '20 at 21:04
2

I won't claim that I understand your numbering system. But you can detect the level in the bookmark code and use it to add dots only for level 0 and larger:

\documentclass[paper=a5]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{bookmark}
\hypersetup{
    bookmarksnumbered=true
}
\makeatletter
\renewcommand*{\Hy@numberline}[1]{#1\ifnum\Hy@toclevel=-1\else.\fi\space}% for dots in bookmarks
\makeatother

\newcommand*{\partnum}[1]{% the (unorthodox) part numbering
    \ifcase \value{#1}%
        VALUE INCORRECT%
    \or%
        A.%
    \or%
        B.%
    \or%
        C. (AA)%
    \or%
        (BB)%
    \or%
        (CC)%
    \or%
        (DD)%
    \else%
        VALUE INCORRECT%
    \fi%
}

\renewcommand*{\thepart}{\partnum{part}}
\renewcommand*{\thechapter}{\Roman{chapter}}
\renewcommand*{\thesection}{\alph{section}}
\RedeclareSectionCommand[tocdynnumwidth]{part}

\begin{document}

\tableofcontents

\part{Example}
\chapter{Example}
\section{Example}
\part{Example}
\part{Example}
\part{Example}
\part{Example}
\part{Example}

\end{document}

enter image description here

1
  • :-) Actually it is not MY numbering system. It's from a centuries old book. Anyway, thanks a lot! You're awesome.
    – keth-tex
    Jun 10 '20 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.