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 understand that TeX uses \headline to place headers. If \headline did not exist, how would one implement a simple version of the same? Additionally, where might one find simple documentation of how \headline is implemented beyond The TeXbook? Of one particular interest is the use of the commands used to position the header text (or the box in which the header is set).

share|improve this question
    
the plain tugboat.sty (on ctan) implements running heads in a different way. it requires tinkering with the \output routine, and may be more complex than desired here. –  barbara beeton Aug 29 '12 at 12:20
add comment

1 Answer

up vote 4 down vote accepted

\headline is a named token register in plain.tex, assigned with \newtoks\headline, and set to \headline={\hfil} (blank). Its content is then used in the output routine via the \makeheadline macro (simplified, and written "open"):

\def\makeheadline{\vbox to 0pt{\vskip-22.5pt
  \hbox to \hsize{\vbox to 8.5pt{}\the\headline}\vss}\nointerlineskip}

That is, the default contains "hard constants" for use with a 10pt setting. And the content of the register is used in horizontal mode (so cannot have vertical mode material if not inside a \vbox), spanning the h orizontal size of the textblock. That whole box is set so that it doesn't take any vertical space, and backed up by the constant of 22.5pt above the actual textblock.

Knuth writes in the TeXbook regarding that 22.5pt constant:

The magic constant -22.5pt is equal to (topskip - height of strut - 2(baselineskip)), i.e., 10pt - 8.5pt - 24pt; this places the reference point of the headline exactly 24pt above the reference point of the top line on the page, unless the headline or the top line are excessively large.

The macro is also refraining inserting the normal interlineskip between the headline and the typeblock.

So setting for example:

\headline={Testing headline\hfill \folio}

would have "Testing headline" to the left, then the glue pushing the page number to the right.

Now, this would keep the same for every page, but say you want to have different head for verso and recto you could do something like

\newtoks\versohead \versohead={\folio\hfill Testing headline}
\newtoks\rectohead \rectohead={Testing headline\hfill \folio}
\headline={\ifodd\pageno\the\versohead\else\the\rectohead\fi}
share|improve this answer
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.