我想创建本地目录,以分项列表的形式列出某一部分内的子部分。为此,我使用etoc
并定义了相应的样式\etocsetstyle
。
问题是,通过调用本地 toc \itemizedlocaltoc
,我还通过调用全局设置了 ToC 深度\etocsettocdepth{subsection}
。这会更改文档其余部分的书签深度:范围泄漏。
有没有办法限制的范围\etocsettocdepth{subsection}
?
etoc.sty
提及的相关部分\global
似乎暗示“不”。
\def\etocsettocdepth {\futurelet\Etoc@nexttoken\Etoc@set@tocdepth }
\def\Etoc@set@tocdepth {\ifx\Etoc@nexttoken\bgroup
\expandafter\Etoc@set@tocdepth@
\else\expandafter\Etoc@set@toctocdepth
\fi }
\def\Etoc@set@tocdepth@ #1{\@ifundefined {Etoc@#1@@}
{\PackageWarning{etoc}
{Unknown sectioning unit #1, \protect\etocsettocdepth\space ignored}}
{\global\c@tocdepth\csname Etoc@#1@@\endcsname}%
不带书签\listsubseclocaltoc
书签\listsubseclocaltoc
\documentclass{article}
\usepackage{fontspec}% xelatex
\usepackage{etoc}% local toc mechanism
\usepackage{lipsum}% dummy text
\usepackage{hyperref}% get pdf bookmarks
\def\itemizedlocaltoc{% All settings, particularly \etocsettocdepth, should be local to this scope
% Available vars provided by etoc: \etocname \etocnumber \etocpage
\def\contentsname{}
\etocsettocstyle{\par\medskip}{}%\etocsettocstyle{beforetoc}{aftertoc}, use for heading
\etocsetstyle{subsection}
{\begin{itemize}}
{\scshape\item}
{\etocname{}}
{\end{itemize}}
%\etocsettocmargins[0mm]{0mm}{0mm}% custom margins for local toc https://tex.stackexchange.com/questions/87709/minitoc-of-a-subsection/87716
\begingroup
\etocsettocdepth{subsection} % set depth of this toc
\localtableofcontents
\endgroup
}%
\begin{document}
% Main Stuff
\section{Main Stuff}
\itemizedlocaltoc
% Sub stuff for demo
\newcount\step
\step=1
\loop% TeX loop for fun
\subsection{Substuff \the\step}
Here is a nice sentence about cool stuff \#\the\step.
\subsubsection{Subsubstuff \the\step}
\advance \step by 1
\ifnum\step<6
\repeat
\end{document}
输出
答案1
Touhami 提到\etocsetnexttocdepth
,这解决了这个问题
定义\etocsetnexttocdepth
\def\etocsetnexttocdepth #1{%
\@ifundefined{Etoc@#1@@}
{\PackageWarning{etoc}
{Unknown sectioning unit #1, \protect\etocsetnextocdepth\space ignored}}
{\edef\Etoc@aftertochook {\global\c@tocdepth\the\c@tocdepth\space
\let\noexpand\Etoc@aftertochook\noexpand\@empty }%
\global\c@tocdepth\csname Etoc@#1@@\endcsname}%
}%
此定义不同于,它添加了一个钩子,该钩子将在每个目录\etocsettocdepth
之后执行。如上面的代码所示,在深度改变之前,将其设置为包含当前 ToC 深度的寄存器。etoc
\edef\Etoc@aftertochook
\c@tocdepth
\c@tocdepth