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.

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:

\documentclass{article}
\pagestyle{empty}
\begin{document}
Hello World
\end{document}

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

2 Answers 2

up vote 2 down vote accepted

Use the standalone document class:

\documentclass{standalone}
\begin{document}
Hello World
\end{document}

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:

Fonts

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). –  mebob 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
add comment

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