5

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?

3
  • 2
    Hint: Try adding \tracingall in your box, and then think about how \protect works :-)
    – Joseph Wright
    Oct 11, 2014 at 21:19
  • You code gives me italicised "page two". Oct 11, 2014 at 21:37
  • Aha...........! Oct 11, 2014 at 21:39

1 Answer 1

6

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.

[The credit for this answer is entirely Joseph Wright's, from his comment to the question.]

3
  • And the reason for this is that LaTeX is designed to expect a this stage only to expand material inside writes and similar stuff where this is the right kind of setting. So putting in a \let\protect\relax is rather dangerous unless that is limited in scope (which of course is possible). Perhaps something that evershi chould take care of (but doing properly then). Oct 12, 2014 at 19:40
  • 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 Oct 12, 2014 at 20:27
  • ...and now also at CTAN Feb 18, 2015 at 16:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .