weave tex.web     
pdftex tex.tex

generates a pdf as follows with a table of content and a document body:

section 13 in pdf

Pay attention: The table of content is below the document!

table of content

I want the table of content listing all sections between two entries in the TOC in the same layout as in "See also sections" in section 13 of the body, everything indented left and right. In this way you can navigate directly from the table of contents to all sections.

How to do this?

This is a follow up question to Where to find an interactive PDF or HTML version of the tex.web documentation?

And here's a follow up question How to add a second table of content to tex.pdf with a LaTeX package by using the contents.tex generated by pdfwebmac? to this question.

  • 2
    This is nothing to do with texdoc per se: it just opens the approprite PDF
    – Joseph Wright
    Jul 28 '19 at 16:12
  • 2
    texdoc just calls a PDF viewer. The operation should be on the weave side, by changing the input macro file. Not something I'd like to study, sorry.
    – egreg
    Jul 28 '19 at 16:13
  • 2
    There's something weird in the code example at the top of your question: texdoc tex will always open a fixed documentation file that was installed by your distribution (e.g. /usr/local/texlive/2018/texmf-dist/doc/generic/knuth/tex/tex.pdf). I think/hope you meant to write weave tex.web followed by pdftex tex.tex followed by opening the generated tex.pdf (and not using texdoc anymore). Jul 29 '19 at 15:20
  • 1
    @CarpeDiemKopi the table of contents should be at the end of the pdf by default
    – texdr.aft
    Jul 29 '19 at 16:18
  • 1
    Note that for a clickable table of contents you should use pdfwebmac, not webmac -- as mentioned in the first paragraph of @texdr.aft's answer. Jul 29 '19 at 16:38

As @egreg said, you have to modify the WEB macro file. For output with hyperlinks, this file is called pdfwebmac.tex. (For use with non-pdfTeX, the file is called webmac.tex.)

The changes concern the output to the CONTENTS.tex file. This output is produced by the \Z macro, which is called every time a starred section is created with \N; the definition of \N is:

\outer\def\N#1.#2.{\MN#1.\vfil\eject % beginning of starred section
  \def\rhead{\uppercase{\ignorespaces#2}} % define running headline
  \message{*\modno} % progress report
  \edef\next{\write\cont{\Z{#2}{\modno}{\the\pageno}}}\next % to contents file

The important part is ...\write\cont{\Z{#2}{\modno}{\the\pageno}}}. Just copy this line into the definition for \M, which is used for unstarred sections (changing \Z{#2} into \Z{#1} to avoid parameter mismatching):

\outer\def\M#1.{\MN#1.\ifon\vfil\penalty-100\vfilneg % beginning of section
  \edef\next{\write\cont{\Z{#1}{\modno}{\the\pageno}}}\next % to contents file

If you're unhappy with the formatting then you could define another command instead of \Z to use with unstarred modules, but that's beyond the scope of this answer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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