32leaves.net

MimeTex ruby bindings

Did you ever wish you could render Tex code using Ruby? Now you can. Ok, it’s not entirly Ruby, but at least we got some bindings now.

I took the code from MimeTex, modified it a bit and wrote some Ruby bindings for it.
So how can I get this, you might ask?

Just install the GEM that that you can download here, using

1
gem install mimetexrb-1.0.0.gem

and you’re ready to go.

Have a look at the following example on how to use it:

1
2
3
4
5
6
7
8
require 'rubygems'
require 'mimetexrb'

renderer = MimeTex::Render.new(4)  # 4 is the font size
raw_gif = renderer.render('\sqrt{\frac{1}{2}}*\vec{a}')
File.open("output.gif", "a") { |f|
  f.print(raw_gif)
}

This code will produce \sqrt{\frac{1}{2}}*\vec{a}.
In Rails you can use send_data to send the image directly to the user.
Ahhm, just to metion this, the code that does the magic is kinda hackish. I’m really no C programmer.

Hope you enjoy this little gadget. If you have any questions feel free to contact me.

Leave a Reply

Fork me on GitHub