Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write a Template.pm filter to generate PNG output from LaTeX source code?

I am looking for a way of generating PNG images of equations from LATEX source code embedded in templates. For example, given:

[% FILTER latex_display ]
\begin{eqnarray*}
\max && U(x,y) \\
\mathrm{s.t.} && p_x x + p_y y \leq I \\
&& x \geq 0, y \geq 0
\end{eqnarray*}
[% END %]

I would like to get the output:

<div class="latex display"><img src="equation.png" width="x" height="y"></div>

which should ultimately display as:

Consumer's Optimization Problem

I am using ttree to generate documents offline. I know about Template::Plugin::Latex but that is geared towards producing actual documents out of LATEX templates.

Any suggestions?

Update:

I appreciate the suggestions (and I have voted them up). However, they are no quite what I need. I would really appreciate a few pointers towards getting started with a Plugin or Filter for Template Toolkit.

like image 590
Sinan Ünür Avatar asked Apr 08 '10 21:04

Sinan Ünür


1 Answers

Wikipedia does something similar to what you want. They use a program called texcv. Then you also have MathJAX which is more aimed at dynamic math rendering in web-pages.

texcv is according to the linked page written in OCaml however since the rest of Mediawiki is written in PHP I don't think you should have any problem with repurposing the program to use with Perl.

like image 173
adamse Avatar answered Oct 03 '22 06:10

adamse