I generate PNG images from latex code to display in web/mobile applications. The general flow is:
- Client makes an API call with the formula I should render
- I wrap the formula in a preamble and run latex on it
- From the generated .dvi I run dvipng with --depth
This process gives me a PNG image and the depth information and has been working fine for a while. Now I want to add the ability to render chemistry formulas, so I added chemfig package, and this is where the issue arises.
There are some answers over the internet like here and here advising to use pdflatex with chemfig and then another tool to convert from PDF to PNG, once just using dvipng won't produce correct images.
Generated with dvipng

Generated with pdflatex + convert

So I can render formula properly. The question is: is there a way to get image depth in this second flow?
The tex snippet to generate the images is:
\documentclass[12pt]{article} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{cancel} \usepackage{color} \usepackage{chemfig} \usepackage{yhmath} % for \wideparen \renewcommand*\familydefault{\sfdefault} \usepackage[active,textmath,tightpage]{preview} \begin{document}$\displaystyle \chemfig{A-B}$\end{document} EDIT: Using the suggested solution to write the information to another file I've got an empty file. Adding \immediate to writes it is not empty anymore, but all values are 0.0pt.
The full source is
\documentclass[12pt]{standalone} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{cancel} \usepackage{color} \usepackage{chemfig} \usepackage{yhmath} % for \wideparen \renewcommand*\familydefault{\sfdefault} \usepackage[active,textmath,tightpage]{preview} \setatomsep{2.0 em} % 'Fixed Bond Length' \makeatletter \global\let\tikz@ensure@dollar@catcode=\relax \makeatother \newsavebox\frm \sbox\frm{$\displaystyle \chemfig{A-B} $} \newwrite\frmdims \immediate\openout\frmdims=\jobname.dims \immediate\write\frmdims{depth: \the\dp\frm} \immediate\write\frmdims{height: \the\ht\frm} \immediate\write\frmdims{width: \the\wd\frm} \immediate\closeout\frmdims \begin{document} \usebox\frm \end{document}
fileorexiv2as in stackoverflow.com/questions/4670013/… and parse the output from that.chemfiguses TikZ, which does not render in DVI files because it uses specials not understood by any DVI viewer (and bydvipng).