I’m currently working on an article that make use of some math notation. Normally, in such cases, when you need something out of the ordinary that can’t easily be marked up as XHTML you render an image (yes, I know about MathML). It’s quite easy to render beautiful math formulae off-line. But making the round-trip out of WordPress can also be quite annoying, especially if you do a lot of tweaking and I normally do a lot of tweaking.
So I ventured out to look for something that let me embed the formula directly into the post and found the wp-latexrender plugin. But since I’m hosted, like most other blogs out there, I can’t install the necessary software on the server, not even in cgi-bin other than Perl scripts.
To my rescue came mimeTeX, a simple cgi-bin program written in C, and the public mimeTeX server. And voilà, here it is: a small, simple, fast, cached plugin without any configuration or software requirements to render something like this:

(Oh yeah, someone have probably done this already, but what the heck!)
Features
- Embed any LaTeX math notation supported by mimeTeX.
- Use public mimeTeX server, no cgi-bin install necessary.
- Cache generated formula locally for fast load time.
- Only working in the QuickTag editor.
Compatibility
This plugin has not yet been tested with WordPress 2.1 for compatibility. However, it has been audited following the notes from the WordPress developers and it should be compatible.
Download
The latest version (version 1.2) of the plugin can be downloaded as dahnielson_mimetex_v12.zip.
Installation
- Download the dahnielson_mimetex_v12.zip archive.
- Unpack the zip archive into your WordPress
pluginsdirectory. - Activate the plugin in the WordPress administrator panel.
- Important: You need a writable
/wp-content/cachedirectory on the server!
Usage
To embed LaTeX math formula into blog posts, enclose the formula in <tex></tex> tags. For details about supported LaTeX markup, visit the mimeTeX site.
ChangeLog
- 1.0: Initial release.
- 1.1: Fixed the format of the query string to the mimeTeX server.
- 1.2: The filter now has highest priority, no longer barf on & in TeX code.
Alternatives
Baris Evrim has created an modified version of the plugin, fixing some CURL issues and using the [tex][/tex] syntax.
There’s also an alternative based on my code tailored for WordPress MU that allows your users to inline LaTeX using the WordPress.com format.
32 comments
You realize, of course, that in one simplified instant, you have totally revolutionized Math markup on Wordpress. Thanks a million or two!
Actually, a lot of credit should go to John Forkosh for creating mimeTeX and setting up the public mimeTeX server my little plugin uses.
It’s an excellent little script, thank you for bringing it to my attention. But the way you finessed it into Wordpress interactivity, it’s brilliant.
Exactly what I needed. Thanks.
Actually, would it be difficult to modify this to use [tex] instead of <tex>?
Er, the reason being is some of the authors use the rich text editor, and if you use <>’s within that, save as draft, and return to it later, the <tex>’s are gone. :)
Aha!
That’s why I see some plugins use [whatever] instead of <this>. Personally I always use the quicktag editor since the rich text editor usually (in my eyes) produce a mess of code. And the brackets can have other meanings in texts (although [tex] isn’t very likely). Will see what I can do. Maybe I’ll make it into an option, but I hate options! ;-)
So in the meantime: 1) do not use the rich text editor, or; 2) find line
30indahnielson_mimetex.phpand replace:$regex = '#<tex>(.*?)</tex>#si';with:
$regex = '#\[tex\](.*?)\[/tex\]#si';And it will almost surely work.
Eric, great blog by the way!
That seems to have worked (editing the .php). I’ll let you know if anything strange happens. Thanks!
Thanks for writing your mimetex plugin. Could I make a minor suggestion? It all boils down to changing the $mimetex_host line to
$mimetex_host = curl_init('http://www.forkosh.com/mimetex.cgi?\\nocontenttype'.urlencode($formula_text));Firstly, the dreamhost url you’re using works fine right now. But if I change ISP’s then it might no longer work. The forkosh.com domain will always be updated with my current ISP, and I’ll always redirect mimetex.cgi to the public web service.
Secondly, I’m guessing you got formdata= by looking at the mimetex.html page, or maybe at mimetex.c itself. Unless I’m mistaken, it’s probably not needed by your plugin. And mimetex interprets queries beginning with formdata= as coming from html forms, and handles them slightly differently. Please let me know if you have a specific reason for formdata= that I’ve overlooked.
Finally, prepending each query with
\nocontenttypewill remove the headersCache-Control: max-age=7200Content-type: image/gif
Since you’re caching mimetex images in local .gif files, you don’t need those headers, and your cached files will be in the standard gif format.
Thanks for the suggestions!
I will look into it and maybe release a new version. BTW, I added formdata since I hade some trouble with spaces ending up as plus signs in the output.
The reason for pointing to Dreamhost was because the
CURLOPT_FOLLOWLOCATIONcould not be activated when in safe_mode. So sadly no redirects if you’re hosted…Adding
\noconenttypeisn’t necessary since CURL is told to ignore any headers when writing the output (that’s why theCURLOPT_HEADERoption is set to false).And as I mentioned above, the
formdata=was added to fix the problem with spaces ending up as plus signs in the output. It was the only way to get the plugin working correctly, that I could figure out.Well, it sounds like you should ignore all my suggestions, and leave your plugin exactly the way you originally wrote it. Strange about the spaces/plusses problem. I thought urlencode would encode spaces as %20’s, which are interpreted okay. Mimetex sometimes converts plusses to spaces and sometimes not. In principle, plusses should always be converted to spaces, and intended plusses should be encoded as %2b’s. But mimetex sometimes gets improperly encoded query strings, with actual spaces and with actual plusses not encoded at all. So I try to figure out what’s actually intended in each query string, but don’t always get it right. Maybe I should just always convert plusses to spaces, and not try to accommodate improper ly encoded query strings. I’ll have to think about that some more. Thanks for explaining why you used formdata=.
Come to think about it, I could fix the redirection by parsing the header contianing
Location:by my self and not relying on CURL to get around the safe mode restriction. At least the plugin will be future proof. So all suggestions wasn’t a waste! ;-)I have modified the plug-in.
Those who have problems with curl for some reason (probably hosting) should use it. And it also has the [tex][/tex] syntax.
You can download it from –>here
I have installed the MimeTex and Snoopy versions of the plug-in. I created a cache folder in my WordPress folder. I can only assign write persmission to the WordPress folder. I’m not sure if it propogates to the cache folder inside.
I keep getting MimeTex code instead of rendering. For example:
[tex]\large\displaystyle e^x=\sum_{n=0}^\infty\frac{x^n}{n!}[/tex]
(this should be code and not math symbols)
Do you have any suggestions as to what may be wrong? I have WordPress install on my site.
Thanks,
Brett
@Brett: Did you activated the plugin? I think that is the problem :)
You were right. I thought it was activated. However, I get this now:
Fatal error: Call to undefined function curl_init() in d:\home\ABC.COM\WordPress\wp-content\plugins\dahnielson_mimetex.php on line 49
As well, the editor strips out any tags.
The altered version doesn’t work for me either. I left a post there: http://www.anlak.com/?page_id=66.
Thanks,
Brett
Does any one have suggestions on how I can possibly test certain functions to figure out which part is not working and keeping the overall program from working?
Thanks,
Brett
@Brett: Lets continue this discussion on http://www.anlak.com/?page_id=66
I dont want to pollute here.
There seem to be a problem with “eqnarray” and “array” as you have to use “&” in them. The “&” is being published as “#038″. Also, I having some problem with “
@Suman: Thank you for the bug report. The solution to the problem is suprisingly simple, just rise the priority of the filter by adding a
1as a third argument to theadd_filterfunction!The latest version of the script (v1.2) contain the fix. I hope this works for everyone.
The plugin doesn’t seem to close the alt command properly for some equations. In particular, if you try
\mathbb{P}(X \le x) = \int_{-\infty}^{x} \frac{1}{\sqrt{2 \pi}} \exp(- t^2/2) dt
The tag it produces is
src=”http://www.ergodicity.net/wp-content/cache/tex_018481e929720057fddf867c097abca7.gif” alt=”mathbb{P}(X le x) = int_{-infty}{x} frac{1}{sqrt{2 pi}} exp(-t{2}/2) dt” />
which produces a unicode symbol #8221 instead of the end quote for the alt tag.
Sorry, in that last code it should have been
src=”http://www.ergodicity.net/wp-content/cache/tex_018481e929720057fddf867c097abca7.gif” alt=”mathbb{P}(X le x) = int_{-infty}{x} frac{1}{sqrt{2 pi}} exp(-t{2}/2) dt& #8221; />
i put a space between the & and the #8221 to be clearer.
@asarwate: Thanks for the report! I will look into it.
A temporary solution would be to not include the equation as alt-text, replace it by some generic string like “equation” or something, but it’s nice to have the original equation since it actually make sense as alt-text. I will look into it.
I just tried to recreate the bug by including your equation in a post on this blog using the latest version (v1.2) of the mimeTeX plugin, but was unable to do so, everything work as it should. I’m guessing you’re still using v1.1 that might experience such symptoms.
It seems my WP template or something auto-parses ” as fancy quotes (which are that unicode tag). Sorry to bother you, since I guess the problem is on my end.
I am having a hard time figuring out how to use \eqnarray in [tex]\LaTeX[/tex] format. There is a problem with &. Any clue?
@Suman Sanyal: Are you using the latest version of my plugin (that uses the <tex></tex> syntax)? Because that issue should be resolved by now, see my previous comment.
Thanks! Eqnarray is working now!
This might be pushing it…but got any idea about
1) including math symbol in Title?
2) including custom latex definition.
3) improvement to the vertical alignment of images
4) I still cannot use “>”
[Lets see if I can use “>” here…. >
I modified the equation editor found here to use mimeTeX instead of LaTeXRender. I’m thinking it should be a matter of a few mods to incorporate into your WordPress plugin. :)
The equation editor I have can be found here. There is a download link to the source in that page. I’m still actively modifying the equation editor to further extend its functionality, so don’t fret if it becomes intermittently unavailable. ;)
Just installed WordPress 2.3, created /wp-content/cache as a writeable directory, and activated Dahnielson’s mimeTex plugin from within WordPress, but it not work. In other words, on entering the code x^5, the 5 did not appear as a superscript.
Any ideas please.
Richard
I have not yet upgraded WP to 2.3 myself and, unfortunately, that will probably not happen in the imminent future (due to my need of sandboxing it first to upgrade the theme and plugins, and make sure that all my customizations are in place). So I have no idea why it breaks. But I’m hardly surprised — 2.3 is a different beast than 2.2.
20 Trackbacks/Pingbacks
[…] MimeTeX - Wordpress LaTeX Plugin […]
[…] 数学公式支持:因为图形学里面涉及不少数学,所以公式渲染是不可避免的,因为不能在虚拟主机上装latex,所以只能用mimeTex了,插件用的是Dahneilson写的。使用起来很简单,比如我们的渲染方程:I(x,x_1)=g(x,x_1)[varepsilon(x,x_1)+int_{s}rho(x,x_1,x_2)I(x_1,x_2)mathrm{d}x_2] […]
[…] mimeTeX 1.1 Use tags to embed LaTeX math in posts, see the mimeTeX manual for details. By Anders Dahnielson. […]
[…] Dahnielson专门为WordPress写了一个插件,使用一个公共的mimeTeX服务器,从而避免了在cgi-bin中安装(有的服务器还不支持这个)。它从服务器上取得图片,放在Blog目录中的wp-content/cache目录下。只要在写文章的时候把TeX公式用<tex></tex>标记括起来,页面在浏览器打开时就会将代码自动替换为图片,非常方便。 […]
[…] dahnielson mimetex,让用户可以使用TeX语言来输出公式,由于使用一个公共的mimeTeX服务器从而避免了在cgi-bin中安装。 […]
[…] 作者网站:mimetex 也可以直接下载 […]
[…] Anyhoo - David Gilmour emailed me to say that he was exploring the possibility of incorporating a plugin into the exc-el wordpress installation that would allow users to put into their posts. This inspired me to hunt around, and I came across this site, which offered just such a plugin. After a bit of playing around, I decided that i would be better to use the adapted version created by Barış. […]
[…] dahnielson mimetex,让用户可以使用TeX语言来输出公式,由于使用一个公共的mimeTeX服务器从而避免了在cgi-bin中安装。 上传激活,在文章中在<tex></tex>中使用TeX即可,由于生成的图片放在wp-content/cache/目录下,所以需要确保这个目录有写权限。 […]
[…] I was having some kind of odysee around the web to find some working mimeTeX-Plugin to use with WordPress. I found Anders Dahnielson’s Version leading to a Version using Snoopy instead of Curl: Baris Evrim Demiroz’s Version. […]
[…] which I have used successfully in other environments. In my search I came across mimeTeX via Dahnielson’s site. This plugin was simple to […]
[…] the question mark is a little high. Wordpress LaTeX stuff provided by this plugin modified from this […]
[…] Wikipédia, et sur certains forums mathématiques. Même sur ce blog, il existe un plugin pour inclure facilement des formules LaTeX sous forme d’image (ce plugin utilise mimeTeX et […]
[…] Go to http://en.dahnielson.com/2006/09/mimetex-plugin.html and download the plugin for the WordPress. That is what I did. It is a single .php file. The […]
[…] Dahnielson » Blog by Numbers: Don’t Shoot the Mime, TeX! (tags: wordpress tex) […]
[…] mimetex如此强大,热门的blog,论坛程序都有专门开发的插件,WordPress也不例外。比如dahnielson_mimetex,现在已经到1.2版本。我下载回来一试,不知怎么回事,简单的式子还好,一到复杂的,比如里面有"&"等就不行了。后来发现可能是它的filter优先级个人的都不一样,自己修正了一下。另一个问题是公用的mimetex服务器被停了,居然也没人声张弄一个新的出来。我只好自己弄了一个。 […]
[…] plugin for wordpress and decided to go with that for the time being. The original homepage I found: Mimetex Plugin. Unfortunately, this hosting doesn’t permit libcurl. But then I found this revision, which […]
[…] Dahnielson’s mimeTex plugin WPMU Plugin - LaTex Math Now it is easy to write equations in wordpress! […]
[…] senza aver installato nessun tipo di programma sul server. Per fare questo, utilizziamo questo plugin, con però la modifica del dollaretto, che è reperibile […]
[…] the MimeTeX […]
[…] de l’encyclopédie Wikipédia, et sur certains forums mathématiques. Même sur ce blog, il existe un plugin pour inclure facilement des formules LaTeX sous forme d’images (ce plugin utilise mimeTeX et évite […]
Post a comment