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 have a book that comes with an answer manual. So when I define a section or subsection I want to also write the name of that to the file containing the answers. Thus, I want to end with this type of thing in bookans.tex.

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

(I write to that file using the answers package.) I see in the LaTeX source that the last thing in argument 6 to \@startsection, the style, can be a command that takes an argument, so I tried variations on this.

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

But it does not get the name; it gets "\setbox \@tempboxa \hbox {{\hskip 0em\relax I.1\hskip 1em\relax \relax }}\hangindent \wd \@tempboxa \noindent \box \@tempboxa \interlinepenalty \@M Gauss' Method\@@par". Then, for instance, hyperref gets annoyed at the section title.

To write the Chapter name I modified \@chapter. Do I need to do the same torturous thing with the sectioning commands (maybe \@sect)? It seems perilous to me; for instance, what if the LaTeX3 folks change those definitions?

share|improve this question
add comment

1 Answer

Probably the easiest thing would be to redefine \addcontentsline as all the sectioning commands pretty much do something like

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

as long as tocdepth is set suitably. You could make that write to the toc and your additional file.

share|improve this answer
    
Thank you David. I take your comment to confirm that I haven't overlooked a natural way to do it. I use that command to do a number of things so I'll have to think about if I can modify it to this purpose. Thanks, Jim –  Jim Hefferon Mar 10 '12 at 22:09
1  
Just remember to redefine \addcontentsline before loading hyperref, because this package redefines it adding to the existent functionality. –  egreg Mar 10 '12 at 22:37
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.