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

Using LaTeX in WordPress

Installing \LaTeX on a hosted site

Friday 27th June 2008

Filed under: — Steve @ 11:08 am

Many \LaTeX users have no root access to the server running their web site, which makes it difficult to install \LaTeX, unless their hosts can be persuaded to do so. However, if you have shell access to your account you may be able to install \LaTeX in your home directory. Instructions are at Installing LaTeX on Web Hosts (32 bit Linux) and Installing latex on HostMonster (64 bit Linux).

CodeCogs Equation Editor

Monday 11th February 2008

Filed under: — Steve @ 11:35 am

LaTeX Equation Editor is an innovative editor with a symbol table for those who are not sure of the LaTeX code as well as allowing the code to be typed directly. It uses Ajax so that the page does not need to be refreshed to see the rendered image.

This equation editor can be used in a number of ways:

    1. Create the equation and then copy and paste the image into your website;
    2. Fetch the code directly from CodeCogs site and use in your website like this
    <img src="http://www.codecogs.com/eq.latex?\tiny \int_{-\infty }^{\infty }e^{-x^{2}}\;dx=\sqrt{\pi }" /> which gives

    3. Incorporate the visual editor into your text box (for example in a forum such as phpBB) or the FCK Editor;
    4. Install the complete system on your server.

Method 1 does not require any code, method 2 only requres a small amount of HTML and is particularly suitable for example for Blogger. Method 3 needs some PHP code on your site and method 4 requires LaTeX and other software to be installed on your server. Full instructions are provided at Installing the CodeCogs Equation Editor v2

Please note that if you use method 3 you should display the following banner on your page CodeCogs - An Open Source Numerical Library and if you use methods 2 or 3 then do please contact CodeCogs first at CodeCogs Services.
Do let CodeCogs know of any customisations or innovative uses that you make of their equation editor.

mathTeX helper

Monday 14th January 2008

Filed under: — Steve @ 5:49 pm

As mentioned in Online LaTeX mathTeX lets you incorporate high-quality LaTeX images in an web page using an image tag so
<img src="http://www.forkosh.dreamhost.com/mathtex.cgi?c=\sqrt{a^2+b^2}" />
becomes which may be placed slightly too high on the line.

This is very simple to do but rememerbing exactly what to type can be a problem, particularly in sites like Blogger. So I have written a tool which

  • allows you to test LaTeX code first
  • creates the image code (or URL with a link if you prefer) automatically for you
  • adds title attributes so that hovering a mouse over the image shows the code
  • ensures that the image’s vertical spacing is improved

This makes it simple to produce c=\sqrt{a^2+b^2} whose code is
<img src="http://www.forkosh.dreamhost.com/mathtex.cgi?c=\sqrt{a^2+b^2}" title="c=\sqrt{a^2+b^2}" alt="c=\sqrt{a^2+b^2}" style="vertical-align:-2pt;" />

Download mathTeX helper which runs on your own computer and uses JavaScript.

LaTeX Web Hosting

Tuesday 23rd October 2007

Filed under: — Steve @ 9:48 am

It is quite difficult to find web hosts who are willing to install LaTeX, so it’s good to read one person’s experience of trying to find a shared host offering LaTeX. (Shared) hosting with LaTeX - An overview gives 7 hosts who gave a positive response.

Update
Following on from Mike Renfro’s comment below recommending A2 Hosting I contacted them to ask about their LaTeX hosting and this is their reply:

“Yes, we either have or can install the LaTeX packages upon request on any particular server. It’s not a problem as long as it does not become a server load issue. We are currently using the CentOS 5 latex package tetex-latex-3.0-33.1.el5 but if anybody wishes to install their own copy of LaTeX locally on their account they can always get the appropriate binary and do that also if they need a different version.

We would certainly be happy to have you point folks in our direction. We will go ahead and add a knowledge base article on the subject as well.”

Online LaTeX 2

Monday 4th June 2007

Filed under: — Steve @ 5:26 pm

As mentioned in the previous post mimeTeX parses a LaTeX maths expression and immediately emits the corresponding gif image. All you need do is write <img src="http://www.forkosh.dreamhost.com/mimetex.cgi?c=\sqrt{a^2+b^2}" /> and you get the mathematical formula. It’s beautifully simple.

Following a suggestion by John Forkosh, the author of mimeTeX, I would like to do the same for LatexRender to help those who don’t have access to a LaTeX enabled server. I am looking for volunteers who are willing to host LatexRender on a publically available server, accessed in a similar manner to mimeTeX’s server. I doubt that it would need huge bandwidth but it does need a commitment to be available for use.

Do let me know if you are interested and can offer such a service.

Online LaTeX

Tuesday 24th April 2007

Filed under: — Steve @ 11:38 am

Unfortunately not every host offers LaTeX but there are sites that can help generate the images that can be downloaded.

Complete LaTeX documents can also be compiled online. Here are a few sites I have come across:

  • LaTeX-Online-Compiler will compile LaTeX documents to postscript, PDF or DVI formats and will generate references. There’s a German language version of the page.
  • ScienceSoft.at can compile a document to various image formats as well as PDF. The resolution can be adjusted and there are a number of templates. There’s a Flash applet version. Again there’s a German language version.
  • LaTeX to PDF uses MiKTeX to convert LaTeX documents to PDF and allows uploading of classes, style files and images.
  • TeX on Web converts LaTeX and plain TeX documents to Postscript and PDF. It has Czech language support. The instructions are in Czech but the site is still easy to use by non-Czech speakers.

WordPress.com offers free hosted blogs with \LaTeX facilities similar to LatexRender. See Can I put Math or Equations in my Posts? for details.

Please let me know about similar sites that are worth including here.

Asymptote Support

Sunday 8th April 2007

Filed under: — Steve @ 10:52 pm

Asymptote is a vector graphics language which creates mathematical diagrams and figures and is designed to be used with LaTeX. Hui Chen has adapted LatexRender code to produce an Asymptote plugin for WordPress.

Image Transparency Bug

Saturday 17th March 2007

Filed under: — Steve @ 4:14 pm

Some versions of ImageMagick fail to process the transparency command properly. If you find that this is causing problems for you then in class.latexrender.php remove the transparency command

-transparent "#FFFFFF"

so

// imagemagick convert ps to image and trim picture
$command = $this->_convert_path." -density ".$this->_formula_density." -trim -transparent "#FFFFFF" ".$this->_tmp_filename.".ps ".$this->_tmp_filename.".".$this->_image_format;

becomes

// imagemagick convert ps to image and trim picture
$command = $this->_convert_path." -density ".$this->_formula_density." -trim ".$this->_tmp_filename.".ps ".$this->_tmp_filename.".".$this->_image_format;

Thanks to Kevin Knuth for pointing out this workaround.

Automated Script for LatexRender

Saturday 20th January 2007

Filed under: — Steve @ 9:00 pm

Gunnlaugur Þór Briem has written a bash script which simplifies the installation of the LatexRender plugin for WordPress. It means that you shouldn’t have to worry about those pesky paths which are so easy to trip over. You will find the instructions and script at LaTeX in WordPress.

Vertical Alignment of Images

Friday 22nd September 2006

Filed under: — Steve @ 3:34 pm

The wp-latexrender.zip download now includes an optional offset beta directory. These contain files that implement Mike Boyle’s Inline Offset improvement to the vertical alignment of images. Users may wish to experiment with this and details of the code changes are given in the offset beta/readme_offset.txt file.

WordPress 2

Wednesday 4th January 2006

Filed under: — Steve @ 5:28 pm

I have tested LatexRender in WordPress 2 and it works fine.

If you use the default visual rich editor (it can be turned off in Your Profile) when posting you won’t see a tex button but that would also be true for all the other WYSIWYG editors you can use.

See Plugin Compatibility for a list of plugins that work with WordPress 2.

Mac Tiger

Monday 5th September 2005

Filed under: — Steve @ 5:48 pm

If you wish to install LatexRender for Wordpress on the Mac Tiger operating system, then you will find NeverEndingBooks instructions very helpful.

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

Using cosec

Saturday 2nd April 2005

Filed under: — Steve @ 10:49 pm

British (and who else?)1 prefer to use \cosec x for \frac{1}{\sin x} but \LaTeX doesn’t recognise \cosec as a command. You could use \mathrm{cosec} which produces \mathrm{cosec} or even use Babel, but a very simple method would be to add a line in class.latexrender.php Just after
$string .= "\begin{document}\n";
add the line
$string .= "\newcommand{\cosec}{\operatorname{cosec}}\n";
and then you’ll be able to use \cosec wherever you want eg \cosec^2x=1+\cot^2x

You can find a whole lot more newcommands at Birmingham (UK) University Maths Postgrad Committee’s Latex Commands page

1. Russian Babel has the \cosec command; so who else uses cosec rather than csc?

Chemistry

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 :smile:

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

\cf{(NH4)2S}

\cf{^{227}_{90}Th+}

\cf{Fe`{III}[Fe`{III}Fe`{II}(CN)6]3}

\cf{2H+,{(aq)}}

\cf{[Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2}

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

\ce{Zn^2+
<=>[\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
or
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.
or
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?
or
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.

IllustRender

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:

draw (0, 50)..(0,0)..(60,40)..(60,10)..cycle;

[Unparseable, unsupported, or potentially dangerous illustration code. Error 5 : 1020x8]

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:
\bfig
\square/>>`>`>` >->/[A`B`C`D;e`f`g`m]
 \morphism(500,500)|m|/.>/&lt;-500,-500>[B`C;h]
 \efig

\bfig
 \Vtrianglepair[A`B`C`D;f`g`h`k`l]
 \efig

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

\bfig
 \place(0,0)[\twoar(1,0)]
 \place(200,0)[\twoar(0,1)]
 \place(400,0)[\twoar(1,1)]
 \place(600,0)[\twoar(0,-1)]
 \place(800,0)[\twoar(1,2)]
 \place(1000,0)[\twoar(1,3)]
 \place(1200,0)[\twoar(1,-3)]
 \place(1400,0)[\twoar(-3,1)]
 \place(1600,0)[\twoar(-1,-3)]
 \place(1800,0)[\twoar(255,77)]
 \efig

\bfig
\cube|arlb|/ >->` >->`>`>/&lt;1000,1000>[A`B`C`D;f`g`h`k]%
(400,400)|arlb|/>`>`>`>/&lt;900,900>[A^{\prime}`B^{\prime}`C^{\prime}`D^{\prime};f^{\prime}`g^{\prime}`h^{\prime}`k^{\prime}]%
 |rrrr|/&lt;-`&lt;-`&lt;-`&lt;-/[\alpha`\beta`\gamma`\delta]
 \efig

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

\psset{unit=.25pt}
\begin{pspicture}*(420, 420)
  \psset{linewidth=.4pt}
  % 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
  \psset{linewidth=1pt}
  \pspolygon(43, 253)(361, 283)(287, 77)
  % nine-points circle (Feuerbach)
  \pscircle[linestyle=dotted, linecolor=red](242, 195){83.09}
\end{pspicture}

(more…)

Plotting Graphs

Tuesday 31st August 2004

Filed under: — Steve @ 10:04 pm

\psset{unit=0.5cm}
\begin{pspicture}(-4,-0.5)(4,8)
\psgrid[subgriddiv=0,griddots=5,gridlabels=7pt](-4,-0.5)(4,8)
\psline[linewidth=1pt]{->}(-4,0)(+4,0)
\psline[linewidth=1pt]{->}(0,-0.5)(0,8)
\psplot[plotstyle=curve,linewidth=0.5pt]{-4}{0.9}{10 x exp}% postscript function
\rput[l](1,7.5){$10^x$}
\psplot[plotstyle=curve,linecolor=red,linewidth=0.5pt]{-4}{3}{2 x exp}% postscript function
\rput[l](2.2,7.5){\color{blue}$e^x$}
\psplot[plotstyle=curve,linecolor=blue,linewidth=0.5pt]{-4}{2.05}{2.7183 x exp}% postscript function
\rput[l](3.2,7.5){\color{red}$2^x$}
\rput(4,8.5){\color{white}change\normalcolor}
\rput(-4,-1){\color{white}bounding box\normalcolor}
\end{pspicture}

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

Cancelling

Monday 30th August 2004

Filed under: — Steve @ 9:22 pm

\displaystyle
\frac{32}{64}
=\frac{2\times4\times4}{4\times4\times4}
=\frac{\cancelto{1}{2}\times\cancel{4}\times\cancel{4}}{\cancelto{2}{4}\times\cancel{4}\times\cancel{4}}
=\frac{1}{2}

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]


Next Page »
 

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