Django template tag for rendering math formulas
Python
Switch branches/tags
Nothing to show
Latest commit 39f7d44 Mar 3, 2014 @emesik emesik Merge pull request #1 from JIoJIaJIu/master
Add math filter
Permalink
Failed to load latest commit information.
django_mathlatex math filter Feb 13, 2014
test_env Initial Feb 28, 2011
.gitignore Rename Mar 6, 2011
README.rst math filter Feb 13, 2014

README.rst

django_mathlatex

Render PNG images of math formulas written in LaTeX notation. It's simple as hell:

{% load mathlatex %}
{% math %}
    E = mc^2
{% endmath %}

Requirements and confirguration

The required tools are:
  • latex with amsmath package,
  • dvipng

The configuration consists of one declaration in settings.py:

MATHLATEX_IMAGES_DIR = 'math/'        # Or wherever you wish under MEDIA_ROOT

Examples

Always include {% load mathlatex %} in your template.

To simply put a formula inline, write:

<p>
Einstein said that {% math %}E = mc^2{% endmath %}.
</p>

<p>
We can say more:
</p>
{% math %}
            \left\{
            \begin{array}{ll}
            x = ct + x\cos(\omega t)\\
            z = R\sin(\omega t)
            \end{array}
        \right. \Leftrightarrow
        \left\{
            \begin{array}{ll}
            x = \frac{L}{T}t+R\cos(\omega t)\\
            z = R\sin(\omega t)
            \end{array}
        \right. \Leftrightarrow
        \left\{
            \begin{array}{ll}
            x = \frac{\omega t}{k}+R\cos(\omega t)\\
            z = R\sin(\omega t)
            \end{array}
        \right.
{% endmath %}

You may also obtain the instance of formula's model by assigning it to a value:

{% math as einstein %}E=mc^2{% endmath %}
<p>
The following equation illustrates mass-energy equivalence:
</p>
<img src="{{ einstein.image.url }}" alt="Mass - energy equivalence" />

Alternatively, you may pass an equation as context variable:

from django.template import Template, Context
t3 = Template("{% load mathlatex %}{% math %}{{ einstein }}{% endmath %}")
ctx = Context({'einstein': 'E = mc ^ 2'})

Also you could use math as filter in templates

::
{{text|math}}