I'm using the labbook class which uses the commands \labday, \experiment, and \subexperiment as the 0,1,2 table of contents levels. I want to add my own chapters with TOC level of 1 and have the \labday, \experiment, and \subexperiment have TOC levels of 2,3,4. Additionally, I want to have the PDF bookmarks as sub-bookmarks as appropriate.

How can I alter the TOC level for custom sectioning commands?

The labbook documentation gives the following commands for setting these levels:

\providecommand*{\toclevel@labday}{0}%
\providecommand*{\toclevel@experiment}{1}%
\providecommand*{\toclevel@subexperiment}{2}%


which I have tried to modify in the following (perhaps, not so minimal) example

\documentclass[idxtotoc, hyperref, openany]{labbook}

\title{Testing Some \texttt{labbook} Modifications}
\author{Jeremy Lloyd Conlin}

% Modifying commands to make bookmarks and such work appropriately
\makeatletter
\renewcommand*{\toclevel@labday}{1}%
\renewcommand*{\toclevel@experiment}{2}%
\renewcommand*{\toclevel@subexperiment}{3}%
\makeatother

\begin{document}
\frontmatter
\tableofcontents

\maketitle

\mainmatter

\chapter{Year 1}
\labday{The First}
\experiment{Programming}
\subexperiment[helloworld.c]{\texttt{helloworld.c}}
I am programming in \texttt{C}.

\labday{The Second}
\experiment{Programming}
\subexperiment[helloworld.f90]{\texttt{helloworld.f90}}
I am programming in \texttt{fortran}.

\chapter{Year 2}
\labday{The First}
\experiment{Documenting}
\subexperiment[helloworld.c]{\texttt{helloworld.c}}
I am documenting \texttt{C}.

\labday{The Second}
\experiment{Documenting}
\subexperiment[helloworld.f90]{\texttt{helloworld.f90}}
I am documenting \texttt{fortran}.

\printindex
\end{document}

-

The reason this doesn't work is that \labdays are treated as chapters, and identified as such rather than as labdays in the aux and toc files. Hence the \toclevel@labday never gets considered for the bookmarks (and this also explains the warnings about missing out a bookmark level).

The following patches \labday so that it gets treated as a section instead of as a chapter (just by replacing \addchap with \addsec in that macro), though note that there may be other areas that still expect labdays to be chapters that this does not touch.

(I have also changed one of the class options to labbook as per the warning from newer package versions, and disabled hypertexnames in hyperref to prevent duplicate destinations.)

\documentclass[index=totoc, hyperref, openany]{labbook}

\usepackage{bookmark}

\title{Testing Some \texttt{labbook} Modifications}
\author{Jeremy Lloyd Conlin}

% Modifying commands to make bookmarks and such work appropriately
\usepackage{etoolbox}
\makeatletter
\renewcommand*{\toclevel@labday}{1}%
\renewcommand*{\toclevel@experiment}{2}%
\renewcommand*{\toclevel@subexperiment}{3}%
\makeatother

\begin{document}
\frontmatter
\tableofcontents

\maketitle

\mainmatter

\chapter{Year 1}
\labday{The First}
\experiment{Programming}
\subexperiment[helloworld.c]{\texttt{helloworld.c}}
I am programming in \texttt{C}.

\labday{The Second}
\experiment{Programming}
\subexperiment[helloworld.f90]{\texttt{helloworld.f90}}
I am programming in \texttt{fortran}.

\chapter{Year 2}
\labday{The First}
\experiment{Documenting}
\subexperiment[helloworld.c]{\texttt{helloworld.c}}
I am documenting \texttt{C}.

\labday{The Second}
\experiment{Documenting}
\subexperiment[helloworld.f90]{\texttt{helloworld.f90}}
I am documenting \texttt{fortran}.

\printindex
\end{document}


The bookmarks and table of contents then look like this, which I believe is what you want:

-
This works well. Thanks! How come we don't have to patch the \experiment or \subexperiment commands? – jlconlin Jan 4 '13 at 21:58
@Jeremy: \experiment uses \@startsection{experiment}... and similarly for \subexperiment, so they get correctly identified in the toc and aux files and hence the \toclevel@... stuff works for them. \labday however uses \addchap instead of something like \@startsection{labday}..., and I don't know enough about labbook or the base class scrbook to change them to issue such. Hence the use akin to \section in this patch, which I think is a reasonable solution if you are happy with the outcome. – cyberSingularity Jan 4 '13 at 23:12