For writing mathematics in WordPress using LaTeX I have been using Pavel Holoborodko’s nice QuickLaTeX plugin. It makes it very easy to convert offline LaTeX source code, possibly including custom macros, into (part of) a WordPress post. To reduce the effort a bit further, I wrote a tiny Python 3 script.

#!/usr/bin/env python

# ---------------------------------------------------------------------
# tex2quick - A LaTeX to QuickLaTeX converter
# Copyright (C) 2017  Sebastiaan G. Janssens (

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <>.
# ---------------------------------------------------------------------

# This module is the interface to the Python regular expression engine.
# See for a tutorial.
import re

# This module is used to pass command line arguments.
# See
import argparse

# Parse input file name from command line.
parser = argparse.ArgumentParser()
parser.add_argument('infile', help='Convert LaTeX to QuickLaTeX for WordPress')
args = parser.parse_args()

f = open(args.infile, 'r')
latex =

# Discard preamble and title and select main text to work on.
p = re.compile(r'\\maketitle(.*)\\end{document}', re.S)
m =
text =

# Each tuple consists of a pattern and a replacement. Add as needed.
subs = [(re.compile(r'\\section\*?{(.*?)}'), r'<h3>\1</h3>'),
        (re.compile(r'\\subsection\*?{(.*?)}'), r'<h4>\1</h4>'),
        (re.compile(r'\\medskip'), r'<p></p>'),
        # Item listing enviroments
        (re.compile(r'\\begin{itemize}(.*)\\end{itemize}', re.S), r'<ul>\1</ul>'),
        (re.compile(r'\\item(.*)'), r'<li><p>\1</p></li>'),
        # Text formatting
        (re.compile(r'\\textit{(.*?)}'), r'<em>\1</em>'),
        (re.compile(r'\\emph{(.*?)}'), r'<em>\1</em>'),
        # Letters with accents
        (re.compile(r'\\`([aeiou])'), r'&\1grave;'),
        (re.compile(r'\\\'([aeiou])'), r'&\1acute;'),
        # Remove commented lines
        (re.compile(r'^%.*$', re.M), r'')]

for p, r in subs:
    text = p.sub(r, text)

# Pipe to xclip to get the output directly on the X11 clipboard.

As you can see, searching and replacement is done using Python’s regular expression module. For those replacements that work on just a single line of input, it would probably be more efficient to first break the input string into lines and then process them sequentially, but clearly efficiency is not really an issue here.

In order to use the script, store the above code into a file, say

that can be found in your path and give it executable permissions. Then run as

$ foo.tex | xclip

In this example the output is piped into the xclip utility, so afterwards you can just paste the contents of your clipboard into the WordPress editor. On systems without X11 (e.g. MS Windows) you should probably redirect standard output to an intermediate file.