[Tex/LaTex] Plain TeX: running header with section name

header-footerplain-texsectioning

I want to create a TeX document with sections and a running header containing the name of the current section. I know I can use \mark{} to mark the section headings and then use \topmark or \firstmark to show the section name in my header. The problem is that neither \topmark nor \firstmark do what I want (they're actually more suitable for typesetting dictionaries).

I would like the header to reflect the section the contents of which appear at the very top of the current page. In other words, I want to use mostly \topmark, but when a new section begins on the current page before any other text before it, I want to use \firstmark (or, alternatively, leave the header blank), because then \topmark refers to the previous section and thus is irrelevant. Any ideas on how I could do that?

Best Answer

Usually the first page in a document has no header; if it's needed for some special application, one can say

\ifnum\pageno=1 \firstmark\else\topmark\fi

in the code for producing the header.