Discussion:
[Dvipng] sleeping --follow
Marc Culler
2012-08-01 17:15:41 UTC
Permalink
Hello all,

I just read the README file and learned about this list. :^)

The attached patch to dvi.c implements a solution to the problem of
delays caused by the 1-second sleep when dvipng hits an EOF. It is
different from the one suggested by Benito below; it eliminates
sleeping altogether. It allows instant generation of images of
snippets of TeX code (which is my application), or faster conversion
of an entire file.

The patch also fixes a bug that causes the --follow option to fail in
OS X. (Fixing this bug just requires adding one line: a call to clearerr().
In OS X, fgetc sets an error flag when it returns EOF, and
any subsequent calls will hang if clearerr() is not called first.)

Here is the scheme implemented in my patch. When dvipng starts up, it
checks whether its input dvi file is a named pipe. If so, it replaces
the input file with a temporary file and does the following: whenever
fgetc returns EOF reading the temp file, dvipng tries to read one byte
from the pipe. This read will block until something is written to the
pipe. As soon as dvipng gets the byte, it completely drains the pipe,
appending everything to the temp file. Then it goes back to reading
the temp file. Typically the copying process should happen just once
per page.

To use this you should first use mkfifo to create a fifo named, say,
myfifo.dvi Then start dvipng like this:
dvipng -D300 -Ttight --follow myfifo
and start TeX like this:
tex -ipc -jobname=myfifo \\relax\\nopagenumbers
Each time you send something like
$x+y=1$\vfill\eject
to tex's stdin it will (instantly) produce a png image file of the formula.

Or, you can do something like this:
dvipng --follow myfifo &
latex -ipc -jobname=myfifo mytexfile

Note that dvipng cannot use a pipe for its input, since it needs to
seek backwards through the dvi file and pipes do not support seek.

Currently this code does not delete the temp file -- I am not sure if
that is a good idea or not.

- Marc
Hi,
reading the documentation you would think that you can use the --follow
option to speed up a tex->png conversion,
because you can run latex and dvipng in parallel.
Unfortunately, it becomes much slower, because for most small documents
latex runs in less than a second, but
dvipng sleeps for 1s, if the dvi-file is not complete.
1. for the first 16 ms, dvipng shouldn't sleep at all, but try to read
continuously from the file
2. afterwards sleep for 1 ms, then for 4 ms, 9, 16, ... up to a maximum
of 1024 ms
3. once a character has been read and processed, it should go back to
step 1, if the file is still not complete.
Jan-Åke Larsson
2012-08-01 17:30:20 UTC
Permalink
Hi,
thanks for the suggestions, both of you. Especially good with a patch.

I will include this functionality, but would want to avoid the tempfile.

Just now I'm on vacation: all good things come to those who wait.
/JÅ

Loading...