dvipng
[Top][All Lists]
Advanced

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

Re: [Dvipng] dvipng and chemfig


From: Jan-Åke Larsson
Subject: Re: [Dvipng] dvipng and chemfig
Date: Tue, 17 Mar 2015 23:23:58 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

Hi,
You are not alone to want to generate pngs from tikz/pgf graphics, in
this case from chemfig.

Dvipng cannot do this because pgf sometimes mixes DVI commands and raw
Postscript drawing. Dvipng tries to draw the Postscript using
ghostscript, but these small snippets of Postscript are not enough to
produce a complete graphic in ghostscript. Also, dvipng cannot know
where point (the DVI cursor) is after such a draw operation. Dvipng does
tell you what goes wrong:

  dvipng warning: PostScript environment contains DVI commands
  dvipng warning: No image output from inclusion of raw PostScript

There are two possibilities to rectify this: either write a dvipng
driver for pgf, or write an internal Postscript interpreter for dvipng.
Both of these are huge tasks that I do not have time for.

The third alternative is to use another tool. Dvipng was written for
speed, competing with ghostscript (slow startup mainly) and ImageMagic
(ditto). Pdftoppm uses poppler and seems fast on my machine, but these
days, everything is. Anyhow, for single images I'd go

\documentclass[12pt]{standalone}
\usepackage{chemfig}
\begin{document}
\chemfig{A-B}
\end{document}

pdflatex tmp.tex
pdftoppm -png -r 200 tmp.pdf tmp

This crops single pages, but I have not found a way to correctly crop
several pages out-of-the-box. Except with dvipng -T tight. Modern, eh?

/JÅ





On 2015-03-17 20:25, address@hidden wrote:
> dvipng does not produce correct output. The default LaTeX
> template in Anki looks like this (I have added the chemfig bits):
> 
> ```latex
> \documentclass[12pt]{article}
> \special{papersize=3in,5in}
> \usepackage[utf8]{inputenc}
> \usepackage{amssymb,amsmath}
> \pagestyle{empty}
> \setlength{\parindent}{0in}
> \usepackage{chemfig}
> \begin{document}
> \chemfig{A-B}
> \end{document}
> ```
> 
> and to use that Anki runs
> 
> latex tmp.tex
> dvipng -D 200 -T tight tmp.dvi -o tmp.png
> 
> which produces broken output:
> 
> http://imgur.com/EHkPSwM
> 
> which is similar to what you get if you just open the .dvi in
> evince. This is unfortunate considering many (well, at least
> Anki) treat dvipng as a complete solution.
> 
> For the record, here's a workaround: If you don't want to let go
> of latex, then convert to postscript and then to pdf
> 
> latex tmp.tex
> dvips tmp.dvi
> ps2pdf tmp.ps
> 
> or just embrace modernity and simplicity and run pdflatex
> 
> pdflatex tmp.tex
> 
> then convert crop the pdf and convert to png
> 
> pdfcrop tmp.pdf tmp-cropped.pdf
> pdftoppm -png -r 200 tmp-cropped.pdf tmp
> 
> and the final file is tmp-1.png:
> 
> http://imgur.com/yxYGdpZ
> 
> Is there any chance dvipng will be patched or is this a feature?
> Also, do you have better workaround? dvipng's -T tight option is
> very handy.
> 
> _______________________________________________
> Dvipng mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/dvipng



reply via email to

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