5

I have a switch I'd like to turn off for the headers and footers but keep on for the main body text. What commands actually tell TeX to write the headers and footers after the body text has been set and how would I add a switch before and after these commands (with etoolbox or similar?).

What I'm looking for is something like \AtBeginPrintHeader. In analogy to \AtBeginDocument, or the hooks from everyhook which allow you to do something at the beginning of each paragraph, mathmode etc. I know there's bophook for doing stuff at the beginning of the page, but I need something that does something between the main body text being written and the headers and footers being written.

Patching \ohead with \apptocmd from etoolbox obviously doesn't work because it's not \ohead that is called when TeX tries to set a header. \ohead sets the relevant internal macros to be what they should so that the header you want is set. So I guess what I want to know is what actually happens when the header is being set: what command should I \appto in order to have something happen right before the header is set?

Is there such a mechanism? Is it compatible with scrpage2 and fancyhdr?

Here's the example. I've used everyhook to add input line numbers to each paragraph. Awkwardly, this includes paragraphs in the header and footer.

\documentclass{article}
\usepackage{everyhook,marginnote}
\newif\ifnotmarginhook
\notmarginhooktrue
\PushPostHook{par}{%
  \ifnotmarginhook%
  \notmarginhookfalse%
  {\marginnote{\small\ttfamily\the\inputlineno}}%
  \notmarginhooktrue%
  \fi%
}
\usepackage{scrpage2}
\pagestyle{scrheadings}
\newcounter{firstline}
\newcommand\nolineno[1]{\notmarginhookfalse #1\notmarginhooktrue}
\ohead{Problem $\to$}
\begin{document}
Some text
\end{document}

So I want to turn \notmarginhookfalse for the headers, and then turning it back on before I set more body text... Using \ohead{\notmarginhookfalse Text} doesn't seem to work.

So is there either a way to hook into the headers or some internal switch so I could do something like \ifheaders and modify things that way

Seamus
  • 73,242

1 Answers1

1

If you load the everyhook package with the [excludeor] option, your solution should work as you expect. (I don't understand the numbering system in your example, but that's not relevant to the solution.)

\documentclass{article}
\usepackage[excludeor]{everyhook}
\usepackage{marginnote}
\newif\ifnotmarginhook
\notmarginhooktrue
\PushPostHook{par}{%
  \ifnotmarginhook%
  \notmarginhookfalse%
  {\marginnote{\small\ttfamily\the\inputlineno}}%
  \notmarginhooktrue%
  \fi%
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newcounter{firstline}
\newcommand\nolineno[1]{\notmarginhookfalse #1\notmarginhooktrue}
\rhead{\nolineno{Problem $\to$}}
\begin{document}
Some text

Some text
\end{document}

partial output of code

Alan Munn
  • 218,180