6

How can I render LaTeX stuff like

\frac{1}{2}

in a Ruby on Rails application? I mean to get an image? Thanks!

Dimitar Vouldjeff
  • 2,067
  • 3
  • 19
  • 24

6 Answers6

10

You could always try http://www.mathjax.org/, leaving the rendering to the client!

Andrew
  • 101
  • 1
  • 3
  • mathjax does not support table's lists or images, so when it comes to more complex latex you are left in the dust. The js library is over-engineered and is head-full to learn. I was hoping to use mathjax vs server-side rendering but it doesn't appear to be a great option now. – Andrew WC Brown Feb 16 '16 at 04:35
1

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 …

Christopher Creutzig
  • 8,656
  • 35
  • 45
1

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.

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
1

Katex

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.

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
0

The katex gem can render these server-side so you don't even need any JavaScript, and it's smaller and better quality than an image.

glebm
  • 20,282
  • 8
  • 51
  • 67
0

There is also mathematical gem that converts TeX math to SVGs, PNGs, or MathML.

Martin
  • 4,042
  • 2
  • 19
  • 29