I was looking for the method that people use to write their beautiful math equations on their blogs. I found this program called LaTeX2WP (written in Python), which converts Latex file to HTML that is ready to be cut and pasted into WordPress editor. Thanks to its creator Luca Trevisan!

However, I could not find a single instruction on the web that gets the program to run immediately on my Windows 7. After several hours of trial and error, I finally figured it out! For those who are puzzled as much as I was, I hope the following steps can be useful.

(1) Download Python 2.7.1 and install it on C:\.

(2) Download LaTeX2WP and unzip the folder into C:\Python27

(3) Go to Control Panel > System and Security > System and click on the Advanced system settings tab. On the popup window, click on the Environment Variables tab. Scroll down the System variable menu until you see the variable `Path’. Select the variable Path and click the Edit button. Add the following to the end of the Variable value:

;c:\Python27,

(4) Next, go to Accessories and open the Command Prompt. If the prompt is not on the C drive, type C: and press Enter. Now, at the C:\> prompt, type the following and press Enter:

python c:\Python27\latex2wp.py c:\Python27\example.tex

(5) Note that example.tex already exists in the latex2wp package. The action in the preceding step generates the HTML file, example.html, which is now placed in the folder where the corresponding tex file is. Open example.html in Microsoft Office. Copy and paste the entire html file into the wordpress post editor which has been set to the HTML mode.

Publish the post and the following should now appear on your blog. Good luck!

Look at the document source to see how to ~~strike out~~ text, how to use different colors, and how to link to URLs with snapshot preview and how to link to URLs without snapshot preview.

There is a command which is ignored by pdflatex and which defines where to cut the post in the version displayed on the main page

Anything between the conditional declarations *ifblog . . . fi* is ignored by LaTeX and processed by latex2wp. Anything between *iftex . . . fi* is processed by LaTex and ignored by latex2wp.

This green sentence appears only in WordPress

This is useful if one, in desperation, wants to put pure HTML commands in the *ifblog . . . fi* scope.

Lemma 1 (Main)Let be a total ramification of a compactifier, then

The (modifiable) numbering scheme is that lemmas, theorems, propositions, remarks and corollaries share the same counters, while exercises and examples have each their own counter.

Theorem 2The adèle of a number field is never hyperbolically transfinite.

*Proof:* Left as an exercise.

Exercise 1Find a counterexample to Theorem 2.

Exercise 2 (Advanced)Prove Lemma 1.

Note that accented characters are allowed. Unfortunately, Erdös’s name cannot be properly typeset in HTML. (Note that to get the above approximation, you need to type backslash-H-space-o, rather than backslash-H-{o}. Both are good in LaTeX, but only the second is recognized by LaTeX2WP.)

One can correctly type the names of Håstad, Szemerédi, Čech, and so on.

It is possible to have numbered equations

and unnumbered equations

Unnumbered equations can be created with the double-dollar sign command or with the backslash-square bracket command.

It is possible to refer to equations and theorems via the *ref*, *eqref* and *label* LaTeX commands, for example to Equation (2), to Equation (1), and to Lemma 1 above.

eqnarray* is supported, but not eqnarray:

*You can nest a bold text inside an emphasized text or viceversa.*

The theorem-like environments *theorem*, *lemma*, *proposition*, *remark*, *corollary*, *example* and *exercise* are defined, as is the *proof* environment.

The LaTex commands to type $, %, and & are supported outside math mode, and % and & are supported in math mode as well:

The section symbol § is also supported.

WordPress has trouble if a LaTeX expression containing a symbol, such as is followed by an expression containing a symbol, such as . This is fixed by converting the inequality symbols into “HTML character codes.” Always write the symbols and in math mode.

It it is possible to have tabular environments, both with borders (the border will not be displayed in the LaTeX preview), as in

blog | quality |

what’s new | excellent |

in theory | poor |

and without borders as in

(The tabular environments will be centered in WordPress, but not in the LaTeX preview.)

And it is possible to include a picture so that the pdf file produced with pdflatex imports it from a local image file (which has to be pdf, gif, jpeg, or png) and the WordPress post imports it from a URL.

The *image* command used to generate the above image has three parameter: a size parameter for either the width or the height, expressed in pixels (if different from the original resolution, the picture will be scaled), a URL for the location of the image (this will be used by WordPress) and a local file name (which will used by pdflatex).

It is possible to have numbered and unnumbered sections and subsections. References to *label* commands which are not in the scope of a numbered equation or a numbered theorem-like environment will refer to the section number, such as a reference to Section 1 below.

HTML does not have good support for itemized list with descriptors (what one gets in LaTeX using the *itemize* environment with optional parameters in square brackets after the *item* commands). We can only offer the following rather ugly rendering:

- Case a. Description of case a
- Case b. Description of case b

** Examples of Sections **

** And Subsections **

**1. A section **

** 1.1. And a subsection **

**2. Changing the style **

The file latex2wpstyle.py contains several definitions that determine the appearance of the WordPress translation. It should be self-explanatory to change the way sections, subsections, proofs and theorem-like environments are typeset, and to change the numbering scheme for theorem-like environments.

The variable in latex2wpstyle.py contains a list of pairs of strings. For every pair, every occurrence of the first string in the document is replaced by an occurrence of the second before proceeding to the conversion from LaTeX to WordPress. If you want to use simple macros (which do not involve parameter-passing) then edit to add support for your own LaTeX macros. (You will have to define the macros in macrosblog.tex as well, otherwise you will not be able to compile your LaTeX file and preview it.)

Some macros are already defined. For example, backslash-E produces an expectation symbol:

Some more macros (see the LaTeX source)

*Computing*

Yves

March 23, 2012

Thanks a lot, for this information, and very difficult to find in the web.

Bruno Joyal

January 29, 2013

Extremely helpful! I have been using latex2wp on a Mac but couldn’t get it to work on my Windows 7 machine. Your instructions at the beginning solved the error message I was getting. Thanks a lot! (However, I have no idea what your instructions amount to… could changing the Path variable value have other symptoms?)