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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use LaTeX to output DVI files, then use DVIPNG to make images for, say, a website. The problem is when I take something like this:

Hello World

and run LaTex on it, then run DVIPNG on the resultant DVI file, I get an image with lots of whitespace to the left and above the text.

I have two questions: One, how do I remove the whitespace to the left and about the "Hello World"? And two, how do I make the text larger? I have done this before correctly, I just don't remember how.

share|improve this question
Besides the answers provided, make sure you have \usepackage[active]{preview} in the preamble and call dvipng with --height to be able to place the image right with regards to the text baseline. – eudoxos Nov 11 '11 at 15:56
up vote 3 down vote accepted

Use the standalone document class:

Hello World

I would convert this to PDF and then convert it to PNG. The reason for standalone is because the output is a cropped version of the document content.

The above example, however, does not work well with displayed math equations, as noted in LaTeX math whitespace. One work-around (apart from the solution presented there), is to use pdfcrop to trim off excess white space around any text. Use it in the following context

pdfcrop <filename>.pdf <filename>.pdf

which will overwrite <filename>.pdf with a trimmed version of itself.

Formatting the font size and shape can be done using the following commands:


The above was taken verbatim from the LateX2e font selection guide.

share|improve this answer
Thank you. It works for that now. But when I apply this to math, I still have whitespace on the left (it is gone on the top though). – chbaker0 Oct 9 '11 at 19:07
I see your point. After compiling the document, use pdfcrop file.pdf file.pdf, which will overwrite file.pdf with a cropped version of itself, removing any white space around it. pdfcrop forms part of a full LaTeX distribution (it's a Perl script). To this end, you could also compile a document using your original MWE, since the standalone documentclass becomes superfluous. I'll update my answer to reflect this. – Werner Oct 9 '11 at 20:40

The dvipng manual says:

-T image_size

Set the image size to image_size which can be either of bbox, tight, or a comma-separated pair of dimensions hsize,vsize such as .1in,.3cm. The default is bbox which produces a .png that includes all ink put on the page and in addition the DVI origin, located 1in from the top and 1in from the left edge of the paper. This usually gives whitespace above and to the left in the produced image. The value tight will make dvipng only include all ink put on the page, producing neat images.

So use -T tight

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.