5

I have been writing latex code for showing chemical reactions thorugh chemfig . Now i want to show it in website . The only solution i find is to capture screenshot crop it and publish it ? Is there any better way than this?

I found the way to show maths equation just by code like using mathml etc. But i still cannot find way to show chemical reaction using codes ?

Is there anyway or i should stick to boring screenshot idea ?

Thank you :)

5
  • Welcome to TeX.SX! I suspect you refer to MathJax (as seen on Math.SX). I'm not sure whether this is covered by TeX.SX.
    – 1010011010
    Jun 23, 2015 at 15:46
  • 1
    If you want to draw your images in latex, compile them individually, and then use them on the websites, maybe the standalone package with the convert to png option is suitable...
    – crateane
    Jun 23, 2015 at 16:50
  • related: meta.tex.stackexchange.com/q/5954/17423 Jun 23, 2015 at 19:01
  • 1
    If you happen to have a WordPress blog you can use the QuickLaTeX plugin (see also its homepage). The examples in this post on my blog are all rendered by the plugin, I just typed the LaTeX code...
    – cgnieder
    Jun 23, 2015 at 19:59
  • @clemens Yes thanks for the plugins . Is there something like php script for compiling latex code ?
    – Shirshak55
    Jun 24, 2015 at 13:11

2 Answers 2

3

chemfig is based on tikz and it is converted to svg images with tex4ht.

If we use example from G.P.'s answer, we get this result:

\documentclass{article}
\thispagestyle{empty}
\usepackage{chemfig}
\begin{document}
\chemfig{ * 6((=O)-N(-CH_3)- *
5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)}
\end{document}

enter image description here

using

htlatex filename command

this solution has advantage that you can create your whole page in LaTeX.

3

Create a document that contains the formula and nothing else. Compile it to a pdf file, and then convert it to png using pdftoppm.

Create the document containing the formula, called chem.tex like this:

\documentclass[margin=10]{standalone}
\usepackage{chemfig}
\begin{document}
\chemfig{ * 6((=O)-N(-CH_3)- *
5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)}
\end{document}

then run pdflatex chem.tex; pdftoppm -r 600 -png chem.pdf chem.png.

If you want a svg file, which most browsers support, replace the last command with pdf2svg chem.pdf chem.svg

This should output this image: Chemical formula for caffeine

of course, you can create a simple script that does this automatically.

3
  • 1
    why pdf -> svg -> png? 1. you can use svgs in most (every?) browser, second if you need a png you can just do pdftoppm -r <resolution> -png <inputfile> <outputfile>. Also using the standalone class the pdfcrop command becomes unnecessary.
    – MaxNoe
    Jun 23, 2015 at 18:38
  • Thanks for the hint to the pdftoppm command, i did not notice it. I tried the standalone class, but it crops the picture too much, the O at the top is cut. Is there any way to specify a margin with the standalone class?
    – G. P
    Jun 23, 2015 at 18:46
  • Yes, there is a margin=dimen class option
    – MaxNoe
    Jun 23, 2015 at 18:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .