Hacking the MediaWiki LaTeX Support

From SarahWiki

NB: MediaWiki 1.5 is assumed here. Note also that this is strictly unofficial -- I have no connection with the MediaWiki developers, and should warn that you can break your installation pretty easily, so use this at your own risk, and I take no responsibility for the consequences.

In compiling my Transitional Logic section, I found it necessary to extend MediaWiki's LaTeX support so that it could cope with my non-standard notation. For example, I want to be able to say

\fz \subset \fq \subset \fff_{0..\infty} \subseteq \bigstar

when I want to render \fz \subset \fq \subseteq \fff_{0..\infty} \subset \bigstar, without having to expand all of those macros by hand.

The trick to making this work is farly straightforward, though it helps if you are at least a little familiar with ML-like languages, because the code you'll need to hack is written in ocaml.

The file you need to edit is texutil.ml, which can be found in the /math subdirectory of your MediaWiki installation.

HOWTO

Somewhere around line 64 in texutil.ml you will find the definition

let find = function
  "\\alpha" ...
| "\\Alpha" ...

To add a new symbol, it is easiest to look through the definitions already present to find something close to the one that you want to create, then take a copy of that entry, paste it in at the end (do NOT paste it after the lines that end 'raise...', however), and modify it to suit your own purposes.

Some symbols render only as LaTeX, due to lack of equivalents in HTML. In some cases, you have to provide both LaTeX and HTML equivalents -- it should be fairly obvious in the code. For example, in the standard definition for \omega

| "\\omega"  -> LITERAL (HTMLABLEC (FONT_UF, "\\omega", "& omega ;"))

it is pretty clear what gets included for LaTeX and HTML rendering respectively (i.e. the "\\omega" is the LaTeX version and "& omega ;" is the HTML version -- note that the extra spaces in the HTML version are not really there in the source, and are only used here to avoid the text rendering as ω).

Caveats:

  1. You will need to rerun make to rebuild the code in order for your changes to take effect.
  2. Pages that are already in the wiki will not change until you next edit them.

Example

My own definition for \bigstar, which renders as \bigstar, is as follows:

let find = function
     ...
| "\\bigstar"   -> (tex_use_ams(); LITERAL (TEX_ONLY "\\bigstar"))
     ...

Note that if you require AMS symbols (which is where \bigstar comes from), you will need to include tex_use_ams(), as I have above.