Path

ez.no / developer / contribs / template plugins / latex template operators


LaTeX template operators

Author Version Downloads Compatible with
Paul Borgermans 0.2 1186 3.6.x (and earlier)
Provides a template operator 'latexrender' which renders LaTeX formulas on the fly as bitmaps. Based on http://www.mayer.dial.pipex.com/tex.htm#latexrender of which only the file class.latexrender.php is used by the template operator.

Description

INSTALL
=======

- Make sure you have the required packages on your server (LaTeX). For info look at the original latexrender page ( http://www.mayer.dial.pipex.com/tex.htm#latexrender )
- Unpack the archive available from
http://pubsvn.ez.no/websvn/dl.php...ion%2Flatex%2F&rev=0&isdir=1
into your extension directory
- Activate the latex extension in your admin interface

USAGE
=====

{$inputstring|latexrender(array(<image format>,<font size>, <density>))}

The $inputstring should contain your LaTeX string without $ or \( )\ (the LaTeX math delimiters)

Additional parameters are <image format>, <font size>, <density> which are by default set to ('png',12,120)

Returns the URL to the converted image.

WHERE TO USE
============

You can use this operator anywhere, but it is probably most useful in a new content class. Just add a plain text field and use the operator in a custom template for this class as described below. A package is provided in the distribution (made in a 3.6.1 site).

However, you may as well add a custom tag for xml text fields. An example template and settings are provided.

EXAMPLE TEMPLATE CODE
=====================
Please note the use of escapes of the closing } in the strings used in the template code. This is required to avoid a clash with other template code.

For versions lower than 3.6, you will need to use the old syntax ... but it should work.



 

{def $myformulas=array('\sqrt{2\}', '\int_{0\}^{1\}','\displaystyle\int_{0\}^{1\}\frac{x^{4\}(1-x)^{4\}\}{1+x^{2\}\}dx=\frac{22\}{7\}-\pi')}


 

{foreach $myformulas as $formula}


<h2>Formula</h2>


<pre>


{$formula}


</pre>


<img src={$formula|latexrender('png',10,72)|ezurl} />


{/foreach}


 



Have fun

-paul

Screenshot

Changelog

[0.1]

- Initial upload, provides latexrender operator for generating png or gif representations of LaTeX formulas. Only tested on Linux.
[0.2]

- Added some more settings as an example how to use it as a custom tag.
- Added a package with an example object, class definition and template
- Added a note here on where to use it
- Added a tar.gz archive from pubsvn.ez.no

Comments

Great!

One thing: since Latex is rather heavy weight, people might be understandably hesitant of running it on a server. For those, look at http://www.forkosh.com/mimetex.html (which is essentially just a self contained CGI script that generates the GIFs)

Great!

Paul, this is really nice contrib!

log in or create a user account to comment.

Contribution info (stable)

Download