# Resize paper to mbox

Is it possible to define a function where the page is resized to exactly the dimension of an mbox? For example, I want to do something like the following:

\documentclass{report}
\thispagestyle{empty}
\begin{document}
\mbox{\Huge buffer}
\end{document}


And have the output be a PDF whose dimension are exactly the size of the bounding box around the word "buffer". Currently, I am using the program pdfcrop to trim the resulting image, but this is a hack. I was wondering if there was a way to do this in TeX natively.

-
How does LaTeXiT do this? – Jukka Suomela Sep 9 '10 at 20:36
– Martin Scharrer Apr 7 '11 at 16:30

I use something like:

\newbox\mybox
\setbox\mybox=\hbox{stuff goes here}
\pdfhorigin=0pt
\pdfvorigin=0pt
\pdfpagewidth=\wd\mybox
\pdfpageheight=\ht\mybox
\shipout\box\mybox


But it works for PDFTeX/LuaTeX only.

-
BTW, ConTeXt has a \startTEXpage \stopTEXpage that does exactly that. – Khaled Hosny Sep 8 '10 at 20:55
I think this can be made to work for all engines by using something like \voffset=-1in \hoffset=-1in instead. – Will Robertson Nov 18 '10 at 6:48
@Will: I'm sure it can, but I certainly don't know how, if you have a working piece of code I'd be grateful! – Khaled Hosny Nov 19 '10 at 11:01

For the type of things that you seem to be doing, perhaps you might also want to look at the preview package. The \mbox isn't necessary, and it gives you a way to make a series of properly trimmed images, in a single run.

-
I think this is the best option here! – Will Robertson Nov 18 '10 at 6:49
preview's definitely the way to go! – Geoffrey Jones Nov 18 '10 at 13:45

You can use the standalone class with either the preview or crop option. The first was the default for v0.x and uses the preview package. The second is new with v1.0 and the default for v1.x. It boxes the content and resizes the page to fit it. This works similar to Khaled Hosny's answer but works with LaTeX in many flavors: latex (DVI mode), pdflatex, xelatex and lualatex.

\documentclass[border=0pt]{standalone}% Add maybe crop or preview manually
\begin{document}
\mbox{\Huge buffer}
\end{document}

-

Here is one with eplain, and I think this form of \special works only with XeTeX:

\input eplain
\hoffset=-1in
\voffset=-1in
\hruledefaultheight=0pt
\hruledefaultdepth=0pt
\vruledefaultwidth=0pt
\boxitspace=1pt % amount of whitespace on all sides
\setbox0\boxit{\hbox{This content right here will be the whole page.}}
\special{papersize=\the\wd0,\the\ht0}
\box0
\bye

-