This site is a showcase for using LatexRender for mathematics in WordPress

Using LaTeX in WordPress

Odd effects

Thursday 21st July 2005

Filed under: — Steve @ 10:33 am

WordPress is very flexible allowing you to choose various text filters. Unfortunately they can filter the mathematical text as well before it gets converted to an image. The most common effect you see is in matrices (or arrays, tables) where you get

    \begin{pmatrix}
a & 038;b & 038;c & 038;d & 038;e \\
x & 038;\hdotsfor{3} & 038;z
\end{pmatrix}

instead of

    \begin{pmatrix}
a & b & c & d & e \\
x & \hdotsfor{3} & z
\end{pmatrix}

This is because the ampersand has been converted to the equivalent HTML code.

You can solve this problem by changing one line in latex.php. In
// $latex_formula = str_replace("& #38;","&",$latex_formula);
remove the comment // and change 38 to 038 so that the line reads
$latex_formula = str_replace("& #038;","&",$latex_formula);
Please note: In order to show the code here I have had to introduce a space between & and #. That space should not be there in latex.php

Other odd effects can be dealt with similarly.
If you see a8217; instead of a’ then either
1. use ^\prime in your LaTeX code and/or
2. add the line (removing the space between & and #)
$latex_formula = str_replace("& #8217;","'",$latex_formula);
in the same place as the previous one in latex.php

Both alterations appear in the latest download.

Note: If you want to regenerate older images then you will either have to remove them from the cache or change the code slightly eg by putting in an extra space which \LaTeX will ignore


 

This site is a showcase for using LatexRender for mathematics in WordPress