开发者

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:

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

I am using ttree to generate documents offline. I know ab开发者_Go百科out 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.


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.


you should take a look at jsMath, MathML, or mathjax


I would really appreciate a few pointers towards getting started with a Plugin or Filter for Template Toolkit

These docs on Template Toolkit site should provide all necessary info to setup a plugin or filter:

  • Plugin provider module
  • Base class for plugin filters

Once you have your LATEX to PNG conversion sorted then you probably need to save it as a file using redirect. Example from POD:

[% PROCESS my/png/generator 
    FILTER redirect("images/logo.png", binmode=1) %] 

Hope that helps.

/I3az/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜