mgieseki / dvisvgm

A fast DVI, EPS, and PDF to SVG converter
https://dvisvgm.de
GNU General Public License v3.0
295 stars 28 forks source link

Request for --follow behaviour like dvipng #211

Open tecosaur opened 1 year ago

tecosaur commented 1 year ago

Hello again,

When using dvisvgm to generate a whole batch of previews to apply to a file when opened it's nice to have the images start showing up as fast as possible. Currently, dvipng is significantly better in this regard thanks to it's support for a --follow flag that allows it to watch an incomplete DVI file and spit out results as pages are appended to it.

 --follow
     Wait for data at end-of-file. One of the benefits of dvipng is that it does not read the postamble,
     so it can be started before TeX finishes. This switch makes dvipng wait at end-of-file for further
     output, unless it finds the POST marker that indicates the end of the DVI. This is similar to tail -f
     but for DVI-to-PNG conversion.

If dvisvgm could support this behaviour too, that would be quite nice.

mgieseki commented 1 year ago

Unfortunately, this is not so easy to do. There are several DVI extensions/specials that require information from following pages, like link targets, annotation data from PDF specials etc. In order to retrieve that information, it's necessary to pre-scan the entire DVI file before the actual conversion. The collected data also speed up the conversion of selected pages and page sequences because it's not necessary to process all DVI commands of skipped pages. With the current implementation, it's not easily possible to add a --follow option, as this would require a different processing model, which I can't afford to implement at the moment due to lack of time.

tecosaur commented 1 year ago

Hmm, I don't suppose it would be possible to support this under the assumption that each page can be processed independently?

mgieseki commented 1 year ago

I don't think so. For example, if the page contains a hyperref link pointing to a location on a page further back in the document, the SVG can't be generated before the information on the link target (i.e. page number an position on that page) is available. There are a couple of further specials like this that prevent a conversion on-the-fly. Also, not all basic data required to convert a certain page is stored between the corresponding BOP/EOP pair in the DVI file. E.g. font definitions occurring on a page are still valid on all following pages and must not be repeated. That means, to convert a single page, all preceding pages must be processed as well. Alternatively, the collected font definitions present in the postamble can be used. As far as I can tell, a "follow functionality" would only be possible for a subset of currently supported DVI files that don't make use of more demanding specials.