# How to change table of content layout for a pdf document created from a web source file?

weave tex.web
pdftex tex.tex


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

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

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.

• This is nothing to do with texdoc per se: it just opens the approprite PDF Jul 28 '19 at 16:12
• 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. Jul 28 '19 at 16:13
• 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
• @CarpeDiemKopi the table of contents should be at the end of the pdf by default Jul 29 '19 at 16:18
• 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

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

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.