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.

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:

\mbox{\Huge buffer}

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.

share|improve this question
How does LaTeXiT do this? –  Jukka Suomela Sep 9 '10 at 20:36

4 Answers 4

up vote 9 down vote accepted

I use something like:

\setbox\mybox=\hbox{stuff goes here}
\advance\pdfpageheight by \dp\mybox

But it works for PDFTeX/LuaTeX only.

share|improve this answer
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.

share|improve this answer
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
\mbox{\Huge buffer}
share|improve this answer

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

\input eplain
\boxitspace=1pt % amount of whitespace on all sides
\setbox0\boxit{\hbox{This content right here will be the whole page.}}
share|improve this answer

Your Answer


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.