# LaTeX equivalent of an output routine

I would like to collect material and when a page is full I'd like to put it into a box with some heading and other decorations.

In Plain TeX I would use an output routine for this:

\count0=1
\hsize=140mm
\vsize=200mm

\output={\shipout\hbox{
\vbox to297mm{
\hrule
\hbox{\vrule\hskip3mm\vbox{\vskip2mm
\ifnum\count0 = 1
{\bf Page 1: First page heading}
\else
{\bf Page \the\count0: Further page}
\fi
\vskip2mm
\unvbox255
\vfill
}\hskip3mm\vrule}
\hrule
}
}

\vbox to 40mm{Some content\vfill}
\vbox to 40mm{Some content\vfill}
\vbox to 40mm{Some content\vfill}
\vbox to 40mm{Some content\vfill}
\vbox to 40mm{Some content\vfill}
\vbox to 40mm{Some content\vfill}
\vbox to 40mm{Some content\vfill}
\bye


which gives me the desired result (showing page 2 here):

Can I do something similar in LaTeX?

Just adding my example from above to a LaTeX document didn't work:

\documentclass{article}
\usepackage[a4paper]{geometry}
\pagestyle{empty}
\usepackage{tikz}

\begin{document}

\output={\shipout\hbox{
\vbox to297mm{
\hrule
\hbox{\vrule\hskip3mm\vbox{\vskip2mm
\vskip2mm
\unvbox255
\vfill
}\hskip3mm\vrule}
\hrule
}
}}

\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\end{tikzpicture}

\end{document}


Output routine didn't use all of \box255.

• Have you tried using your \output code in LaTeX? – Peter Wilson May 9 '19 at 17:26
• Hm, it actually kind of does the same thing if I put it in a document environment, with simple paragraphs of text at least. But when I start putting less simple things like a tikzpicture into the page, it breaks. – AndreKR May 9 '19 at 18:57
• Please add a sample document with the code that doesn't work for you – siracusa May 9 '19 at 19:04
• I'm not sure that I really understand what you are trying to do, but it looks like something that I would do with tcolorbox. – Ulrike Fischer May 9 '19 at 19:24
• @siracusa Done. – AndreKR May 9 '19 at 19:28