3

When a new page is added to the document by executing a \shipout command, what settings are carried over to the new page from where the \shipout was executed?

For instance, as the following example demonstrates, the font settings carry over, while the color settings are lost.

\documentclass{article}
\usepackage{xcolor}
\begin{document}%
\font\myfont=cmtt17\myfont%
\color{red}%
\shipout\hbox{Hello, world!}%
\end{document}

Resulting pdf:

Shipped-out document

However, if I start a new page with \newpage or \eject:

\documentclass{article}
\usepackage{xcolor}
\begin{document}
\font\myfont=cmtt17\myfont%
\color{red}%
\newpage% also works with \eject
Hello, world!
\end{document}

both settings carry over:

Color settings carry over

How can I predict what settings will carry over when a new page is started with \shipout? What's the rule? I'm not asking only about font and color settings, but about every potentially possible setting, or at least about every possible setting that is native to TeX (I know color is not native to TeX).

4
  • 2
    "every possible setting" is a lot. Regarding colors: there are not native to tex, so you must use them correctly. In your example \shipout\hbox{\color@setgroup Hello, world!\color@endgroup}. Aug 7 '17 at 18:52
  • @UlrikeFischer: So how about every possible setting that is native to TeX?
    – Evan Aad
    Aug 7 '17 at 18:57
  • Starting points: "The TeXbook" by Donald E. Knuth, or "TeX by Topic" by Victor Eijkhout. Aug 7 '17 at 19:34
  • as \showbox output shows, fonts are an intrinsic part of the box structure. colours are just saved or not saved in a box as \special or equivalent \pdfcolor commands to change the sate. whether colour is restored at a page break depends on the macros you use and the back end driver being used. see the color package documentation, pdftex, latex+dvips, xetex, luatex all have different behaviour in edge cases Aug 7 '17 at 20:31
3

In

\documentclass{article}
\usepackage{xcolor}
\begin{document}%
\font\myfont=cmtt17\myfont%
\color{red}%
\shipout\hbox{Hello, world!}%
\end{document}

The \color command puts a whatsit on to the main vertical list that tells the back end to set the current colour to red.

You then \shipout a horizontal box directly to the output, without using the main vertical list at all, so the text is output (in black) at the start of the pdf. Any text output from the main vertical list would be red but actually latex discards pages at \clearpage or \end{document} that only have a whatsit and no box or rule, and so in fact the red colour instruction isn't output to the pdf at all as you have no text in this document, so the only page output is the \shipout horizontal box.

4
  • There is a tendency to lose colour at page breaks anyway. At least, the output produced by latexdiff has to be hand-edited to restore colour after page breaks in many, but not all, cases. In these cases, LaTeX certainly is not discarding pages which contain only a whatsit (which I've never really known what it is) because all my pages have content and the text before the page breaks is always correctly coloured. This is a huge pain, actually. I don't trust myself to get the edits right in all cases ....
    – cfr
    Aug 7 '17 at 22:10
  • @cfr yes see my comment under the question, how colour reacts at a page break is tricky and highly dependent on the macros and back end driver in use, but this question was (apparently) specifically about \shipout in which tex page breaking is not involved at all. Aug 7 '17 at 22:17
  • By the way, does LaTeX redefine the \shipout primitive?
    – Evan Aad
    Aug 8 '17 at 15:27
  • no, but you don't need to ask, just add \show\shipout in any latex document to see the current definition. Aug 8 '17 at 15:40

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.