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 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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
Seamus may be referring to this related comment on linking your source code with your PDF output. –  Werner Aug 9 '11 at 19:21
    
I'm actually referring to this question but yes. –  Seamus Aug 9 '11 at 21:18
    
I like this solution to my actual problem, but I guess I'd still like a general solution to hooking into the header/footer mechanism. –  Seamus Aug 9 '11 at 21:20
    
But I think that the general solution is the same; the problem with your example was in how the everyhook package works, not with the possibility of setting conditional elements within the header and footer. –  Alan Munn Aug 9 '11 at 21:28

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.