Last month, I have written a program that converts a LaTeX document into a format that is ready to be copied and pasted into the WordPress editor.

I have been using it to post the notes of my cryptography class here, as well as some other posts.

Terry Tao has tested it on a couple of posts. Thanks to his feedback, the current version, while surely bug-filled and very limited, is stable enough to be used by other people. It is now available to anybody who might be interested.

What is the point of this program?

WordPress offers a very simple way to write a mathematical formula in a post, one writes “$ latex e^{-t^2}$”, and out comes . It was for this convenience that *in theory* moved from Blogger to here.

Anyone who has tried writing a relatively long mathematical exposition on WordPress, however, has faced various inconveniences, including:

- The online editor one has to use to write a post is unsuitable to write anything longer than a couple of hundred words. The editing window is tiny, saving and previewing is sometimes very slow, and there are some design flaws. (Saving a post makes the editor forget where you are in the post and resets the cursor to the beginning.)
- For inline mathematics, one has to always write
`$ latex . . . $`

, instead of`$ . . .$`

, and it is easy to forget to do so. Previewing a post, finding such mistakes, correcting them, and saving and previewing again is a pain. (See above point.) - Simulating displayed equations becomes more cumbersome, and one has to do something like
`<p align="center"> $ latex \displaystyle . . .$ </p>`

- Simulating
*numbered*displayed equations and referring to them is really bad, when one is used to the convenience of LaTeX. The numbering and the referring has to be done by hand, and if one rearranges the exposition, the numbers (and, more annoyingly, the*references*) have to be changed by hand. - Some WordPress themes (including the one I use), typeset LaTeX equations in gray. It is possible to make them black by adding
`&fg=000000`

at the end of every LaTeX equation. Note the difference between and . - Simulating something like
`\begin{theorem} ... \end{theorem}`

suffers from similar problems (manual numbering and referring) and one has to be careful to maintain a uniform style.

When posting lecture notes for a course, there is the additional problem that one needs to convert the posts back to LaTeX if one wants to collect the notes into a single document and make it available online (as I have done for some past complexity courses).

There is, of course, an obvious solution: write mathematical posts in a (subset of) LaTeX, and then use a conversion program to turn the LaTeX into a format suitable for cutting and pasting into WordPress.

This way

- it is easier to later package the mathematical content in the form of printable lecture notes;
- the post can be written with a nice text editor, and a partially written post can be easily previewed at any time;
- there is the convenience of latex, including automatically numbered equations and theorems, and symbolic references via \label and \ref.

Since this is a problem faced by anybody who writes math in WordPress, I assumed that such a program had been already written (probably several times) but I could not find one after extensive googling.

So I decided to write it myself.

Since I did not have a lot of time to devote to this project (if I were not going to have a working first version in a day I was going to give it up), I do not remember anything about compilers (last studied 15 years ago), and, to put it mildly, I don’t have a lot of programming experience, the final product is not coded in a particularly elegant way. It does, however, more or less work.

It handles LaTeX macros that do not involve parameters. It allows any set of theorem-like environments, which can be numbered with any combination of counters. (For example Theorems and Lemmas can share the same counter, but Remarks are numbered independently.) It recognizes math environments such as $…$, $$…$$, \[…\], and \begin{equation}… \end{equation}. (It does not recognize eqnarray and align, which are not supported by WordPress. In a future version, I plan to support eqnarray via HTML tables.) It support LaTeX tables defined via tabular, and it supports \label{…}, \ref{…} and \eqref{…}, which work in the expected way. A quirk of my primitive parsing is that {\em …} and {\bf …} cannot be nested, and there can be no curly bracket in their scope.

To get a sense of how it works, and of what is still missing, here is the unedited output of the program given the latex source of my Max Cut paper (the most recent arxiv submission).

LiveJournal’s syndication (its RSS internal RSS aggregator so that LJ users can see your posts on their friend-lists) is barfing on the single quotes in your html img tags, or maybe on the comma after the title parameter in these tags — see http://syndicated.livejournal.com/luca_feed/ for examples. Any chance of a fix?

That’s horrible 😦

Unfortunately the image links with the single quotes are created by WordPress itself, after one (or one’s conversion program) writes something like $ latex … $

Pingback: Notes of Lecture 4 « Error Correcting Codes: Combinatorics, Algorithms and Applications

I find it very hard to read really mathy posts in blog form. What is the advantage to doing things this way, rather than just posting a link to a pdf?

You can indirectly use align environment in wordpress by using \begin{array} \end{array} in wordpress latex. So for instance this’ll work: .

I’ve been using hevea in the past: http://hevea.inria.fr/

Thanks a lot for all of your hardwork. I’ll be using your program too and tell you how my experience is going.

Thanks “H”, this is new, using arrays with more than one column in WordPress used to produce a “formula does not parse” error.

I found out that in order for the array environment to work we have to write all of it with no line breaks. In this page: http://kogler.wordpress.com/2008/03/21/latex-multiline-equations-systems-and-matrices/ there a lot of good examples

Pingback: LaTeX 轉成 Wordpress « XOO’s

COOL……………..

Pingback: Wordpress and Latex « One problem a day

Pingback: LaTeX in WordPress « Eikonal Blog

Pingback: Using LaTeX in WordPress « God, Your Book Is Great !!

Pingback: The core of a cooperative game « Christian Marks

need some help from you..

in posting mathematical formulae in wordpress..

cud you please giv ur id? mine is itsshajahan[at]gmail[dot]com

this is really helpful. I will be using it to post on my blog.

I hope one day wordpress can support full LaTeX though. 😛

Pingback: Convert from LyX/Latex to wordpress postConverting an Overleaf document to a WordPress postHow to convert source code from LaTeX to LyX?Convert latex conference paper to html with figures and bibliographic referencesConvert LaTeX to HTMLRuby Code Highligh

Pingback: Convert from LyX/Latex to wordpress postConverting an Overleaf document to a WordPress postHow to convert source code from LaTeX to LyX?Convert latex conference paper to html with figures and bibliographic referencesConvert LaTeX to HTMLRuby Code Highligh