Discussion:
[Dvipng] Static/dynamic library for dvipng?
Alex
2009-09-29 22:55:02 UTC
Permalink
Hello,

I've just recently discovered the dvipng project, and am considering
using it for on-the-fly TeX rendering of mathematical expressions, for
which it would seem to be suitable. However, I am slightly curious as to
how this process should work. (My apologies if this is detailed in the
docs, but I couldn't find anything). Firstly, I presume the only way to
generate the DVI file from the TeX input is to use the TeX command-line
utility. The next step would seem to be to use the dvipng command-line
utility to convert this DVI to a PNG file. This is of course no problem
for a GUI app, though somewhat inefficient I might think.

My main question is: is dvipng suitable to be used as a static/dynamic
library for inclusion in other programs? (In addition, I would be
curious to know whether it is possible to use a library rather than a
stdio program for generating the DVI.)

I am presuming that both the DVI generator of TeX and the PNG generator
of dvipng are designed to output solely to files. Still, if there is any
way of circumventing this and doing things in-memory, that would be
useful for me.

A final small query: is compiling dvipng for Windows possible (given
that it is my primary target platform), or perhaps via cygwin, if that's
less painful? Using MiKTeX should make no difference, as I understand.

Many thanks,
Alex
Jan-Åke Larsson
2009-10-01 13:55:41 UTC
Permalink
Post by Alex
The next step would seem to be to use the dvipng command-line
utility to convert this DVI to a PNG file. This is of course no problem
for a GUI app, though somewhat inefficient I might think.
This is true, but you should remember that the overhead will be there in
any case, when calling TeX and when dvipng itself calls gs for image
inclusion.
Post by Alex
My main question is: is dvipng suitable to be used as a static/dynamic
library for inclusion in other programs? (In addition, I would be
curious to know whether it is possible to use a library rather than a
stdio program for generating the DVI.)
There are no designed entry points, and above all no stable API. I could
perhaps design one, implement it, and learn how to release it as a
library, but I have preciously little time these days.
Post by Alex
I am presuming that both the DVI generator of TeX and the PNG generator
of dvipng are designed to output solely to files. Still, if there is any
way of circumventing this and doing things in-memory, that would be
useful for me.
The DVI generator of TeX I do not know much about. I have been thinking
about named pipes for dvipng but this is a less portable solution.

The internals of dvipng does do everything in memory. Input of files
uses mmap for reading, and if mmap is not available, reads in the whole
file into memory. Output is via libgd in memory as a gdimage and as a
final step uses a gd function for writing to a file, IIRC there is one
for in-memory conversion to a PNG. So in principle it would be possible
to do everything in memory.
Post by Alex
A final small query: is compiling dvipng for Windows possible (given
that it is my primary target platform), or perhaps via cygwin, if that's
less painful? Using MiKTeX should make no difference, as I understand.
Dvipng is included in MiKTeX. And TeXLive under cygwin.

/JÅ
--
"We're working at the intersection of TeX (bizarre and, er, eccentric),
Emacs (bizarre and, er, eccentric) and GhostScript. Why expect
GhostScript to be any less bizarre and eccentric than the rest?"
Nick Alcock, the preview-latex development team
Alex
2009-10-01 16:37:04 UTC
Permalink
Hi Jan-Åke,

Thanks for your quick reply. It seems I may be best off just using the
program as it currently is - a command-line utility based around the
filesystem.

I am however curious as to how preview-latex manages to accomplish the
task of on-the-fly LaTeX rendering. Since my overall goal is to create
an on-the-fly TeX renderer to integrate into a .NET/C# application, I
would probably want to mimic much of the approach. Unfortunately, there
seems to be minimal information on the workings of preview-latex, and I
suspect the only way to figure out exactly what goes on will be to dig
through the source. If you could however describe the approach in brief,
or point me to a resource, it would be much appreciated.

Regards,
Alex
Post by Jan-Åke Larsson
Post by Alex
The next step would seem to be to use the dvipng command-line
utility to convert this DVI to a PNG file. This is of course no problem
for a GUI app, though somewhat inefficient I might think.
This is true, but you should remember that the overhead will be there in
any case, when calling TeX and when dvipng itself calls gs for image
inclusion.
Post by Alex
My main question is: is dvipng suitable to be used as a static/dynamic
library for inclusion in other programs? (In addition, I would be
curious to know whether it is possible to use a library rather than a
stdio program for generating the DVI.)
There are no designed entry points, and above all no stable API. I could
perhaps design one, implement it, and learn how to release it as a
library, but I have preciously little time these days.
Post by Alex
I am presuming that both the DVI generator of TeX and the PNG generator
of dvipng are designed to output solely to files. Still, if there is any
way of circumventing this and doing things in-memory, that would be
useful for me.
The DVI generator of TeX I do not know much about. I have been thinking
about named pipes for dvipng but this is a less portable solution.
The internals of dvipng does do everything in memory. Input of files
uses mmap for reading, and if mmap is not available, reads in the whole
file into memory. Output is via libgd in memory as a gdimage and as a
final step uses a gd function for writing to a file, IIRC there is one
for in-memory conversion to a PNG. So in principle it would be possible
to do everything in memory.
Post by Alex
A final small query: is compiling dvipng for Windows possible (given
that it is my primary target platform), or perhaps via cygwin, if that's
less painful? Using MiKTeX should make no difference, as I understand.
Dvipng is included in MiKTeX. And TeXLive under cygwin.
/JÅ
Jan-Åke Larsson
2009-10-01 17:53:27 UTC
Permalink
Post by Alex
I am however curious as to how preview-latex manages to accomplish the
task of on-the-fly LaTeX rendering. Since my overall goal is to create
an on-the-fly TeX renderer to integrate into a .NET/C# application, I
would probably want to mimic much of the approach. Unfortunately, there
seems to be minimal information on the workings of preview-latex, and I
suspect the only way to figure out exactly what goes on will be to dig
through the source. If you could however describe the approach in brief,
or point me to a resource, it would be much appreciated.
The preview-latex package is based on preview.sty, a package which takes
out snippets like equations and other things and produces a DVI with
just these, one on each page. dvipng is then used to render all these
pages in a batch, and this saves much of the overhead you mentioned. One
run of latex/dvipng for each time the images are to be updated.

preview.sty has a manual, I dont remember how it is accessed just now,
but 'texdoc preview' should do the trick. Ask again if you need more help.

/JÅ
Jan-Åke Larsson
2009-10-02 07:03:27 UTC
Permalink
Yeah, it sounds like I want to be using preview.sty. Unfortunately,
texdoc returns no information on the package ('Documentation for preview
could not be found.'). Note that I'm running a MiKTeX installation, if
that makes a difference. Anywhere else that I might be able to access
the documentation?
See http://www.ctan.org/tex-archive/help/Catalogue/entries/preview.html
CTAN seems to be down at the moment, though.

It calls latex with arguments like

"\nonstopmode\nofiles\PassOptionsToPackage{active}{preview}\AtBeginDocument{\ifx\ifPreview\undefined\RequirePackage[displaymath,floats,graphics,textmath,sections,footnotes]{preview}[2004/11/05]\fi}\input{filename.tex}"
Also, when you say that this package does a run of latex/dvipng for each
update, I presume you mean that the command line utility for each is
executed, saving the intermediary files on disk?
Exactly. Preview is the latex package that makes ONLY the requested bits
of a TEX file appear in the output, one on each page, and the generated
images are then inserted by the preview-latex Emacs package, see

http://www.gnu.org/software/auctex/preview-latex.html


/JÅ

Loading...