Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering LaTeX to an image

Tags:

c

php

latex

tex

I have read lots of questions and answers here but I haven't found a clear Question/Answer.

I need to create a really simple webpage which allows users to enter LaTeX and generate a PNG (or other lightweight image format). The webpage contains only a textarea and a submit button and it produces a link like "http://www.example.com/generated-images/cnl344l4jcxlj.png" with the image.

INPUT: already-written latex like

f(x)=\displaystyle\int_{-\infty}^x e^{-t^2}dt

OUTPUT: Link to the generated PNG or GIF image

http://rinconmatematico.com/latexrender/pictures/35800007a15a3f0e39006dc63f04f1b5.gif

The processing of the latex code and the generation of the image should happen in the server-side (so no JavaScript)

I'd like to do this in PHP (which I'm pretty good at), but if there are simple-enough libraries I could give it a shot in Perl.

A straightforward implementation in pure C could also work. A program which scanfs the input latex code and printfs "image generated at c:/program/image00000000001.gif"

Any free/opensource libraries that do any of this? Any advice in how to proceed? Any special concerns?

http://rinconmatematico.com/latexrender/pictures/35800007a15a3f0e39006dc63f04f1b5.gif

like image 473
Daniel Avatar asked Mar 04 '12 20:03

Daniel


3 Answers

Try:

  • TeX2PNG - generate png image for given equation
  • MathJax - JavaScript library that find and render math equations in HTML
  • KaTeX - lighter and a little bit less capable alternative to MathJax
like image 79
Hauleth Avatar answered Nov 17 '22 12:11

Hauleth


Look at dvipng. I wouldn't write a wrapper over it in C but in a scripting language.

like image 4
AProgrammer Avatar answered Nov 17 '22 10:11

AProgrammer


If it's not a high-traffic website, you can try online rendering with sites like the Online LaTeX Equation Editor. In particular, this site allows you to put LaTaX directly into the URL like the following:

\sum_k a_k

The URL being: http://latex.codecogs.com/gif.latex?\sum_k%20a_k

like image 2
Joe Avatar answered Nov 17 '22 12:11

Joe