Latex for WordPress

I’ve just installed ‘Jetpack‘ which comes with \LaTeX. This post is to provide a quick reference. \LaTeX parses the text in the WordPress post, and lays out the display as a graphic for the viewer. Though someone reading this will see images, there are no images referred to in the edited post.

\LaTeX is a generalised document layout language, but as far as I am concerned, the main use of \LaTeX in WordPress is mathematical.

Note that as the images are generated on the fly, the page will be slower to load than if the page were pre-rendered. Therefore, I think it may still be best for the web to generate the image, save it and then display the result via an <img> tag (keeping the \LaTeX hidden in a comment so that the image can be regenerated if need be). As already mentioned, I have not pre-generated the images for this post, it is all done in code.

It’s a pity that MathML isn’t well supported at the moment.

According to the wordpress codex, one uses this format to include \LaTeX code:

$latex your-latex-code-here$

Some of the basic examples were been taken from the wordpress codex page, others I’ve created. The references from Andy Roberts were very helpful (though he didn’t talk about integration as far as I could see). His reference of symbols is quite handy

The code \LaTeX will show a properly formatted \LaTeX string, and adding &s=X (where X is a number from -4 to 4 will change the size).

$latex \LaTeX&s=X$

$latex \LaTeX&s=-4$
\LaTeX
$latex \LaTeX&s=4$
\LaTeX

There are a lot of symbols which I can use, e.g. + – ! = / () [] <> and a few others. For other symbols such as Greek letters, arrows, boolean algebra there are commands to issue. Thus the instruction $latex v=f\lambda$ gives v=f\lambda

To create a fraction, the \frac command is used. This as the format \frac{numerator}{denominator}

$latex
\frac{1}{1+z}&s=4
$
\frac{1}{1+z}

Commands can be nested:

$latex
\frac{
\frac{(z+1)^2}{z+2}-1
}{1+z}&s=4
$
\frac{  \frac{(z+1)^2}{z+2}-1  }{1+z}

It’d be nice to have some brackets here:

$latex
\frac{
(\frac{(z+1)^2}{z+2})-1
}{1+z}&s=4
$
\frac{  (\frac{(z+1)^2}{z+2})-1  }{1+z}

However, those new brackets are a little weedy, let’s make them bigger:

$latex
\frac{
\left(\frac{(z+1)^2}{z+2}\right)-1
}{1+z}&s=4
$
\frac{  \left(\frac{(z+1)^2}{z+2}\right)-1  }{1+z}

By adding \left and \right in front of the bracket symbols, I am telling \LaTeX to automatically resize the brackets to fit whatever is inside.

Powers can be easily done with the expected ^, and curly brackets are again used to group things, note the space after \pi

$latex
e^{\pi i}+1=0&s=4
$
e^{\pi i}+1=0

Let’s try something a little more tricky

$latex
\psi(t)=Ae^{i(\omega t-kx)}&s=4
$
\psi(t)=Ae^{i(\omega t-kx)}

Matrices can be typeset with the array command:

$latex
\left[
\begin{array}{ c c c }
1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & 1
\end{array} \right]
$
\left[  \begin{array}{ c c c }  1 & 0 & 0 \\  0 & -1 & 0 \\  0 & 0 & 1  \end{array} \right]

… or how about this piece of mathematical poetry

$latex
cos\left(\frac{3\pi}{9}\right)
\int^{\sqrt[3]{3}}_1 t^2 \, dt
= ln \sqrt[3]{e}&s=4
$
cos\left(\frac{3\pi}{9}\right)  \int^{\sqrt[3]{3}}_1 t^2 \, dt   = ln \sqrt[3]{e}

I hope that someone stumbling on this page found it useful, and they weren’t searching for other types of \LaTeX….

About Murk

I'm interested in a range of things, from science and computers, to history and creative stuff. I'm leaving a lot out. My problem is time. As a result, murky.org, flits around from topic to topic as my interest is piqued. It's all tagged though - so it should be easy to find other posts of mine on similar topics - do give the RSS feed a try, and I welcome, nay, I crave comments on articles.

5 thoughts on “Latex for WordPress

  1. hai sir Murk..

    how you write all the above example code before the equation.

    example:
    $ latex
    \frac{1}{1+z}&s=4
    $
    nik

  2. Insert HTML between the $ and the latex

    e.g. <strong>$</strong><strong>latex code here $</strong>

    It could be any HTML, e.g. &nbsp;

Comments are closed.