14

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

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Daniel
  • 1,321
  • 12
  • 25
  • Have you checked google? Simple shell script from http://www.nought.de/tex2im.php worked for me. – Luka Rahne Mar 04 '12 at 20:37
  • 2
    Perhaps this helps: [TeX to image over command line](http://tex.stackexchange.com/questions/34054/tex-to-image-over-command-line/34058#34058) – Peter Grill Mar 05 '12 at 18:42

3 Answers3

7

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
Hauleth
  • 22,873
  • 4
  • 61
  • 112
  • 1
    Wish there would be a pure C/C++ solution that doesn't require a 100MB package (a running webbrowser or a full LaTex installation + perl + ghostscript). – Lothar Aug 09 '18 at 21:21
4

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

AProgrammer
  • 51,233
  • 8
  • 91
  • 143
2

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

Joe
  • 16,328
  • 12
  • 61
  • 75