将 LaTeX 章节标题写入附加文件

将 LaTeX 章节标题写入附加文件

我有一本附有答案手册的书。因此,当我定义一个章节或小节时,我还想将其名称写入包含答案的文件中。因此,我想以这种类型的东西结束bookans.tex

\subsection{One.I.1: Gauss' Method}
\begin{ans}{One.I.1.17}
      We can perform Gauss' method can in different ways ..

(我使用答案包。)我在 LaTeX 源代码中看到,参数 6 中的最后一个参数\@startsection风格,可以是一个带参数的命令,所以我尝试了对此进行变体。

\renewcommand{\subsection}{\@startsection
   {subsection}{2}{0em}{-10ex plus1ex minus1ex}{1em}%
   {\raggedright\usefont{T1}{fvs}{b}{n}\large\SetSectioningName}}

\def\SetSectioningName#1{\gdef\sectioningname{#1}%
  \typeout{SUBSECTION\space START:\space\sectioningname}}

但它没有获取名称;它获取的是“ \setbox \@tempboxa \hbox {{\hskip 0em\relax I.1\hskip 1em\relax \relax }}\hangindent \wd \@tempboxa \noindent \box \@tempboxa \interlinepenalty \@M Gauss' Method\@@par”。然后,例如,超链接对章节标题感到恼火。

为了写入我修改的章节名称\@chapter。我是否需要对分段命令执行同样痛苦的操作(也许\@sect)?这对我来说似乎很危险;例如,如果 LaTeX3 人员更改了这些定义怎么办?

答案1

可能最简单的事情就是重新定义,\addcontentsline因为所有的分段命令基本上都做了类似的事情

\addcontentsline{toc}{chapter}{#1}

只要 tocdepth 设置得当。您可以将其写入 toc 和附加文件。

相关内容