How can I render LaTeX stuff like
\frac{1}{2}
in a Ruby on Rails application? I mean to get an image? Thanks!
How can I render LaTeX stuff like
\frac{1}{2}
in a Ruby on Rails application? I mean to get an image? Thanks!
You could always try http://www.mathjax.org/, leaving the rendering to the client!
By invoking an external program that does the processing for you, such as tex2png
or tex2png.pl
.
Then again, for simple formulas like that, you may also wish to consider using jsmath. The next step then would be to let your users choose which version they want to see …
To render LaTeX for the web, it looks to me like mathTeX
is the application of choice. There are many other options, all of which seem to build on dvipng
as a foundation. MathTeX
appears to be the most polished and capable, and it is easy to configure as a CGI service, so your Rails application can generated ordinary HTML <img>
tags with rather complex src
attributes.
EDIT: Having installed mathTeX, I can say that the code is inflexible, that it violates the Linux Filesystem Hierarchy standard, and that it is amateur work—in both the good and bad senses of that word. The code is so complex that there are no obvious faults. I will be looking for alternatives.
Take a look at Katex. It's from a couple of people behind Khan Academy and it looks extremely legit.
This uses Javascript to generate a nice HTML view of the formulas so I'm still working out the best method to turn this into an image conveniently, though.
There is also mathematical gem that converts TeX math to SVGs, PNGs, or MathML.