MathModePlugin
Add math formulas to TWiki topics using LaTeX markup language
Description
This plugin allows you to include mathematics in a TWiki page, with a format very similar to LaTeX. The external program
latex2html
is used to generate
gif
(or
png
) images from the math markup, and the image is then included in the page. The first time a particular expression is rendered, you will notice a lag as
latex2html
is being run on the server. Once rendered, the image is saved as an attached file for the page, so subsequent viewings will not require re-renders. When you remove a math expression from a page, its image is deleted.
Note that this plugin is called
MathModePlugin, not LaTeXPlugin, because the only piece of LaTeX implemented is rendering of images of mathematics.
Syntax Rules
<latex [attr="value"]* > formula
</latex>
generates an image from the contained
formula
. In addition attribute-value pairs may be specified that are passed to the resulting
img
html tag. The only exeptions are the following attributes which take effect in the latex rendering pipeline:
-
size
: the latex font size; possible values are tiny, scriptsize, footnotesize, small, normalsize, large, Large, LARGE, huge or Huge; defaults to %LATEXFONTSIZE%
-
color
: the foreground color of the formula; defaults to %LATEXFGCOLOR%
-
bgcolor
: the background color; defaults to %LATEXBGCOLOR%
The formula will be displayed using a
math
latex environment by default. If the formula contains a latex linebreak (
\\
) then a
multline
environment of amsmath is used instead. If the formula contains an alignment sequence (
& = &
) then an
eqnarray
environment is used.
Note that the old notation using
%$formula$%
and
%\[formula\]%
is still supported but are deprecated.
If you might want to recompute the images cached for the current page then append
?refresh=on
to its url, e.g. click
here to refresh the formulas in the examples below.
Examples
The following will only display correctly if this plugin is installed and configured correctly.
<latex title="this is an example">
\int_{-\infty}^\infty e^{-\alpha x^2} dx = \sqrt{\frac{\pi}{\alpha}}
</latex>
\int_{-\infty}^\infty e^{-\alpha x^2} dx = \sqrt{\frac{\pi}{\alpha}}
<latex>
{\cal P} & = & \{f_1, f_2, \ldots, f_m\} \\
{\cal C} & = & \{c_1, c_2, \ldots, c_m\} \\
{\cal N} & = & \{n_1, n_2, \ldots, n_m\}
</latex>
{\cal P} & = & \{f_1, f_2, \ldots, f_m\} \ {\cal C} & = & \{c_1, c_2, \ldots, c_m\} \ {\cal N} & = & \{n_1, n_2, \ldots, n_m\}
<latex title="Calligraphics" color="orange">
\cal
A, B, C, D, E, F, G, H, I, J, K, L, M, \\
\cal
N, O, P, Q, R, S, T, U, V, W, X, Y, Z
</latex>
\cal
A, B, C, D, E, F, G, H, I, J, K, L, M, \ \cal
N, O, P, Q, R, S, T, U, V, W, X, Y, Z
<latex>
\sum_{i_1, i_2, \ldots, i_n} \pi * i + \sigma
</latex>
\sum_{i_1, i_2, \ldots, i_n} \pi * i + \sigma
This is
\cal A new inline test.
Greek letters |
\alpha |
\alpha |
\theta |
\theta |
\beta |
\beta |
\iota |
\iota |
\gamma |
\gamma |
\kappa |
\kappa |
\delta |
\delta |
\lambda |
\lambda |
\epsilon |
\epsilon |
\mu |
\mu |
\zeta |
\zeta |
\nu |
\nu |
\eta |
\eta |
\xi |
\xi |
Plugin Installation Instructions
- Download the ZIP file
- Unzip
MathModePlugin.zip
in your twiki installation directory. Content: File: | Description: |
data/TWiki/MathModePlugin.txt | |
lib/TWiki/Plugins/MathModePlugin/Core.pm | |
lib/TWiki/Plugins/MathModePlugin.pm | |
pub/TWiki/MathModePlugin/latex2img | |
- This plugin makes use of three additional tools that are used to convert latex formulas to images. These are
- Make sure they are installed and check the paths to the programs
latex
, dvipng
and convert
in the latex2img shiped with this plugin
- Edit the file
<path-to-twiki>/pub/TWiki/MathModePlugin/latex2img
accordingly and set execute permission for your webserver on it
- Visit
configure
in your TWiki installation, and enable the plugin in the {Plugins} section.
Troubleshooting
- If you get error like
"fmtutil: [some-dir]/latex.fmt does not exist"
, run fmtutil-sys --all
on your server to recreate all latex formatstyles.
- If your generated image of the latex formula does not show up, then you probably have encoding issues. Look into the source of the <img>-tag in your page's source code. Non-ASCII characters in file names might cause troubles. Check the localization in the TWiki configure page.
Configuration
There are a set of configuration variables that an be set in different places. All of the below variables can be set in your
LocalSite.cfg
file like this:
$TWiki::cfg{MathModePlugin}{<Name>} = <value>;
Some of the below variables can
only be set this way, some of the may be overridden by defining the respective prefrence variable.
Name |
Preference Variable |
Default |
HashCodeLength |
|
32 |
|
length of the hash code. If you switch to a different hash function, you will likely have to change this |
ImagePrefix |
|
'_MathModePlugin_' |
|
string to be prepended to any auto-generated image |
ImageType |
%LATEXIMAGETYPE% |
'png' |
|
extension of the image type; possible values are 'gif' and 'png' |
Latex2Img |
|
'.../TWiki/MathModePlugin/latex2img' |
|
the script to convert a latex formula to an image |
LatexPreamble |
%LATEXPREAMBLE% |
'\usepackage{latexsym}' |
|
latex preamble to include additional packages (e.g. \usepackage{mathptmx} to change the math font) ; note, that the packages amsmath and color are loaded too as they are obligatory |
ScaleFactor |
%LATEXSCALEFACTOR% |
1.2 |
|
factor to scale images |
LatexFGColor |
%LATEXFGCOLOR% |
black |
|
default text color |
LatexBGColor |
%LATEXBGCOLOR% |
white |
|
default background color |
LatexFontSize |
%LATEXFONTSIZE% |
normalsize |
|
default font size |
Plugin Info