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.


I use something like:

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

But it works for PDFTeX/LuaTeX only.

  • 2
    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
\mbox{\Huge buffer}

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.}}

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.