Help talk:Displaying a formula/Archives/2006

From Meta, a Wikimedia project coordination wiki


OK so we have transparency. Next problem is that we would like the pngs to be appropriately scaled to the surrounding text. This means that the png looks like it fits in even if the page is using larger or smaller fonts, or if the user has cranked up or cranked down the overall font scaling in the browser.

How do we do this? The strategy (which is simple-minded but in practice works well enough) is essentially the following. Suppose we knew the height of the png, and suppose we had some sort of general ratio along the lines of "height of an x in the png, as created by texvc with the settings it uses" relative to "the height of an x on our web page under certain conditions". Then we could express the height of png (in the <img> tag) in terms of ex units and, voila, everything scales appropriately.

So let's put that into practice. Step one is to write the following tiny shell script:

identify $1 | awk '{print$3}' | awk -F"x" '{print $2*0.11}'

and save it, changed to executable, in wiki/math as This script takes the name of a png as argument, uses the identify command (part of ImageMagick, so presumably already on your system) to generate a line of text about the png, and uses some awk to grab from that the height in pixels of the png. The factor of .11 is a magic value, determined empirically, that gives the visually-appropriate height of this png in ex units. If you want, run this script on a png and verify that it gives kinda sane values. For a png of a simple integral I think you get a value of around 4 or 5ex of height.

Step 2 is to open wiki/include/Math.php, which is the php code that deals with calling texvc and so on, and look for

function _linkToMathImage() 

which should be at about line 200. Change this to

 global $wgMathPath, $wgMathDirectory;
 $url = htmlspecialchars( "$wgMathPath/{$this->hash}.png" );
 $alt = trim(str_replace("\n", ' ', htmlspecialchars( $this->tex )));
# return "<img class='tex' src=\"$url\" alt=\"$alt\" />";

 $wgGetTexImageHeightInEx = './math/';
 $cmd = $wgGetTexImageHeightInEx.' '.
 wfEscapeShellArg( "$wgMathDirectory/{$this->hash}.png" );
 $heightInEx = chop(`$cmd`)."ex";
 return "<img class='tex' src=\"$url\" alt=\"$alt\" style=\"height:$heightInEx\" />";

So what we have changed is

  • note $wgMathDirectory as a global since we will need it, as well as just $wgMathPath
  • call $wgGetTexImageHeightInEx, the script we defined in step 1,
  • shove a style specifier that specifies height of the png in ex units at the end of the created URL.

(When/if this gets formalized into the code base, the maintainers will probably want to move the definition of $wgGetTexImageHeightInEx out to DefaultSettings.php, but for explaining and testing it's obviously easier to define it here as I did.)

That's it, we're done! Open a page displaying TeX pngs and ooh and aah with wonder as they scale larger and shrink smaller as you increase/decrease the size of the browser font scaling. (On Firefox or Safari on MacOS X you do this with command+ or command-, no idea about windows/linux browsers). (Ctrl++/Ctrl+- or Ctrl+Scroll wheel.) (CSS for images that scale with text)

What are the reasons for scaling via shell scripts instead of via CSS's ex and em (using height and width)? Daphne A 20:38, 6 February 2006 (UTC)
The point of the above code is not to actually carry out the scaling. The point of the code is to work out that, for example, the image is (I guess) three times as high as the "x". Once you know that, you can use either CSS or put the size in the HTML directly. Anyway, the issue is moot, because most modern browsers (Safari being a notable exception) have very nasty scaling code, and the result looks terrible. Dmharvey 23:20, 6 February 2006 (UTC)
Kind thanks for explaining. I don't agree, though, that most browsers make scaled PNGs look terrible. Rather, I think that most browsers make scaled-up PNGs look terrible. So how about making the PNGs three times (for example) the size needed. (The browser will then scale down by default.) Using even double sizes would probably be adequate. I've tested this with Firefox and IE6, and gotten decent results from both.   —Daphne A 17:35, 28 February 2006 (UTC)
I tried this some time ago, using the scaling down as you suggest. As I recall, my experience was that in equations involving thin horizontal objects, like minus signs and equal signs, the horizontal bits sometimes went missing altogether (including on the browsers you listed). So minus signs would sometimes vanish, and equal signs would sometimes turn into minus signs. Does that happen on your system? Dmharvey 17:45, 28 February 2006 (UTC)
Okay, here's the test I just did. I used GIMP 2.2 to create PNG images of text "a-b=4", using Trebuchet MS font and 0 compression. Browsers were IE 6.0 and Firefox 1.5. With IE, I found that text "a-b=4" displayed on my system at about the same size as GIMP-text font size of 20 pts. I then scaled an image of 20-pt "a-b=4" using the HTML height="20%" (which actually displayed larger than 20% of original size, but still quite small). All horizontal bars (in minus, equals, and four) in the down-scaled image were visible.
Repeating this in Firefox, I found that "a-b=4" displayed at about the same size as a GIMP-text font size of 22 pts. I then scaled an image of 22-pt "a-b=4" to 20%. Again, the down-scaled horizontal bars were all visible.
Note that this test does not use the enlarged PNGs that I was suggesting. (Because there were no problems, I didn't try.)   — Daphne A 20:06, 28 February 2006 (UTC)
This is mighty curious. A few questions: (1) Are you saying you scaled down 20pt text down to 4pts? And at 4pts it was still readable at all? (2) Since you mention IE, I assume you are running all this on Windows. In fact I recall Windows was the platform where things looked worst when I did my tests. What version of Windows are you running? (3) Do you have Windows' ClearType functionality turned on? (It's in something like display or desktop settings.) I thought ClearType only applied to font rendering, but maybe it does something to bitmapped graphics as well. Dmharvey 20:26, 28 February 2006 (UTC)
Sure.... (1a) Theoretically, yes, but as I said, it actually displayed larger than 20% of the original size, though still quite small. (1b) Just barely; actually, the minus sign was visible as something, but would have had trouble identifying it if I wasn't psychic: it was definitely not invisible though. (2) Windows XP SP2. (3) Yes. I've just now tried the IE test without ClearType or even standard antialiasing, and the horizontal lines were still visible (or at least not invisible).
Maybe it is the OS display technology? (What OS did you use?)   —Daphne A 22:00, 28 February 2006 (UTC)
I did my tests both on some edition of winXP and Mac OS probably 10.3.something. What you're saying is all very interesting. I should mention, in case you didn't know about it already, that I'm working on developing some actual MathML support for mediawiki. (See Blahtex and try The blahtex software can also generate PNGs, much the same way as texvc does. Right now, coincidentally, I've been working on the PNG output, and in particular studying issues to do with heights and depths of the output image. I'm considering switching to using latex+dvipng instead of the latex+dvips+imagemagick+ghostscript quartet that texvc currently uses. One nice thing about dvipng is that it can output the height and depth of the image very reliably. (Height is what you think it is; depth tells you where the "baseline" of the equation is within the image.) So if/when blahtex is used on wikipedia, it should be much easier to allow for rescaling of images to the correct size, without all the trickery discussed earlier in this section. Perhaps this could even be something in the user's preferences. Anyway, thanks for pointing out to me that it shouldn't be considered a lost cause. I'll keep it in mind. Dmharvey 22:27, 28 February 2006 (UTC)
MathML support would sure be nice. Good luck!   Daphne A 21:52, 2 March 2006 (UTC)

Missing Symbol

Is it possible to get a symbol added to the dialect of TeX that wikipedia uses? At the moment, we have \bigodot, but not \odot. \odot is useful because it is the solar symbol, and \bigodot is a bit large for that purpose. 07:32, 12 January 2006 (UTC)

Yes, things can be added. I think you need to file a bug report on Mediazilla? — Omegatron 14:05, 21 March 2006 (UTC)

Sans-serif font

See en:Wikipedia:Village_pump_(proposals)#Proposed_change_to_MediaWiki:Common.css for a discussion about changing the site-wide font to sans-serif. — Omegatron 03:58, 15 March 2006 (UTC)

<math> tag not recognized

my Wiki installation does not recognize <math\> tag. i.e. whenever I try to use, it just spits out the characters, not the formulae. like this: <math>{t_max}</math> (of course I try it without nowikis, here they are just to display it)

Have you read the following link?*checkout*/wikipedia/phase3/math/README. (by the way, please sign your messages with four tilde signs: ~~~~, makes the conversation easier to follow) Dmharvey 02:29, 21 March 2006 (UTC)

I need superscript for \to

... but not this kind. Rather, I want the O to be right above the arrow, implemented nicely without hacks. Please help. Ramir 06:23, 23 March 2006 (UTC)

I found the proper TeX way to do it: \buildrel P \over \to, but it does not work in this bloody renderer. Could anyone add a bug-report or something? I am too lazy to do that, knowing that developers rarely take notice (see, for instance bugzilla:2458). Ramir 06:43, 23 March 2006 (UTC)
Actually, this problem is being worked on. See m:Blahtex, which implements \overset to solve your problem, and also can do the non-ASCII characters you refer to in the bugzilla link. Dmharvey 13:23, 23 March 2006 (UTC)


I noticed that the \phantom command doesnt' work in wikipedia. Is there another way to leave some space in subscripts and superscripts? Thanks

math environment in different lines causes Failed to parse (unknown error):

My mediawiki is set up on windows machine, texvc is enabled, MikTex, ImageMagick, ghostscript, and Cygwin are all installed.

When I use

<math> \sqrt{10} </math>

in single line as a test, everything works fine. But when I tried to use the math environment in multiple lines


Failed to parse (unknown error): sqrt{10} appears. Suppose LaTex ignores newlines and spaces, so this should work,. Anyone knows how to fix this problem in windows environment?

I tried to use to test which part of mediawiki on windows went wrong. This method hacked the includes/Math.php renderMath($tex) {...}, and the only difference is the render() part. Instead of using the Math.php's render() function, it uses the result from the outside cgi. And the improperly parse problem is solved in this way, though the generated math is not good. So I think there must be something wrong in render() function in Math.php which can't parse the following condition properly in windows environment. Could anyone help to trace the render() function?

Josephsieh 03:15, 2 April 2006 (UTC)

Symbols fail to display

Can anybody please suggest why certain symbols fail to render correctly in my install. Something like

renders beautifully whereas replacing the \alpha with a \propto causes the whole equation to be shown without rendering as
P(r) \propto r^{n-1} \exp(-kr^2/2\sigma^2)

Certain other symbols also don't work e.g. \nabla and \sim. The strange thing is that perfect png images are created in my images/math folder - just for some reason they are not correctly displayed.

Many thanks in advance.

Joejk2 18:55, 3 May 2006 (UTC)

tensor ?

Is there a way to display tensor indices properly in a wiki without the (very useful!) tensor package ?LeYaYa 11:36, 6 May 2006 (UTC)

Equation numbering

Is there a good way to number equations? In math textbooks, equations usually have an equation number that is aligned to the right side of the page. For example, the (2.1.1) below would be right aligned.


I have a large number of ms-word documents with equations in them, what's the easiest way to get these into our Wiki? The best I've come up with so far is Word -> TeX conversion software (, automated search/replace using sed or something and a whole lot of manual editing.

If you want to manually align equation numbers, you can do this:
I don't recommend it, however, because it's a whole lot of CSS and there's no automatic numbering going on. It wouldn't be too difficult, however, to create a parser extension to automatically number equations, so you may want to go bug the developers.
Thanks. For reference, someone else beat me to it:, 00:30, 22 May 2006 (UTC)
Regarding your Word documents, I really can't help you. I'm surprised that there are even Word to TeX convertors out there. I would just rewrite the whole things (catching whole lot of other possible errors along the way). — Ambush Commander(Talk) 14:22, 21 May 2006 (UTC)
That's a whole lot of work that I don't want to do. We'll probably use the method above + a math student to manually fix the output.

On italian wikibooks we created a Template to do this, B:it:Template:Equazione The Doc 15:16, 21 May 2006 (UTC)

I didn't know about templates, but a combination of AC's HTML and your solution looks exactly what I was looking for.

I created an English variant of this Italian template, at [[1]]. This Eq template provides a way to add an equation number or label, right justified on the page. It doesn't automatically renumber equations, but at least it provides a way to refer to an equation to that a reader can click on a reference to an equation and jump to that equation. If it's useful, perhaps it could be moved to Wikipedia's main collection of templates. --Plasma g 19:41, 29 July 2006 (UTC)

I've also added W:en:Template:Equation; it's based on B:it:Template:Equazione, and is simple to use. 20:05, 7 February 2007 (UTC)


Hi, I was just thinking up that It should be possible to render the TeX formulas as w:en:SVG files. AFAIK, TeX uses vector based fonts for rendering, therefore it should be possible to render vector based images of a formula instead of the bitmap based PNG. This would be a great improvement when zooming in a website in a zoomable browser (f.e. Firefox with addons). TeX formulas would zoom in and out accordant to the text around it. --Abdull 13:18, 4 June 2006 (UTC)

Most of the time, SVN gets rasterized to PNG anyway for display inside the text, so the zoomable SVG point is basically null. That being said, it's an interesting idea, but needs an implementation. — Ambush Commander(Talk) 02:31, 5 June 2006 (UTC)
You might be interested in blahtex which provides en:MathML support. This would allow zooming as you describe. There's a test wiki at Dmharvey 12:00, 5 June 2006 (UTC)

Over leftright harpoons

Any way of getting a leftright harpoon over something as to define a line? It only shows how to get an arrow going in one direction or the other on top of two letters, but not in both. 13:12, 21 June 2006 (UTC)

I'm not sure exactly what you mean, but maybe when/if m:blahtex is installed, you'll be able to do this: [2] Dmharvey 13:43, 21 June 2006 (UTC)

Help in lining up equation


I've tried to use the math statements to look into some binary floating point explanations. So far I have

Ideally i would like to have the 1s and 0s lined up like so, with the braces beneath them

Can you do this in math or would it be best to make it into a picture? pluke 21:25, 28 June 2006 (UTC)

*sigh*. Unfortunately because the TeX implementation here is a bit broken, you can't quite do it. You can get pretty close with m:blahtex, see for example here. Maybe it will get installed one day, but for now I think you might need to draw a picture. Dmharvey 00:52, 29 June 2006 (UTC)
Dang. Any idea when they will update the wikimedia implementation of tex? I have saved the image that blahtex output to here. Any idea what license i should attach to it? Thanks for the help. Pluke 11:28, 29 June 2006 (UTC)
(1) We're working on it. (2) I think the self-made license is fine. Dmharvey 23:56, 29 June 2006 (UTC)
Todays update this this problem, now you can write like this:
AzaToth 14:32, 29 October 2006 (UTC)

What's up with math markup?

Anyone know why math markup is broken? This happened a few weeks ago and then started working again. Now it has been broken for quite a while. I've looked around, but I don't see any discussion of the problem or the resolution. Any ideas? Madhu 18:37, 21 July 2006 (UTC)

Seems to work for me: . Please be more specific. Dmharvey 02:19, 22 July 2006 (UTC)
Yes, it is working. All I saw was the markup itself rather than the rendered image. I think there is a firewall/security restriction on my end. BTW, is there a way to insert an @ symbol in math markup? is as close as I could get. Thanks! Madhu 01:36, 23 July 2006 (UTC)
Well, you should be able to just use the at-sign. But wikipedia's TeX implementation apparently doesn't support it. If/when blahtex is installed, this will be fixed. (Regarding the missing math, did the image filename contain the string "ad"? This sometimes causes ad blocking software to prevent the image being displayed.) Dmharvey 11:17, 23 July 2006 (UTC)
I don't know, I'm not at that location now, so I can't be sure. I'll look into it further and get back to you. Madhu 22:31, 25 July 2006 (UTC)


I just noticed that despite all claims to contary, \textstyle and friends work now, which is wonderful. I'll fix the help page. -- 19:23, 5 August 2006 (UTC)

Line space

I would like to create line space in my formula. How do I do that? I thought it was \\& 15:55, 18 September 2006 (UTC)

Dash after a formula

Lately after some formulae I write, if they are simple enough to be displayed in HTML, there is a dash added at the end of it. (For example: .) Why is that, can it be fixed? --Knakts 12:15, 19 September 2006 (UTC)

I have noticed this too, and in fact came here to complain about it. Wikipedia started doing this a few weeks ago, I think.-- 15:12, 22 September 2006 (UTC)
It's a bug. See bug 7367. 20:21, 23 September 2006 (UTC)
OK, thank you for the reference! --Knakts 11:18, 26 September 2006 (UTC)

Question / Request: Music scores

I'm not sure if this is the right place for my question - please indicate if there would be a better place to ask.

Is it possible to add a MusicTex like functionality to Wikimedia? This would enabel to typeset music in a direct way as it is possible now with mathematic formlas. Reasons:

  1. An interaction of the showed score and the describing text would be much reader-friendly. At the moment, scores are included as images, which have to be scaled either as thumbs, thus obscuring the article when enlarged. Or the score is included without the thumb option and is then much dependant on the viewer's windows sizes and screen/printer resolutions.
  2. The creation of scores would be much easier without the necessity of using external programs for creating bitmaps. A correction or expansion of typeset music by others will be possible with the proposed change. This would enable true wiki-procedures.
  3. During a recent discussion at de-Wikipedia it was remarked that short excerpts from musical scores might violate wikipedias copyright policy in The reason is that the images itself are published under GNU-FDL and thy might be shown without any context or comment. This would violate German and other countries laws on copyright concerning citation (No citation without context dealing with the cited material).

I have no idea if the existing musictex macros make it easy to extend wikimedias features. Personally I would make much more citations and examples of scores in articles if that feature would be added. I think it could be a great tool to improve the quality of articles in all wikipedias (and also in wikisource, coming to think of that...) --Hei ber 09:48, 3 October 2006 (UTC)

There is an existing extension based on Lilypond, but it cannot be installed for safety reasons. guillom 09:52, 3 October 2006 (UTC)
Thank you very much for the answer. This system seems exactly to do what I had in mind when asking here and it seems to be used on other wikis. Too bad there are security issues. Do you think it might be possible to remove these reasons or to have the program run in a "sandbox"? Or are there other programs or possibilities which are similar to LiliPond? (In any case it might be a partial solution to create the sheet music with LilyPond and put score as well as source in an article. In this way others can change the score more easily.) --Hei ber 20:26, 3 October 2006 (UTC)
You can check out Wikisophia. guillom 15:28, 4 October 2006 (UTC)
Very nice. Thank you for the link! I've also found Music_markup where the whole issue is discussed. --Hei ber 04:34, 5 October 2006 (UTC)

It'll be very helpful if you could add only \doublesharp, x like sign.-- 02:13, 16 December 2006 (UTC)

Formula aplication

Hy, I am interested in knowing if there is any way to use directly the formula format in programming/mathematic software, and if so in which program it can be used.

I usually use my HP49G in algebraic notation, and it would be a very usefull way to be able to add formulas to wikipedia like that! even more if the sintactics is linked with available mathematical programs!.

best regards,

Is it possible to set the background color?

I see a previous post suggesting how to modify the software to produce transparent GIFs, so I'll assume that isn't supported (too bad). What about just specifying the background color for the generated image—is that possible? —Doug Bell talkcontrib 16:23, 24 October 2006 (UTC)

How about this change in Functions, symbols, special characters?

When I first looked at the table, I was confused about the many occurrences of "\quad" , "\;" , "\," etc. and even today I find these just impede one-to-one reference. These are not part of the syntax we want to explain, so we should cut them. Those who really want to see the complete syntax can either hover over the rendering or edit the page. Can I just go ahead and change it? SebastianHelm 01:14, 28 October 2006 (UTC)

YES, I have also thought about that. AzaToth 14:37, 29 October 2006 (UTC)

New environment: array

now you can use the formula array:

1 & a & = & a + b \\
2 & b & = & c^2 + d \\
3 & c + a & = & d

AzaToth 18:59, 29 October 2006 (UTC)

Why formulas are looking out of focus?

Recently I've noted that the formulas rendered in png are looking out of focus and smudged. --Dante, the Wicked 16:10, 2 November 2006 (UTC)

Texvc updated again

This was a rather large update, that's wwhy it took such a long time. First of all, bug bugzilla:1182 is fixed, so non greek greek symbols () are not displayed as italics. Whats new is as following (\binom is more of a bugfix):

    L  & = \lim_{|x| \to \infty}\ {{\cos {1 \over x} \cdot  {-1 \over x^2}}\over {-1 \over x^2}} \\
    & = \lim_{|x| \to \infty} {\cos{1 \over x}} \cdot {-1 \over x^2} \cdot {x^2 \over -1} \\
    & = \cos{1 \over \infty} = \cos{\ 0} = 1
    L  & = \lim_{|x| \to \infty}\ {{\cos {1 \over x} \cdot  {-1 \over x^2}}\over {-1 \over x^2}} &\quad& \text{by me} \\
    & = \lim_{|x| \to \infty} {\cos{1 \over x}} \cdot {-1 \over x^2} \cdot {x^2 \over -1} && \text{by him} \\
    & = \cos{1 \over \infty} = \cos{\ 0} = 1 && \text{Axiom 3}
\bigl( \begin{smallmatrix}
  a&b\\ c&d
\end{smallmatrix} \bigr)$
Foo Bar
 A \xleftarrow{n+\mu-1} B \xrightarrow[T]{n\pm i-1} C
Some new symbols that where forgotten

AzaToth 14:36, 4 November 2006 (UTC)

Why change the layout?

I think the Revision as of 00:06, 1 November 2006 had a good layout. Why did you change it? Was it too wide? --Egriffin 15:06, 7 November 2006 (UTC)

It was too many separate math objects, so the server kept timing out because it was to much to handle. AzaToth 17:24, 7 November 2006 (UTC)
Shouldn't that only be a problem the first time the images are generated? — Omegatron 20:06, 7 November 2006 (UTC)
After getting 10+ zero sized replied when doing a "minor" edit, I decided to reduce the number of math tags. remeber that for each tag, there needs to make one database call at least, and it was around 1000 math tags on the page :) AzaToth 22:16, 7 November 2006 (UTC)
Ah. :-) — Omegatron 22:22, 7 November 2006 (UTC)

I'm getting tex instead of math

I just got my math function working on my 1.8.2 installation. But it only functions as < tex > instead of < math > . Does anybody here know how I can change this? Is it something I need to edit in math.php or mimetex.php? I appreciate it.Rovo79 20:06, 9 November 2006 (UTC)

I think it is in includes/Parser.php. On my 1.6.7 installation on line 454 it says case 'math':. In your case it probably says case 'tex':. If that doesn't help then maybe there is a line containing $wgParser->setHook("tex", somewhere that you need to change. --Egriffin 19:09, 14 November 2006 (UTC)

Use special template to simplify enumeration of math commands in Help pages?

Could somebody who already knows how to do this define a template that accepts a parameter EXPR (the code stripped of the <math> tags that would render the math expression), and generate the wiki code for three horizontal table cells that contain

<code>EXPR</code> || <math>EXPR</math> || <math>EXPR \, \!</math>

? This way it should be much easier to update the list and the wikicode will be much shorter. 15:38, 11 December 2006 (UTC)

That does not work, see Help:Displaying_a_formula#Syntax.--Patrick 18:39, 11 December 2006 (UTC)

Complex Math unknown?

I finally got my WindowsXP installation of MediaWiki to utilize Math formulas... kindof: Simple Math commands like <math>\left (\frac{a}{b}\right )</math> work as expected, and render as . But using more complex functions, like <math>\therefore</math> don't render as , but rather give a "failed to parse" error. For some reason, did my fresh download of MediaWiki 1.8.2 not include recent updates to texvc that includes those functions? I'm pretty sure this is an issue with the texvc program not recognizing some of the newer, more complex functions. How can I get it to recognize them? --MidnightLightning 04:36, 29 December 2006 (UTC)

You can acess the updated texvc from the SVN. AzaToth 17:05, 29 December 2006 (UTC)

cdot unicode character


\cdot \circ \bullet

I was able to see that \circ and \bullet are most likely ∘(0x2218) and ∙(0x2219) respectively. However the closest match for \cdot is ⋅(0x22C5) or equivalently &sdot;. Is sdot the Unicode equivalent of cdot in latex? -- 01:42, 31 December 2006 (UTC)

Is there a better place to ask this question? -- 06:29, 5 February 2007 (UTC)

? -- 02:32, 18 May 2007 (UTC) (originally, but can't prove it)

? -- 23:29, 7 August 2007 (UTC) (originally, but can't prove it)