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.

This is probably going to sound like a strange request (trust me that there's a good reason for it), but is it possible to have LaTeX compile straight to an image file instead of to something like PDF, PostScript, or DVI? I know there are probably good ways to convert those formats to an image instead, but I figured I would see if there was a more direct route.

Some requirements:

  • The image format can be either PNG or JPG.
  • I'm not looking just for a single expression or something (I'm aware of tools like tex2im). I want to compile an entire document.
  • There should be one image for each page in the corresponding PDF, with the same resolution, margins, etc. It should be identical to just converting each page faithfully.

In case this turns out to be impossible for some reason, I would also be happy with a simple conversion routine to accomplish this with a PDF generated by pdflatex.

Thanks!

share|improve this question
4  
TeX and LaTeX are both designed to output the description of a typeset page. In other words, they target page description languages such as DVI, PostScript or PDF. I doubt you will find a TeX backend that directly targets images since that is not a meaningful format for TeX output. That being said, there are a pile of conversion programs that will do the job. –  Sharpie Aug 14 '10 at 7:31
1  
You can convert a LaTeX file to PNG using the standalone class, see e.g. Compile a LaTeX document into a PNG image that's as short as possible. However, this is intendend for smaller things, like picture environments and not for whole documents. –  Martin Scharrer Feb 5 '13 at 22:21

3 Answers 3

up vote 13 down vote accepted

Probably the best way is latex followed by dvipng. The main advantages over pdflatex followed by pdf2png are: it is faster; it can start working on the dvi while latex is still in the process of producing the dvi. It's optimized for producing screen-resolution antialiased images at maximum speed. If your foo.dvi has 4 pages then you get foo1.png foo2.png foo3.png foo4.png.

share|improve this answer

You want the preview package. For example, this is what I use for tikz:

\RequirePackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{1pt}%

You can insert as many tikzpicture env as you wish and each one appears on a single page with the page fit to the image.

share|improve this answer
    
Hey Leo, thanks for the comment. However, unless I'm misunderstanding your answer and what I found by googling the preview package, this would require me to explicitly wrap each page in an environment. This doesn't quite suit my purpose -- I just want the images to be separated the same way pdflatex separates pages in a PDF -- automatically and at compile-time. Unless I'm missing something, this won't do that. Thanks though :) –  Adrian Petrescu Aug 14 '10 at 6:41
    
(The preview package does sound really neat though, and I can see lots and lots of uses for it. Definitely going into my toolbox) –  Adrian Petrescu Aug 14 '10 at 6:42
1  
@Adrian: preview is used when you want to create an image from a "semantic" piece of a LaTeX document - a figure, table, equation, etc. - rather than a "visual" piece like a page. In other words, you use preview when the things you want to turn into images are already wrapped by environments. I think Leo may have slightly misread your question. –  David Z Aug 14 '10 at 8:36
    
if you want the whole page to png/jpg, maybe check out dvipng though I have never used it myself. –  Leo Liu Aug 14 '10 at 9:29

There is not a way to get a PNG or JPG directly from LaTeX.

My guess is you're attempting to make some web service where users enter LaTeX and get pictures as a result. If this is the case, there are many that do this already and I should caution you that it is unsafe to directly expose LaTeX to the internet. If this is not the case, ignore this graf.

share|improve this answer
    
Not the case :) I believe there's approximately a billion services that do this already, anyway! Thanks for the feedback though; I guess this leaves me with pdf2png or somesuch? –  Adrian Petrescu Aug 14 '10 at 6:43
1  
(The real story, I guess I should mention, is that I'm porting a bunch of documents to an old device which doesn't support new-fangled stuff like PDF or PS, so I'd like to emulate them using images which it can display). –  Adrian Petrescu Aug 14 '10 at 6:47
2  
There was a TUG2010 talk on making images for the iPad: river-valley.tv/tex-and-the-ipad. You might want to take a look (I think the process used DVI conversion). –  Joseph Wright Aug 14 '10 at 6:58
    
@Joseph, thank you, will definitely be watching that :D –  Adrian Petrescu Aug 14 '10 at 7:06

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.