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:

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

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

4 Answers

up vote 9 down vote accepted

I use something like:

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

But it works for PDFTeX/LuaTeX only.

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

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
add comment

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}
share|improve this answer
add comment

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