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

Using LaTeX in WordPress


Saturday 5th March 2005

Filed under: — Steve @ 11:56 pm

Chemists do make use of \LaTeX but they have different typesetting conventions from mathematicians. For example the chemical \cf{H2O} is quite different from the mathematical H_2O . Martin Hensel’s mhchem package allows the easy typing of chemical symbols. Here are some examples taken from mhchem’s documentation. Needless to say, not being a chemist, they don’t mean much to me 🙂

Hover over, or click on a formula, to see the underlying latex code.






\ce{SO4^2- + Ba^2+ -> BaSO4 v}

<=>[\ce{+ 2OH-}][\ce{+ 2H+}]
{\underset{\text{amphoteres Hydroxid}}{\ce{Zn(OH)2 v}}} %group!
<=>[\ce{+ 2OH-}][\ce{+ 2H+}]
{\underset{\text{Hydroxozikat}}{\cf{[Zn(OH)4]^2-}}}% group!

\ce{{{x\,}} Na(NH4)HPO4 ->[\Delta]
(NaPO3)_{{x}} + {{x\,}} NH3 ^ + {{x\,}} H2O}

Improved Output

Saturday 22nd January 2005

Filed under: — Steve @ 11:09 pm

Benjamin Schwartz has adapted class.latexrender.php to improve the quality of the output. He has used “the PNG format’s support for true alpha blending to make those jagged edges (on non-white background) disappear”. The text colour for both PNG and GIF are customizable as is the background colour for GIFs. The original settings are still available.

You can download the file here and view its effect at Digital Diary of Ben Schwartz. The enhancement works best on dark backgrounds so, if you are using Firefox or Opera then try switching the stylesheet to ‘Dark Fire’ on that page.

Some things to be aware of:

  • the improved output may have a small speed penalty
  • the system will only work with recent versions of ImageMagick (such as 6.1.2)
  • Internet Explorer on Windows does not show PNGs as transparent

Path Problems in Linux

Friday 14th January 2005

Filed under: — Steve @ 3:32 pm

If you can’t get LatexRender to work then comment out the 6 unlink lines in class.latexrender.php with // so that they look like this:
// unlink($this->_tmp_dir."/".$this->_tmp_filename.".tex");
// unlink($this->_tmp_dir."/".$this->_tmp_filename.".aux");
// unlink($this->_tmp_dir."/".$this->_tmp_filename.".log");
// unlink($this->_tmp_dir."/".$this->_tmp_filename.".dvi");
// unlink($this->_tmp_dir."/".$this->_tmp_filename.".ps");
// unlink($this->_tmp_dir."/".$this->_tmp_filename.".".$this->_image_format);

Then look in the /tmp folder you have created and see what files have been created. If there’s a .ps file but no .gif or .png file then it may be because ImageMagick can’t find Ghostscript as detailed in Latexrender for WordPress under Mac OS X.

This is because in Linux, Imagemagick expects to find the gs file (Ghostscript’s binary) in /usr/bin. In fact, it may be in /usr/local/bin or somewhere else. You can either
1. reinstall Ghostscript into /usr/bin
2. change the path in Imagemagick’s file to tell it where to look. The file you want is delegates.mgk and might be found in /usr/share/ImageMagick, though this can vary. In this text file just alter /usr/bin/gs to the correct path – there may be 8 of these to change.
3. This is probably the simplest method. Make a symbolic link from /usr/bin/gs to /usr/local/bin/gs or wherever gs resides. How do I create a symbolic link?
4. See Marcin Gomulka’s comment below. This is great if you don’t have access to the server

Please let me know if this works for your installation.


Sunday 2nd January 2005

Filed under: — Steve @ 4:06 pm

Alex Gittens has released IllustRender to aid in drawing illustrations in WordPress
IllustRender is a plugin for WordPress, heavily based on LatexRender, which replaces illustration code in your posts with the actual illustration.

The LATEX Graphics Companion is the reference book to consult for such graphics. A couple of examples, rendered by IllustRender, are:

[illust]draw (0, 50)..(0,0)..(60,40)..(60,10)..cycle;[/illust] [illust]picture p; path q;
p := thelabel(btex \Large
\iint\limits_A f(x,y)\,dx\,dy\qquad
\iiint\limits_A f(x,y,z)\,dx\,dy\,dz\
\iiiint\limits_A f(w,x,y,z)\,dw\,dx\,dy\,dz
\qquad\idotsint\limits_A f(x_1,\dots,x_k)
q := fullcircle scaled 2.5in;
fill q withcolor black;
clip p to q;
draw p rotated (90) withcolor white;[/illust]

Commutative Diagrams

Wednesday 29th December 2004

Filed under: — Steve @ 5:10 pm

These diagrams are drawn by Michael Barr’s diagxy package and are taken from the manual:
\square/>>`>`>` >->/[A`B`C`D;e`f`g`m]


A\twoleft B\twoleft^f C\twoleft_g D\twoleft^h_{{\rm Hom}(X,Y)} E


\cube|arlb|/ >->` >->`>`>/&lt;1000,1000>[A`B`C`D;f`g`h`k]%

More \LaTeX Graphics

Sunday 28th November 2004

Filed under: — Steve @ 6:42 pm

These graphics were taken from LaTeX Graphics

Triangle with circumscribed, inscribed, adjacent and Feuerbach circles

\begin{pspicture}*(420, 420)
  % Frame
  \pspolygon(0, 0)(420, 0)(420, 420)(0, 420)
  % Circumscribed circle and inscribed circle
  \pscircle[linecolor=blue](206, 222){166.18}
  \pscircle[linecolor=yellow](250, 197){75.42}
  % Adjacent circles
  \pscircle[linestyle=dashed, linecolor=green](476, 135){157.68}
  \pscircle[linestyle=dashed, linecolor=green](-32, -22){266.53}
  \pscircle[linestyle=dashed, linecolor=green](132, 579){315.92}
  % triangle
  \pspolygon(43, 253)(361, 283)(287, 77)
  % nine-points circle (Feuerbach)
  \pscircle[linestyle=dotted, linecolor=red](242, 195){83.09}


Plotting Graphs

Tuesday 31st August 2004

Filed under: — Steve @ 10:04 pm

\psplot[plotstyle=curve,linewidth=0.5pt]{-4}{0.9}{10 x exp}% postscript function
\psplot[plotstyle=curve,linecolor=red,linewidth=0.5pt]{-4}{3}{2 x exp}% postscript function
\psplot[plotstyle=curve,linecolor=blue,linewidth=0.5pt]{-4}{2.05}{2.7183 x exp}% postscript function
\rput(-4,-1){\color{white}bounding box\normalcolor}

These graphs are courtesy of PSTricks

LatexRender for the Mac OS X

Filed under: — Steve @ 2:54 pm

Installation of LatexRender using the Mac OS X can be a little tricky. Fortunately, lieven le bruyn has written instructions on how to install it at Latexrender for WordPress under Mac OS X


Monday 30th August 2004

Filed under: — Steve @ 9:22 pm


Thanks to S.O.S. Mathematics CyberBoard for alerting me to the delights of the \LaTeX cancel package

Make LatexRender XHTML-compliant

Saturday 14th August 2004

Filed under: — Steve @ 10:48 pm

You can ensure LatexRender is XHTML-compliant if you make the small changes here (thanks to d)

\mbox{\Huge \pi}

Monday 9th August 2004

Filed under: — Steve @ 7:44 pm

\displaystyle \pi = \sum _{k=0} ^{\infty}  \dfrac{1}{16^k} \left[\dfrac{4}{8k+1}-\dfrac{2}{8k+4}-\dfrac{1}{8k+5}-\dfrac{1}{8k+6}\right]

LatexRender as a plugin

Filed under: — Steve @ 6:02 pm

I have now managed to make LatexRender as a plugin (download files here) which means that it won’t be necessary to edit WordPress files. Before you get too excited this assumes

  1. You are using at least WordPress 1.2 (which uses plugins)
  2. You have the latest files which don’t eat backslashes (detailed on page 2)

If not, you can still use the method in 5th August’s post. Also you will need to put some information about where to find files in the latexrender files.

1. You need to have \LaTeX and ImageMagick installed on your server. If this is not possible, then try mimeTeX (see page 2)

2. latexrender-plugin.php
Ensure that
contains the correct path to where you have put latex.php

3. latex.php
Ensure that
$latexrender_path = "/home/domain_name/public_html/path_to/latexrender";
$latexrender_path_http = "/path_to/latexrender";
contain the correct path to where your latexrender files are to go

4. class.latexrender.php
Ensure that
var $_latex_path = "/usr/bin/latex";
var $_dvips_path = "/usr/bin/dvips";
var $_convert_path = "/usr/bin/convert";
var $_identify_path = "/usr/bin/identify";

point to the right places.

For Windows the paths in class.latexrender.php must use \ or / not just a single \
For example
var $_latex_path = "C:\texmf\miktex\bin\latex.exe";
var $_latex_path = "C:/texmf/miktex/bin/latex.exe";

5. Create a new latexrender folder in your WordPress folder, with sub folders tmp and pictures. These 2 folders must be chmod to 777. Upload latex.php and class.latexrender.php to the latexrender folder

6. If you are happy to let commenters use LaTeX (but beware spammers) then in latexrender-plugin.php remove // from the line:
// add_filter(‘comment_text’, ‘addlatex’);

7. Upload latexrender-plugin.php to WordPress’s plug-in folder (/wp-content/plugins) and activate it in the Plugins menu

\LaTeX should now be enabled! Use [tex ] and [/tex ] (without the space) to surround your maths. There’s a tex button to do this for you.


Sunday 8th August 2004

Filed under: — Steve @ 11:54 pm

Now that the backslash eating problem is being resolved, I am hoping to produce a plugin which avoids editing WordPress files. Watch this space \displaystyle \int_{-\infty }^{\infty }e^{-x^{2}}\;dx=\sqrt{\pi }

Using LaTeX in WordPress

Thursday 5th August 2004

Filed under: — Steve @ 6:59 pm

This is how you can use LatexRender in WordPress. Assuming you have \LaTeX and Imagemagick setup on your server and have downloaded then:
1. In the download folder, otherPHP/latexrender you just need the 2 files
latex.php and class.latexrender.php
a) in latex.php ensure that
$latexrender_path = "/home/domain_name/public_html/path_to/latexrender";
contains the correct path to where your latexrender files are to go
$latexrender_path_http = "/latexrender";
so it says
$latexrender_path_http = "/path_to/latexrender";


I’m testing

Filed under: — Steve @ 12:15 pm

I’m testing the \sqrt{2} and \dfrac{1}{2}


Wednesday 4th August 2004

Filed under: — Steve @ 7:27 pm

\displaystyle \int_{0}^{1}\frac{x^{4}\left( 1-x\right) ^{4}}{1+x^{2}}dx=\frac{22}{7}-\pi

\kappa =\dfrac{d\psi }{ds}=\dfrac{\dfrac{d^{2}y}{dx^{2}}}{\left( 1+\left( \dfrac{dy}{dx}\right) ^{2}\right) ^{\frac{3}{2}}}=\dfrac{\overset{.}{x}\overset{..}{y}-\overset{..}{x}\overset{.}{y}}{\left( \overset{.}{x}^{2}+\overset{.}{y}^{2}\right) ^{\frac{3}{2}}}

« Previous Page

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