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:
- Cheap -- Because I don't do much web programming, and my blog won't get much traffic, I wanted my hosting service to cost $7 a month or below.
- Feature multiple MySQL databases and add-on domains -- Although I don't intend on getting a lot of traffic, I do have a quite few domains, and I need to maintain that. So I must have multiple addon domain / database support.
- Support secure FTP connection and SSH certificate -- Security is important.
- Has LaTeX installed -- About half of my blog entries contain LaTex expressions. I used to use Easy LaTeX to grab png images out of wordpress.com but added latency and dependency on external service isn't great. So I wanted to get rid of this dependency with new hosting service.
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
to
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,
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.