🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text.tex
Article #10376

Re: TeXnical question

#10376
From: Victor Eijkhout
Date: Wed, 19 Jun 1991 21:17
65 lines
3594 bytes
zjdg11@hou.amoco.com (Jim Graham) writes:

>\def\mainheading#1{\goodbreak
>    \centerline{\subtitles\uppercase{#1}} \par
>    \ifcontents
>       \immediate\write\contentsfile{|countitem \uppercase{#1} |dotfill \folio}
>       \immediate\write\contentsfile{}
>    \fi
>    }

>Note, when the table of contents is pulled in, "|" is defined as an escape
>char, just like \ normally is.  I had to do this because I couldn't figure
>out how to print the "\" to the file as such (if someone can help there as
>well, I'm all ears...or eyes, as the case may be  ;-)  ).

Do \string\countitem or \noexpand\countitem

>If I call this as \mainheading{foo} I'll end up with something like
>   |countitem FOO |dotfill 42

>Most of the time, this works out to be correct.  HOWEVER, and this is where
>I need some assistance, if it just so happens that the heading WAS going to
>be written in at the bottom of the page (with the paragraph starting at the
>top of the next page) before the \goodbreak fixed that, TeX still lists the
>page number for that section as being the previous page, when in fact it has
>been moved into the next page.

Well, if you just remove the \immediate everything will be fine,
because then the write is executed when the part of the page
that contains it is actually written out.

However, you may also want to write the chapter number, somehting like
    \write\tocfile{\string\tocchap{\chapno}{#1}{\folio}}
The problem with this is that if more than one chapter starts
on a certain page (which can easily happen with sections or subsections)
you will twice get the second chapter number. Remedy for that:
    \edef\act{\noexpand\write{\string\tocchap{\chapno}{#1}{\noexpand\folio}}}
    \act
In the \edef the chapternumber will be expanded, and the
write statement will contain th correct number.

>Now, I'm sure there's something stupid that I'm missing....but....

You were missing something indeed, but it's not stupid. All of this
is quite nontrivial. Table of contents are particularly nasty,
because you may want to read them in while you are building them
(for instance the toc comes after the preface, and the preface should
appear in the toc, so the file is open for writing, and you
want to read it in in that place).

>I'm kinda looking for 2 things here.  First, I'd really like to know how
>to fix this situation.  Second, if someone can point me to the right page
>numbers in The TeXbook to learn more about this situation, I'd love to hear
>it.

The only place in the TeXbook that treats this is exercise (!!!) 21.10.
I suggest you keep an eye peeled for 'TeX in practice' by Stephan
von Bechtolsheim and 'A TeXnician's Reference Guide' by yours truly,
which are both to appear later this year and which treat this sort
of stuff in detail.

Another option is to take an existing macro packag that has the
toc facility, and try to understand what's happening there.

Victor.
Technical Details
Message-ID: <1991Jun19.211753.4838@csrd.uiuc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!spool.mu.edu!sdd.hp.com!caen!ox.com!umich!vela!m.cs.uiuc.edu!roundup.crhc.uiuc.edu!ux1.cso.uiuc.edu!csrd.uiuc.edu!s41.csrd.uiuc.edu!eijkhout
References: <1991Jun19.125224.19855@hou.amoco.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!spool.mu.edu!sdd.hp.com!caen!ox.com!umich!vela!m.cs.uiuc.edu!roundup.crhc.uiuc.edu!ux1.cso.uiuc.edu!csrd.uiuc.edu!s41.csrd.uiuc.edu!eijkhout
From: eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout)
Newsgroups: comp.text.tex
Subject: Re: TeXnical question
Message-ID: <1991Jun19.211753.4838@csrd.uiuc.edu>
Date: 19 Jun 91 21:17:53 GMT
References: <1991Jun19.125224.19855@hou.amoco.com>
Sender: news@csrd.uiuc.edu (news)
Organization: UIUC Center for Supercomputing Research and Development
Lines: 65