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'm just reading the everyshi manual, and it says:

This package provides the hooks \EveryShipout and \AtNextShipout whose arguments are executed after the output routine has constructed \box255, and before \shipout is called.

This seems to imply this \box255 is somehow special; but I tried looking it up on the net and could find terribly much about it.

So, can anyone explain why would \box255 be special, and possibly point to a quick reading or tutorial involving it?

share|improve this question
1  
Please do not use a closing statement. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  Martin Scharrer May 26 '12 at 17:28
1  
AFAIK the whole page is stored in \box255. \box<number> is just a way to reference one of TeX box registers. TeX (at least the non-extended version) has only 256 box registers (0-255) and 255 is simply the last one. For some reason it is reserved for the output routine. –  Martin Scharrer May 26 '12 at 17:29
1  
Note that the atbegshi package "is a modern reimplementation of package everyshi" (sic) and uses \AtBeginShipoutBox instead of \box255. However it might use box #255 internally anyway. –  Martin Scharrer May 26 '12 at 17:35
2  
Thanks for the note, @MartinScharrer - I'm aware of the closing statements policy, but I got used to adding them to sort of "warm up" the conversation :) Btw, would you mind putting your \box255 comments as an answer? I think they are a perfectly acceptable explanation (unless a more in-depth answer shows up). Many thanks - cheers! –  sdaau May 26 '12 at 17:40
add comment

2 Answers

up vote 22 down vote accepted

When TeX decides it's time to eject a page (because one has been filled up or the user has issued a command to the same effect), it does some maintenance work and then packs the page's contents into the box register 255.

Next it calls the output routine, which is supposed to do several things: adding the header and the footer, incrementing the page number and so on.

The simplest output routine would be

\output{\shipout\box255}

which would do nothing to the page other than shipping it out. The standard output routine in Plain TeX is (in simplified form)

\output={\plainoutput}
\def\plainoutput{\shipout\vbox{\makeheadline\pagebody\makefootline}%
  \advancepageno
  \ifnum\outputpenalty>-20000 \else\dosupereject\fi}
\def\pagebody{\vbox to\vsize{\boxmaxdepth=\maxdepth \pagecontents}}
\def\makeheadline{\vbox to 0pt{\vskip-22.5pt
    \line{\vbox to8.5pt{}\the\headline}\vss}\nointerlineskip}
\def\makefootline{\baselineskip=24pt \lineskiplimit=0pt
    \line{\the\footline}}
\def\dosupereject{\ifnum\insertpenalties>0 % something is being held over
  \line{}\kern-\topskip\nobreak\vfill\supereject\fi}
\def\pagecontents{\ifvoid\topins\else\unvbox\topins\fi
  \dimen@=\dp255 \unvbox255
  \ifvoid\footins\else % footnote info is present
    \vskip\skip\footins \footnoterule \unvbox\footins\fi
  \ifr@ggedbottom \kern-\dimen@ \vfil \fi}
\def\footnoterule{\kern-3pt
  \hrule width 2truein \kern 2.6pt} % the \hrule is .4pt high

where the usage of \box255 is more complicated because it keeps track of insertions such as floating figures and footnotes; the \shipout operations is performed to another box which is in turn built using the contents of \box255. (I'm not even trying and confront the LaTeX output routine, which is vastly more complicated than this one, but the sense of the thing is just the same.)

This box register is automatically managed by TeX and it's quite dangerous to make use of it (if your name isn't Heiko Oberdiek).

The package atbegshi does some trick by redefining \shipout, adding hooks to it so the contents of the box being shipped out can be tweaked in various ways.

The first set of macros doing something of this can be found in quire.tex, a remarkable piece of code that I believe is still usable even with LaTeX; but there are easier ways now to achieve the same effect.

% quire.tex: Macros for making booklets, printing double pages, and
%            printing outlines and crop marks.
% version: 1.0  release: 19 January 1991
%
% copyright (c) 1991 Marcel R. van der Goot

that used a similar trick for producing quires, that is, sets of pages to be printed on the same sheet of paper and then cut and folded.

share|improve this answer
    
Many thanks @egreg for the great answer, especially the explanation of the output routine - cheers! –  sdaau May 26 '12 at 23:45
    
I keep finding answers of yours that I have mysteriously neglected to upvote during my hiatus. –  Ryan Reich Jul 8 '12 at 5:29
add comment

I found this: http://www.scribd.com/doc/91214700/444/Output-and-box255

share|improve this answer
1  
This is from TexByTopic which is available free. –  Yiannis Lazarides May 27 '12 at 5:42
    
Thanks for pointing to that resource, walle1357 and @YiannisLazarides; here's TeX by Topic homepage - cheers! –  sdaau May 27 '12 at 9:26
add comment

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.