# LaTeX, dvipng and pipes

I am trying to create PNG images for each page in a LaTeX document on the fly. Since the startup time of LaTeX is the limiting factor for speed I tried the following approach using names pipes:

Bash 1 (listening):

mknod test.dvi p # create named pipe 'test.dvi'
dvipng test.dvi  # let dvipng wait for input on that named pipe


Bash 2 (sending):

echo "\\documentclass{article}\\pagestyle{empty}\\begin{document}text\\end{document}" \
| latex -jobname=test # typeset small LaTeX document into test.dvi


The LaTeX run finishes successfully. But dvipng quits with the following error:

dvipng: Fatal error, POST occurs within page


Surprisingly, dvipng works as expected when I redirect the test.dvi to a regular file using

cat test.dvi > test2.dvi
dvipng test2.dvi # results in test21.png


on Bash 1.

Hopefully, I can sent continuous data to LaTeX so that dvipng outputs a .png each time latex outputs a page to test.dvi. If you have better approaches than the one above please let me know! Note that I also precompiled the preamble of the LaTeX document. But this is still not fast enough.

-
Is it easier to create a pdf and convert that into individual pngs? – mlt Oct 5 '12 at 17:35
Maybe pdflatex and a tool for png conversion would solve the pipe related issue. But pdflatex is slow compared to latex. Also, dvipng is very fast. Currently I use a RAM disk to solve the speed issue. But using pipes would be much nicer. – porst17 Oct 5 '12 at 21:35