**[Using LaTeX2WP]**

Click here to download LaTeX2WP version 0.6.2, May 20, 2009

LaTeX2WP is written in Python, so you’ll need a Python interpreter.

(If you are using Linux/Unix or OS X, then you already have it. If you are running Windows, go here and get the Windows installer for 2.6.1)

Uncompress the files of the LaTeX2WP distribution in the directory in which you are going to write your posts in LaTeX.

(On OS X, double click on the file latex2wp.0.6.2.zip after saving it; on Linux `unzip latex2wp.0.6.2.zip`

. If your Windows machine says it doesn’t know what to do with a .zip file, get 7zip.)

Write your LaTeX post, say you call it `spam.tex`

. When you are done writing your post, type from the command line

`python latex2wp.py spam.tex`

This will produce a file `spam.html`

. Open it with a text editor, copy and paste it into the WordPress editor, and here is your post.

The file *readme.txt* describes some of the LaTeX features that are recognized by LaTeX2WP and those that are not. The file *example.tex* shows how to typeset in colors and include pictures and hyperlinks. It is easy to change the way theorems, section names, etc., are typeset, and to add simple macros. More about this on the Using LaTeX2WP page.

### Like this:

Like Loading...

## 29 comments

Comments feed for this article

December 14, 2009 at 11:28 pm

zhiyongyanThank you very, very much!

It works well for me !

I have a quetion: Could the reader get the .tex and .pdf files from my blog?

thanks a lot!

December 15, 2009 at 12:12 am

zhiyongyanCould the reader get the .tex and .pdf files of the ( some or all ) articles in my wordpress blog ?

thanks!

December 22, 2009 at 3:30 pm

loyolavery awesome! a great contribution to the math online community, thanks!!!

March 16, 2010 at 6:52 am

Latex in WordPress « Programming Resources[…] Theory offers a solution to this problem whereby you can write your posts in latex and then use a Python file to convert […]

July 10, 2010 at 12:31 pm

SpencerI’m having some trouble getting going with latex2wp.

My file is called general.tex and I consistently see

File “”, line 1

python latex2wp.py general.tex

^

SyntaxError: invalid syntax

Am I doing something silly wrong (I’m completely new to python and am running Windows so have downloaded and tried Python 2.6 and 2.7) or is there a deeper reason for this do you know?

August 7, 2010 at 6:39 am

Leandro AlexandreIt’s simply amazing man! Thanks a lot!

August 7, 2010 at 7:09 am

LaTeX e Wordpress: LaTeX2WP | Incerteza em Princípio…[…] funcionamento do programa é bem simples. Você deve baixar o arquivo compactado na página http://lucatrevisan.wordpress.com/latex-to-wordpress/download/ , descompactá-lo num diretório onde esteja seu arquivo .tex, e executar o […]

August 26, 2010 at 2:59 pm

LaTeX2WP « Polariton[…] wordpress painlessly, without going through the rigmarole of using JavaScript. It is available at http://lucatrevisan.wordpress.com/latex-to-wordpress/download/. It’ll make the more technical posts a lot easier to write, for sure. Categories: […]

September 24, 2010 at 6:07 pm

VivekI get this error:

python c:\python31\l2wp\latex2wp.py hw2sol.tex

Traceback (most recent call last):

File “c:\python31\l2wp\latex2wp.py”, line 657, in

s=extractbody(s)

File “c:\python31\l2wp\latex2wp.py”, line 140, in extractbody

for i in range(1,(len(L)+1)/2) :

TypeError: ‘float’ object cannot be interpreted as an integer

What’s wrong?

November 5, 2010 at 12:49 pm

chandrasekharHi–

i am using fedora and i am getting this error.. can you please help

Error: can’t open file ‘latex2wp.py': [Errno 2] No such file or directory

January 19, 2011 at 12:22 pm

LaTeX to WordPress | Testisivu[…] on tehty vanhasta LaTeX-lähdekoodista ohjelmalla latex2wp, jonka voi vapaasti ladata sivulla http://lucatrevisan.wordpress.com/latex-to-wordpress/download/ olevasta linkistä. Ohjelman tarvetta perustellaan […]

January 19, 2011 at 11:22 pm

latex2wp, alustava testi | Testisivu[…] käännösohjelmaa latex2wp. Alle kopioitu sen generoima koodi sivulla http://lucatrevisan.wordpress.com/latex-to-wordpress/download/ mainitusta esimerkkitiedostosta example.tex. Tätä seuraavassa kirjoituksessa kokeilen tätä […]

April 27, 2011 at 9:20 pm

Latex2wordpress « under the sun[…] (2) Download LaTeX2WP. […]

July 12, 2011 at 8:46 am

Latex in Wordpress « Procrastimatics[…] I created the post using Latex2wp. It was very easy to use, so easy that someone like myself who doesn’t know a thing about […]

July 29, 2011 at 10:31 am

From LaTeX to Wordpress « schlappohrhase[…] in my WordPress blog. Thanks to Dirk Lorenz I have found out that I should use the Python script latex2wp for this. So this post is my first try to use […]

November 20, 2011 at 5:34 pm

LaTeX to WordPress (latex2wp.py) « Guzman's Weblog[…] Here is the post that was copied and pasted using the example.tex supplied by downloading the program: […]

November 21, 2011 at 5:50 am

LaTeX to WordPress (latex2wp.py using terrystyle.py) « Guzman's Weblog[…] Here is the post that was copied and pasted using the example.tex supplied by downloading the program: […]

December 30, 2011 at 9:43 am

$latex LaTeX$ na WordPress – porada « FIKSACJE[…] entuzjazmu – mogą pozostać prywatne! Skrypt o którym mowa można pobrać na tej stronie, zaś instrukcja jego używania znajduje się tuż […]

December 30, 2011 at 11:12 am

LaTeX na WordPress – porada « FIKSACJE[…] entuzjazmu – mogą pozostać prywatne! Skrypt o którym mowa można pobrać na tej stronie, zaś instrukcja jego używania znajduje się tuż […]

January 12, 2012 at 4:22 pm

DanielI converted the example.txt file (part of the LaTex2WP distribution) with LaTex2WP and then pasted the ouput html file in the WordPress editor window. I then saved the draft and previewed the post but it did not work. I am seeing a lot of html code and LaTex equations that do not parse. Does LaTex2WP work with the free version of WordPress or do I need to purchase the WordPress upgrade to get it work.

January 12, 2012 at 6:50 pm

lucaIt works with the free version hosted on wordpress.com

When you go to the editor window, you’ll notice that there is a tab that lets you choose between the “visual” editor and the “html” editor. You want to choose “html” editor before pasting.

July 18, 2012 at 10:18 pm

De Latex a WordPress « Memorandum Matemático[…] Para descargar esta utilidad de clic aquí […]

September 18, 2012 at 9:11 pm

Using Latex in WordPress | Statistical Signal Processing (SSP) Lab, IISc[…] popular and more functional alternative is Latex2Wp. Download and install it from here. (Interestingly, it looks like most mathematicians use this plugin for blogs, for eg. Terence […]

November 12, 2012 at 3:49 pm

On blogging and Latex « M721: Index Theory[…] http://lucatrevisan.wordpress.com/latex-to-wordpress/download/ […]

November 16, 2012 at 7:51 am

hugoi get the same error as Vivek

January 25, 2013 at 10:51 am

xaboblog\documentclass[12pt]{article}

\usepackage[pdftex,pagebackref,letterpaper=true,colorlinks=true,pdfpagemode=none,urlcolor=blue,linkcolor=blue,citecolor=blue,pdfstartview=FitH]{hyperref}

\usepackage{amsmath,amsfonts}

\usepackage{graphicx}

\usepackage{color}

\setlength{\oddsidemargin}{0pt}

\setlength{\evensidemargin}{0pt}

\setlength{\textwidth}{6.0in}

\setlength{\topmargin}{0in}

\setlength{\textheight}{8.5in}

\setlength{\parindent}{0in}

\setlength{\parskip}{5px}

\input{macrosblog}

\begin{document}

Look at the document source to see how to \sout{strike out} text, how

to \begin{red}use\end{red} \begin{green}different\end{green} \begin{blue}colors\end{blue},

and how to \href{http://www.google.com}{link to URLs with snapshot preview}

and how to \hrefnosnap{http://www.google.com}{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\more

Anything between the conditional declarations {\em ifblog . . . fi}

is ignored by LaTeX and processed by latex2wp. Anything

between {\em iftex . . . fi} is processed by LaTex and ignored

by latex2wp.

\ifblog \begin{green}This green sentence appears only in WordPress \end{green} \fi

\iftex \begin{red}This red sentence appears only in the LaTeX preview \end{red} \fi

This is useful if one, in desperation, wants to put pure HTML commands

in the {\em ifblog . . . fi} scope.

\begin{lemma}[Main] \label{lm:main}

Let $\cal F$ be a total ramification of a compactifier, then

\begin{equation} \label{eq:lemma} \forall g \in {\cal F}. g^2 = \eta \end{equation}

\end{lemma}

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.

\begin{theorem} \label{th:ad} The ad\`ele of a number field is never

hyperbolically transfinite.

\end{theorem}

\begin{proof} Left as an exercise. \end{proof}

\begin{exercise} Find a counterexample to Theorem \ref{th:ad}.

\end{exercise}

\begin{exercise}[Advanced] Prove Lemma \ref{lm:main}. \end{exercise}

Note that accented characters are allowed. Unfortunately,

Erd\H os’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\aa stad, Szemer\’edi,

\v{C}ech, and so on.

It is possible to have numbered equations

\begin{equation} \label{eq:test} \frac 1 {x^2} \ge 0 \end{equation}

and unnumbered equations

$$ t(x) – \frac 12 > x^{\frac 13} $$

Unnumbered equations can be created with the double-dollar sign

command or with the backslash-square bracket command.

\[ f(x) = \int_{-\infty}^{x} \frac 1 {t^2} dt \]

It is possible to refer to equations and

theorems via the {\em ref}, {\em eqref} and {\em label} LaTeX

commands, for example to Equation (\ref{eq:test}),

to Equation \eqref{eq:lemma},

and to Lemma \ref{lm:main} above.

eqnarray* is supported, but not eqnarray:

\begin{eqnarray*}

f(x) & < & x^2 – y^2\\

& = & (x+y) \cdot (x-y)

\end{eqnarray*}

{\em You {\bf can} nest a {\bf bold} text inside an emphasized

text or viceversa.}

The theorem-like environments {\em theorem}, {\em lemma},

{\em proposition}, {\em remark}, {\em corollary}, {\em example}

and {\em exercise} are defined, as is the {\em proof} environment.

The LaTex commands to type \$, \%, and \&\ are supported outside

math mode, and \%\ and \&\ are supported in math mode as well:

\[ 30 \& 10 \% \]

The section symbol \S\ is also supported.

WordPress has trouble if a LaTeX expression containing a $<$

symbol, such as $x^2 $ symbol, such as $(x+y)^2 > (x+y)^2 – 3$. This

is fixed by converting the inequality symbols into “HTML

character codes.” Always write the symbols $$ 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

\begin{btabular}{lr}

blog & quality\\

what’s new & excellent\\

in theory & poor

\end{btabular}

and without borders as in

\begin{tabular}{ccc}

$a$ & $\rightarrow$ & $b$\\

$\downarrow$ & & $\uparrow$\\

$c$ & $\rightarrow$ & $d$

\end{tabular}

(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.

\image{width = 400}{http://imgs.xkcd.com/comics/donald_knuth.png}{knuth.png}

The {\em 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 {\em 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 \ref{sec} below.

HTML does not have good support for itemized list with

descriptors (what one gets in LaTeX using the {\em itemize} environment

with optional parameters in square brackets after the {\em item} commands).

We can only offer the following rather ugly rendering:

\begin{itemize}

\item [Case a.] Description of case a

\item [Case b.] Description of case b

\end{itemize}

\section*{Examples of Sections}

\subsection*{And Subsections}

\section{A section}

\label{sec}

\subsection{And a subsection}

\section{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 $M$ 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 $M$ 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:

\[ \E_{x \in X} f(x) := \sum_{x\in X} \P [x] \cdot f(x) \]

Some more macros (see the LaTeX source)

\[ \B, \R , \C, \Z, \N , \Q, \eps \]

\end{document}

August 14, 2013 at 12:20 am

LaTeX and WordPress.com | Thiago G. Martins[…] can download LaTeX2WP following these instructions. Once you have a .tex document with latex features compatible with LaTeX2WP (see below) you just […]

December 5, 2013 at 7:52 am

osukenakaharaTo answer the posts by Vivek and hugo, I think all you need to do is to replace the division operator “/” on line 140 and 153 with the integer division operator “//”. To understand why, see

http://www.daniweb.com/software-development/python/threads/450103/float-object-cannot-be-interpreted-as-an-integer

Thank you, Luca, for writing this program.

March 22, 2014 at 11:33 pm

mathtuition88thanks for writing this program!

however, I am getting a similar error as Vivek above.

I tried with the example.tex given in the zip.

Traceback (most recent call last):

File “c:\python31\l2wp\latex2wp.py”, line 657, in

s=extractbody(s)

File “c:\python31\l2wp\latex2wp.py”, line 140, in extractbody

for i in range(1,(len(L)+1)/2) :

TypeError: ‘float’ object cannot be interpreted as an integer