dvipng
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Dvipng] sleeping --follow


From: Marc Culler
Subject: Re: [Dvipng] sleeping --follow
Date: Wed, 1 Aug 2012 12:15:41 -0500
User-agent: Mutt/1.5.20 (2009-06-14)

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

> 2012-05-31 19:14, Benito van der Zander skrev:
>
>     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.
>
>     So, I suggest that it does something like this:
>
>     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.

Attachment: dvipng_patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]