更新目录级别和 pdf 书签

更新目录级别和 pdf 书签

我正在使用labbook使用命令\labday\experiment\subexperiment作为 0、1、2 目录级别的类。我想添加我自己的章节,目录级别为 1,并且\labday\experiment\subexperiment的目录级别为 2、3、4。此外,我想将 PDF 书签作为适当的子书签。

如何改变自定义切片命令的目录级别?

文档labbook给出了以下命令来设置这些级别:

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

我尝试在以下(也许不是那么简单的)例子中对其进行修改

\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}

答案1

之所以不起作用,是因为\labdays被视为章节,并labdayauxtoc文件中被标识为章节而不是 。因此\toclevel@labday永远不会被考虑用于书签(这也解释了关于错过书签级别的警告)。

以下修补程序\labday将其视为一个部分而不是一个章节(只需在该宏中替换\addchap\addsec,但请注意,可能还有其他区域仍然期望labday它是这不会触及的章节。

labbook(我还根据新软件包版本的警告更改了其中一个类选项,并禁用hypertexnameshyperref以防止重复的目的地。)

\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}

书签和目录如下所示,我相信这就是您想要的:

带有上述补丁的输出图像

相关内容