# What happens to fonts (and robust commands) in shipout?

The following example does not produce quite the output I expect:

\documentclass{article}

\let\origshipout\shipout
\def\shipout{\origshipout\vbox{
%\normalsize
\emph{hello}}\origshipout}

\begin{document}
This should appear on \emph{page two}.
\end{document}


When run, this produces a verso page containing the text ‘hello’, and recto page with ‘This should appear on page two’ – that's fine.

However I would also expect the ‘hello’ to be emphasised, but it instead appears in the same (?) upright face as the recto page. In the real problem case, of which this is a reduction, I also see hard-to-interpret but broadly consistent problems with maths fonts. If I uncomment the \normalsize, then the verso page contains instead ‘1012hello’, which I take to be the \@xpt \@xiipt in the expansion of \normalsize to \@setfontsize \normalsize \@xpt \@xiipt ....

(The real case uses the ‘everyshi’ package; that neither fixes nor causes the problem)

So I'm perplexed: looking at latex.ltx, I can't see anything relevant in \output or in \@outputpage; the \@outputpage macro itself uses \normalsize (meaning it's not for some reason disabled); I can't see anything which disables \@setfontsize at any point; inserting \normalfont/\reset@font doesn't magically make things better. Indeed I can't see anything obviously relating to fonts in \output or \@outputpage – presumably there is something non-obvious there.

The corresponding Plain document:

\let\origshipout\shipout
\def\shipout{\origshipout\vbox{{\it hello}}\origshipout}
This should appear on {\it page two}.
\bye


works as expected (so I'm not going mad).

What am I missing?

• Hint: Try adding \tracingall in your box, and then think about how \protect works :-) – Joseph Wright Oct 11 '14 at 21:19
• You code gives me italicised "page two". – Przemysław Scherwentke Oct 11 '14 at 21:37
• Aha...........! – Norman Gray Oct 11 '14 at 21:39

Commands such as \emph are ‘robust’ commands, which means that they are defined in such a way as to include a call to \protect. This is so that such commands can survive being used in ‘moving arguments’ such as section names. This protection is implemented by tactical redefinitions of \protect at various points within the LaTeX code.
In the normal run of text, \protect is just \relax — no protection is required. In the context within the question, however, \protect is \noexpand, which causes the \emph to expand to simply \relax, which causes exactly the behaviour described.
With this understood, the solution is obvious, and adding \let\protect\relax inside the redefined \shipout causes everything to work as expected.
• I can imagine that could be dangerous, and in this case the redefinition is indeed kept firmly within a group. Here, the material being set is text gathered from a previous run, to be set on a verso page (sort of marginpar++); the text in question is deliberately not expanded (\unexpanded{...}) on being written to the .aux file from where it's later retrieved. This is a quick hack which turned, slightly to my surprise, into a potentially released package: bitbucket.org/nxg/versonotes – Norman Gray Oct 12 '14 at 20:27