Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

\usepackage[colorlinks=true, linkcolor=blue]{hyperref}

\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}
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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[colorlinks=true, linkcolor=blue, hypertexnames=false]{hyperref}
\usepackage{bookmark}

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

% Modifying commands to make bookmarks and such work appropriately
\usepackage{etoolbox}
\patchcmd{\labday}{\addchap}{\addsec}{}{\errmessage{failed to patch}}
\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:

image of output with above patch

share|improve this answer
    
This works well. Thanks! How come we don't have to patch the \experiment or \subexperiment commands? –  Jeremy 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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