# Is it possible to have dotted and undotted section numbering mixed in hyperref bookmarks?

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.

• I have no idea if it is possible but without a small complete example I won't even start to look at it. – Ulrike Fischer Jun 9 '20 at 17:52
• @UlrikeFischer You're right. Sorry for that. See above. – keth-tex Jun 9 '20 at 19:06

## 1 Answer

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}


• :-) 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