# MediaWiki math markup

**This page is oudated, see Help:Displaying a formula to see how to insert a formula in a wiki page.**

MediaWiki supports LaTeX markup:

Click here to try it out in the sandbox!

Once in the sandbox:

1. Click the Mathematical Formula (LaTeX) icon above to get this:

<math>Insert formula here</math>

2. Then enter any LaTeX markup (see Help:Formula), for example:

<math>\alpha^2+\beta^2=1</math>

...displays

## Statement of the Situation (March, 2008)[edit]

Currently, mathematical equations are entered in LaTeX and displayed as images. A disadvantage of this is that the user cannot copy the content page and modify the equation.

Ideally, a user should be able to create a mathematical formula with a word processor, copy and paste the formula into the MediWiki edit box, and have the formula rendered on the wiki in such a manner that a second user can copy the rendered content page, paste it into a word processor, and edit the formula, changing, say, the number of eggs per hen in the equation from 6 to 4.

What's needed:

- The user needs to be able to easily enter mathematical equations. LaTeX is good for this.
- The content should be rendered as MathML. This is the W3 math display standard that browsers now understand. MathML is ugly; users should be shielded from it.
- Word processors need to be able to render MathML as an equation, and save the file with the equation retrievable. (When OpenOffice.Org Writer 2.4 saves a file in either .html or MediaWiki format, the MathML is replaced with an image, rather than LaTeX.)
- It would not be necessary for the MediaWiki edit box to accept MathML input if word processors made the LaTeX format readily available.

The main thing remaining that MediaWiki can accomplish, then, is to render mathematical equations as MathML, rather than images, so that users can readily edit and reformat the equations. This will also reduce the file size. Cking 15:21, 30 March 2008 (UTC)

## texvc: Taw's proposal[edit]

*This is a culling from many other places that have raised this issue. Merciless refactoring of the text is required, to clearly present pros, cons and implementation possibilities*

The most recent idea seems to be something which takes markup like this:

- [[math:someTex]]
- [[math:\alpha^2+\beta^2=1]]

and generates a PNG file which is then cached until the formula is next changed.

## ASCIIMath[edit]

Has anyone taken a look at the PHP version of ASCIIMath (or even the original javascript version, which I think can also handle LaTex)? I like the fact that the simpler formulae are very simple. I was trying to see if I could create an extension using the PHP version, but was having problems as it seemed that I couldn't get PHP to serve up XML, which is apparently what MathML needs. --Sf-andrew 05:59, 18 August 2005 (UTC)

## Sage[edit]

Excuse me, I do not know if I am really supposed to enter this, but looking at this page, I want to point you to the solution in Sage, a mathematica like open source python based project. They render latex well, can do images when need be or use actual fonts that can be cut and paste and you can right click and get the latex in the paste buffer. Hope this helps in terms of ways to display math. Personally I think it's cool mediawiki supports even the bitmap version, it looks quite nice. cheers.

## Old stuff from FAQ talk[edit]

**Q. I am asking this again, because I do not feel I received an adequate answer, last time. To write pages on Math, the authors need to be able to include a large number of math symbols, graphs, etc. This is not a question of linking to someone else's images. These are items we need to be able to use freely and in our own original way. It would require, at present, uploading the content to one's own websites, assuming we have them ,and linking to this. For example, to discuss differentiation and integration in Calculus, one needs to have: an Integral sign, a summmation sign, a symbolism for limits, etc. Somehow, writing, the limit of sin(x)/x as x goes to infinity, just doesn't cut it. Already we are all missing the small epsilon for "belongs to," the symbol for "is a subset of," and many more in the Abstract Algebra entries. I think this will impede the addition of much material in the Math area.**

A. This is a difficult problem. Part of the problem is that html web pages don't do math symbols very well at all. So almost any solution will be a crutch. Within the next couple of years, browsers should be able to render MathML. This will be a time of much joy. Between now and then, I'm open to suggestions, but I think this is a really hard problem.

(Added note by Zephyr) The best way to put in math would probably be to write it in TeX (or LaTeX) and then use TtH. This will generate an HTML file with all of the math symbols in text form (no images). Here is an example, and here is another. TeX is almost inarguably the standard for mathematical writing.

TtH produces beautiful HTML only equations, but they can't be inserted without being garbled. If this could be fixed, then TtH would definitely be a fabulous answer. -- TedDunning

As much as I admire Knuth, I must disagree totally. MathML should be the ultimate standard, not TeX. For one thing, TeX is more display-oriented and MathML is more semantics-oriented. MathML is also the standard supported by the World Wide Web Consortium, and will therefore likely be supported by browsers (Mozilla and Microsoft are committed to it, for example). TeX is used by a few academics, but they don't represent the real world.

Fooey on that. TeX is definitely only used by a few academics, but those few academics happen to include most of the mathematicians in the world. MathML is not usable as an authoring tool (and TtM exists for that anyway). TeX may be display-oriented, but few people actually write in TeX directly. Instead, they use LaTeX or AMSTeX which are both very semantics-oriented. In any case, I happen to live in the present and MathML is definitely in the future and may remain there indefinitely. If we can just figure out how to support the tables that TtH produces then the world be a lovely place (or at least the math pages in wikipedia). -- TedDunning

It really comes down to WYSIWYG (What You See is What You Get) vs WYSIWYM (What You Say is What You Mean). First of all, I would like to say that TeX is used almost exclusively by anyone writing up math. Can you show me any major publication which does not require submissions to be in some variant of TeX? A popular thing about TeX is that (if you so wish) you do not need to worry about formatting, you can just say "this is a section, format it for me". You can still have this flexibility by setting the templates. Have you looked at MathML lately? I was looking at some MathML examples and it seems that TeX is much more straightforward to write. $x^2-4=2$ becomes <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <msup><mi>x</mi><mrow><mn>2</mn></mrow> </msup> <mo>-</mo><mn>4</mn><mo>=</mo><mn>2</mn></mrow></math>. I cannot speak much for this, everybody is entitled to their opinion, but I think that MathML would have a very tough time overthrowing TeX (although it would be good for the TeX to MathML convertor).

*Note: There is exactly such a converter from the same guy who wrote TtH* -- TedDunning

A minor but important correction to the above: It is LaTeX in what you in principle should not need to care about formatting, just concentrate on the content and structre. Plain TeX, on the other hand, is mostly purely formatting-oriented low-level typesetting language. Unfortunately, there are times in LaTeX when you do have to care about formatting. E.g. there are no tables that would a) work in paragraph mode and b) at the same time not require manually set the table width. But still, TeX math is the best way to write math, and I'd claim LaTeX the best way to write structured documents, despite it's flaws. The usual rule of "least worst" applies. WYSIWYG is never an alternative to me. Lout is an alternative, and has some advantages (e.g. =>, <=) but some major disadvantages: 'x_i^2' (the natural and TeX way to write this) vs. horribly undreadable 'x sub i supp 2'. Anyway, I think this project really needs a way to write math. Current text-emulation is horrible. I'd vote for using TeX math as it is perhaps the most readable and writable format, and most mathematicians know it. Something like LaTeX2HTML could then be used to render the formulas as images (as mathworld did...). When browsers decently support MathML, a converter from TeX to that format can be used. Whatever people might think, MathML is not the ultimate solution, because it is utterly unwritable.

Note that HTML 4.0 contains many math symbols (all greek letters, integrals, summation signs, logical and set theoretic symbols etc.). I have had no problem typesetting math using these, and occasionly a bit of ascii art. So while it would be preferable to have some TeX or MathML mechanism in place, I don't think it's a big issue and the lack of it does not hold up the math pages right now. (If your browser does not support all HTML 4.0 entities, report it as a bug to the manufacturer.) --AxelBoldt

Sorry, Alex, but that's just not helpful advice at all at this point. *Most* popular browsers in use today fail to support most of the symbols defined in HTML 4, with good reason (mainly the lack of those symbols in the native OS). It's also not a reportable bug (as if it were possible to report bugs in Microsoft products anyway:-), because HTML 4 doesn't require that they be rendered correctly. Some math articles would greatly benefit from typsetting features still not available in HTML 4. It is entirely appropriate for us to investigate other methods, and for the even more important reason that HTML won't allow us to save the *semantic* information about he formulas, only their appearance. --LDC

- Well, I'm told that the most popular browser, IE (version 5.5) displays all math and greek symbols from HTML 4.0 just fine. (I don't know if one has to download free fonts from Microsoft though.) And free software is usually much better at following the standards; mozilla and konqueror work fine as well. So which ones don't work? Also, I'm all in favor of investigating better math typesetting methods, but I claim that right now the math articles are not held back in any way. --AxelBoldt

*How about using EzMath in the pages (http://www.w3.org/People/Raggett/EzMath ), and having the wiki translate to MathML or images? It's very readable (and writable) as plain text. Sample expressions: "integral of sin x from 0 to 2pi wrt x", "x^2-4=2", "x squared - 4 = 2".*

[Note added by Serge Winitzki] Here is a compromise: you type math in TeX and see HTML and images (http://www.mathcircle.org/cgi-bin/mathwiki.pl?) Unfortunately, the (free) software for this "mathwiki" implementation is not in production shape right now. Please contact me if you would like to get in touch about this. (http://www.geocities.com/CapeCanaveral/Lab/5735/1/email_me.html) I intend to work on improving mathwiki code later this year (I am not the principal author). -- S.W.

This is a very good solution since it is fast and completely portable among browsers. Getting the generated image font sizes to match up with the text would make this an excellent choice. The image description could use TeX so that Lynx users would find it useful as well. --Jonathan

Jonathan, first, welcome to Wikipedia, and second, please stay on top of this. CliffordAdams is the main programmer for UseModWiki, but I'm not sure he's interested in including functionality of the sort you describe. But if he doesn't do it, I suspect we'll be able to interest other programmers to work on his code and do it. Anyway, our math section is very active and competent and there's definitely a crying need for this sort of feature. --LMS

There is a patch for ZWiki called LaTeXWiki. It lets you type in LaTeX and ultimately renders it as a png grafic. The LaTeXWiki page is http://latexwiki.rootnode.com/

## Vilage pump, Sept 2002[edit]

This has probably come up before, so if I'm repeating tired old arguments, or worse still inadvertently walking into a minefield, apologies, but I think it would be nice to have a simpler, more wiki-ish markup for subscripts and superscripts, rather than relying on raw HTML (it was really starting to piss me off while doing the notation example in electron configuration). Something a bit TeXy, perhaps, like ^ and _ (though that leads to ambiguity over exactly what wants sub/superscripting so it might be best to use paired symbols ^2^ and _2_, or perhaps even ^2_ _2^, so that ^ meant go up a level and _ meant go down a level) --Bth

It has come up before, but it's well worth mentioning again! Something like ^^2^^ might be safer. It's also been suggested that we could use TeX itself to generate PNG images, thus: [[math:some TeX expression in here]]. I like this idea a lot, even though I'm of the age of WYSIWYG and I *fear* TeX -- Tarquin 22:10 Sep 26, 2002 (UTC)

The problem with the suggested syntaxes is that (one way or another) they don't allow scripts within scripts. My suggestion in the past has been "^{...}" and "_{...}" (which follows TeX even more closely) on the assumption that "^{" and "_{" will rarely or never occur naturally together. We could still double the "^" and "_" if that assumption proves mistaken, but we'll still need some sort of asymmetric bracketing; unlike other wiki syntax, scripts don't simply toggle. — Toby 10:32 Sep 29, 2002 (UTC)

(But TeX is *lovely* ...) The thing is, nice though it would be to have some sort of swish automagic mathematics-generator, I think this is a slightly separate (though related) issue: sub/superscripts are possible within HTML and they occur frequently enough (and not always in mathematical contexts) that it'd be nice to be able to do them wiki-style. --Bth

Yes, TeX is quite lovely; I use it all the time, even for writing letters to friends. After discussing possibilities for implementing it ad nauseam on the Wikipedia:mailing list, I eventually decided that it would only make editing harder for the uninitiated and thus shouldn't be done. But y'all may have fresh ideas that we didn't have before, so feel free to bring it up there again. — Toby 10:32 Sep 29, 2002 (UTC)

I think we should bring it up again. TeX would only be used for fairly complex equations; so most people who will come face to face with it will be mathematicians of some sort. Those (like me) who don't know tex already can probably handle the learning curve. -- Tarquin 10:45 Sep 29, 2002 (UTC).

I suspect that the time is right to think about allowing TeX markup, rendered as either HTML or MathML on the fly using either (latex2html, tex4ht,tth) and ttM - the selection being a user preference. MathML is at a critical stage where many of the newer browsers now support it. It's time web sites started delivering or we'll be here in 10 years time still discussing how to put maths on the web. The browser support issue is largely solved by linking pages to an XSLT stylesheet - see http://www.w3.org/Math/XSL/Overview-tech.html. Some font problems may remain for a time. On wikipedia, the biggest technical obstacle is probably the need to deliver XHTML rather than HTML in order to embed MathML properly - though a quick glance through some pages suggests that the HTML may convert easily. -- Gmp26

Summary of my opinion at this stage:

- Most math can be rendered in ASCII and the simple HTML that we support, and should be for maximum readability.
- Most of what we'd need rendered by LaTeX or the like and presented in an image format is diagrams, matrices, and other big displayed things.
- Since these often require extensions to LaTeX like Xypic, we shouldn't try to write our own LaTeX parser for what we think we'll need but instead allow people to use what they need for that particular diagram.
- Edit the LaTeX source to a diagram is much better for the wiki way than uploading new versions of an image.
- We don't really need to support special math markup inline, although there are some MathML features (like multiscripts) that it would be nice to use there.
- If we only call LaTeX for displayed equations and diagrams, then a natural wiki markup would be "$$" at the beginning of a line (and only there!). An ending "$$", natural for LaTeX but not for wiki, could be optional.
- If we're going to load packages using
`\usepackage`, then we'll need some markup to indicate the packages used, since`\usepackage`must appear before the`\begin {document}`and`\[`that precede the inputted source.

— Toby Bartels 13:59 Dec 11, 2002 (UTC)

Why is ONLY a small subset of the TeX commands implemented? No eqnarray, no \underrightarrow, no etc., etc., etc.128.175.112.224

I ran across the Wikipedia page for limit point, and noticed that my browser (IE6, the current most popular browser by far) displayed the HTML codes for the math symbols as plaintext. This was ugly and unreadable, so I changed them to use math tags. The author reverted my changes! I tried to discuss this with them but received no reply. While I'm certainly no fan of in-line images for symbols, in this case I think they're better than the alternative (strange codes appearing to 95% of viewers). Besides that, I'm sure the Wikipedia engine could easily convert these to HTML codes for users whose browsers support them, and even MathML one day for browsers supporting that.

In other news, I have read a Microsoft website in which Microsoft insisted that they would never support MathML natively in IE, and plug-ins were good enough. I'm sorry I don't have a link right now, but if they don't change their mind about this, any MathML plans for the web could be shot.

In some shared sites LaTeX is not available, and so the texvc solution does not work. An alternative is to use mimetex, a on-fly generator. I have put it to work here:

http://www.physcomments.org/wiki/

(please feel free to create some sandbox area if you want to test the idea). It needs, of course, a different math.php module.

Alejandro

Lets try this