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



This should appear on \emph{page two}.

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:

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

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

What am I missing?

  • 2
    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.

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

| improve this answer | |
  • 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). – Frank Mittelbach Oct 12 '14 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 – Norman Gray Oct 12 '14 at 20:27
  • ...and now also at CTAN – Norman Gray Feb 18 '15 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.