Hi everyone,
Is it possible to retrieve (preferably via the MediaWiki API) an image representing a mathematical formula given in the <math> tags that are frequently encountered in Wikipedia articles ? It would be very helpful if there were a way to "expand" these tags directly into images, similarly to how the "templates=expand" string appended to the query string automatically expands most of the templates in an article's wikitext; otherwise, a section of the API or of the site (such as a Special page) that can make this conversion for individual fragments would also be very helpful.
Thanks in advance, Gabriel
2010/12/13 Gabriel Sandor gabi.t.sandor@gmail.com:
Is it possible to retrieve (preferably via the MediaWiki API) an image representing a mathematical formula given in the <math> tags that are frequently encountered in Wikipedia articles ?
There's no direct way to do this, although I guess it could be implemented. A workaround would be to do something like http://en.wikipedia.org/w/api.php?action=parse&text=<math>\gamma=\frac{1}{\sqrt{1-v^2}}</math>&format=yamlfm , which will give you the HTML generated for this <math> tag, which could be an image (like in this case), or HTML if the formula is sufficiently simple (try a^2+b^2=c^2 for instance).
Roan Kattouw (Catrope)
I see, very helpful idea, thank you ! And what if the formula is really long ? I guess there are limits to the length of the URL, so is it possible in this case to send a POST message and retrieve the same result ?
On Mon, Dec 13, 2010 at 1:23 PM, Roan Kattouw roan.kattouw@gmail.comwrote:
2010/12/13 Gabriel Sandor gabi.t.sandor@gmail.com:
Is it possible to retrieve (preferably via the MediaWiki API) an image representing a mathematical formula given in the <math> tags that are frequently encountered in Wikipedia articles ?
There's no direct way to do this, although I guess it could be implemented. A workaround would be to do something like http://en.wikipedia.org/w/api.php?action=parse&text= <math>\gamma=\frac{1}{\sqrt{1-v^2}}</math>&format=yamlfm , which will give you the HTML generated for this <math> tag, which could be an image (like in this case), or HTML if the formula is sufficiently simple (try a^2+b^2=c^2 for instance).
Roan Kattouw (Catrope)
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
2010/12/13 Gabriel Sandor gabi.t.sandor@gmail.com:
I see, very helpful idea, thank you ! And what if the formula is really long ? I guess there are limits to the length of the URL, so is it possible in this case to send a POST message and retrieve the same result ?
Yes, POST works as well, for all API requests.
Roan Kattouw (Catrope)
On Mon, Dec 13, 2010 at 12:57:35PM +0100, Roan Kattouw wrote:
2010/12/13 Gabriel Sandor gabi.t.sandor@gmail.com:
I see, very helpful idea, thank you ! And what if the formula is really long ? I guess there are limits to the length of the URL, so is it possible in this case to send a POST message and retrieve the same result ?
Yes, POST works as well, for all API requests.
Is there any reason besides coder convenience for a client to ever GET instead of POST for API requests?
Brad Jorsch wrote:
On Mon, Dec 13, 2010 at 12:57:35PM +0100, Roan Kattouw wrote:
2010/12/13 Gabriel Sandor gabi.t.sandor@gmail.com:
I see, very helpful idea, thank you ! And what if the formula is really long ? I guess there are limits to the length of the URL, so is it possible in this case to send a POST message and retrieve the same result ?
Yes, POST works as well, for all API requests.
Is there any reason besides coder convenience for a client to ever GET instead of POST for API requests?
No.
2010/12/13 Brad Jorsch b-jorsch@alum.northwestern.edu:
Is there any reason besides coder convenience for a client to ever GET instead of POST for API requests?
Cacheable requests (with the maxage and smaxage parameters) are only supported for GET, not for POST.
Roan Kattouw (Catrope)
So eventually I tried this and indeed it works as expected. I have one more question though.
I've seen that most of the complex math formulas are converted into .png images with some long names - for instance, the <math>\iiiint\limits_F , dx,dy,dz,dt</math> formula (triple integral) is converted into an image with the name 49005f50f3ba2dfade3a265ebe363ee9.png. I'd like to know, is this file name unique for each formula ? And is it persisted on the wiki's server indefinitely, just like other images in articles ? To be more clear, is the triple integral formula always going to be associated to this 49005f50f3ba2dfade3a265ebe363ee9.png file ? I'm trying to implement a cache mechanism in my app that tries to also deal with images generated from math markup (besides usual images in articles), that's why I have this curiosity. I'd like to know if I can safely associate a math markup string with a file name so that there's no need to retrieve the image from the server again when I encounter that formula.
On Mon, Dec 13, 2010 at 1:23 PM, Roan Kattouw roan.kattouw@gmail.comwrote:
2010/12/13 Gabriel Sandor gabi.t.sandor@gmail.com:
Is it possible to retrieve (preferably via the MediaWiki API) an image representing a mathematical formula given in the <math> tags that are frequently encountered in Wikipedia articles ?
There's no direct way to do this, although I guess it could be implemented. A workaround would be to do something like http://en.wikipedia.org/w/api.php?action=parse&text= <math>\gamma=\frac{1}{\sqrt{1-v^2}}</math>&format=yamlfm , which will give you the HTML generated for this <math> tag, which could be an image (like in this case), or HTML if the formula is sufficiently simple (try a^2+b^2=c^2 for instance).
Roan Kattouw (Catrope)
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
2011/1/20 Gabriel Sandor gabi.t.sandor@gmail.com
So eventually I tried this and indeed it works as expected. I have one more question though.
I've seen that most of the complex math formulas are converted into .png images with some long names - for instance, the <math>\iiiint\limits_F , dx,dy,dz,dt</math> formula (triple integral) is converted into an image with the name 49005f50f3ba2dfade3a265ebe363ee9.png. I'd like to know, is this file name unique for each formula ? And is it persisted on the wiki's server indefinitely, just like other images in articles ? To be more clear, is the triple integral formula always going to be associated to this 49005f50f3ba2dfade3a265ebe363ee9.png file ? I'm trying to implement a cache mechanism in my app that tries to also deal with images generated from math markup (besides usual images in articles), that's why I have this curiosity. I'd like to know if I can safely associate a math markup string with a file name so that there's no need to retrieve the image from the server again when I encounter that formula.
On Mon, Dec 13, 2010 at 1:23 PM, Roan Kattouw roan.kattouw@gmail.comwrote:
2010/12/13 Gabriel Sandor gabi.t.sandor@gmail.com:
Is it possible to retrieve (preferably via the MediaWiki API) an image representing a mathematical formula given in the <math> tags that are frequently encountered in Wikipedia articles ?
There's no direct way to do this, although I guess it could be implemented. A workaround would be to do something like http://en.wikipedia.org/w/api.php?action=parse&text= <math>\gamma=\frac{1}{\sqrt{1-v^2}}</math>&format=yamlfm , which will give you the HTML generated for this <math> tag, which could be an image (like in this case), or HTML if the formula is sufficiently simple (try a^2+b^2=c^2 for instance).
Roan Kattouw (Catrope)
Yes, the name is unique, I discovered by reverse engineering that it is merely "the MD5 transformation of the normalized TeX code". An intelligent trick that, I guess, points directly on the png image without any need to calculate it again: I presume that the name only is calculated, and, if the png exists, it is uploaded! The "normalized TeX code", I guess, is the text that you can see browsing the html code, into the "alt" attribute of the image tag.
There are online free MD5 coders somewhere into the web, try the conversion of alternate text.
Nothing of this is documented, I discovered it by myself; can be, I'm absolutely wrong. :-)
Alex
mediawiki-api@lists.wikimedia.org