WordPress and LaTeX on A2 hosting

After my previous hosting service failed on me, I decided to change my hosting service. I did quite extensive research about each hosting service. My main criteria are following:

The three criteria aren’t unusual and many of hosting services do satisfy. The hardest criteria was the last one. It’s hard to find a shared hosting service with LaTeX installed. After a lot of research, I came to conclusion that A2 hosting was the best choice because of a blog post.

Installing WordPress is rather smooth process nowadays because most of steps has been automated except editing wp-config.php.

After installing WordPress, I immediately started installing WP LaTeX, a plugin that replaces LaTeX code on an article or a page by a corresponding png images. It uses wordpress.com’s API to generate png images by default, but you can configure it to use local LaTeX installation. Unfortunately, it didn’t work out of box when I enabled this option. Of course, I made sure wp-content/latex directory was writable but it kept telling me that it cannot find latex.fmt:

This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4) I can't find the format file 'latex.fmt'!

This was rather odd since I could generate a dvi file (WP LaTeX generates a dvi file and converts it to a png image using dvipng) when I ran latex sample.txt through ssh. After searching online for a while, I figured the problem was that WP LaTeX changed the working directory to /tmp and latex could not find latex.fmt from /tmp. So I manually edited the line 188 of automattic-latex-dvipng.php:

if ( !$this->tmp_file = tempnam( '/tmp', 'tex_' ) ) // Should fall back on system's temp dir if /tmp does not


if ( !$this->tmp_file = tempnam( '<path to my home directory>/latex_tmp', 'tex_' ) ) // Should fall back on system's temp dir if /tmp does not

And I copied latex.fmt (find -name “latex.fmt” would probably find one) into ~/latex_tmp. So finally, you can see beautiful formula here, sin2(x)+cos2(x)=1, and it’s not coming from wordpress.com anymore.

I also searched for a good code hightlight plugin and settled with Syntax Highlighter for WordPress. With this plugin, you can wrap code on article with [language] and [/language] (language is php, html, etc…) and it automatically highlights the code with Alex Gorbatchev’s SyntaxHighlighter package. Because highlighting happens on client-side, it won’t benefit users without JavaScript enabled but all other plugins I tried either produced bogus markup (does not pass validator) or didn’t handle entity reference properly.