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

Using LaTeX in WordPress

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.

6 Comments »

RSS feed for comments on this post. TrackBack URI

  1. The directory where ‘gs’ is, needs to be in the $PATH for convert to work correctly.

    I have wordpress installed on an university server and they
    put ghostscript in an unusual directory.

    The following workaround adds the additional directory into the PATH variable:

    // class.latexrender.php

    // begin of workaround
    // extending the PATH environmental variable
    $oldpath = getenv(“PATH”);
    $where_gs_is = “/usr/sfw/bin”;
    if ($oldpath) { $where_gs_is .= “:$oldpath”;}
    putenv(“PATH=$where_gs_is”);
    // end of workaround

    // 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;
    $status_code = exec($command);

    Comment by MarcinGomulka — Sunday 31st July 2005 12:29 pm #

  2. I was getting the same symptoms and I discovered it was because my convert doesn’t support the -trim option. I was able to get it to work by replacing “-trim” with “-crop 0×0″ in the line defining $command.

    Comment by Matthew Leingang — Tuesday 20th September 2005 12:37 pm #

  3. [...] following this advice. [...]

    Pingback by simon jackman’s blog » Math in Blogs via LatexRender — Saturday 24th March 2007 6:25 am #

  4. I was having some path problems that I think had to do with symbolic links on the server confusing the automated script, but what I wanted to mention here (because I can’t find anywhere better) is that once it was ‘working’ the images were filled with garbled text that I eventually discovered quite by accident were the result of \f’s needing to be \\f’s, as the \n’s are \\n’s, presumably because of some kind of end-of-line filtering or whatever, in WordPress 2.6. Basically, from lines 197-224 of class.latexrender.php I had to replace every \f with \\f and now it works fine!

    Comment by rec — Thursday 11th September 2008 2:32 am #

  5. \f is a new escape character in versions 5.2.5 or later of PHP. The replacement by \\f is thus only required for these versions of PHP; \f also only occurs in the offset beta version of latexrender.

    Comment by Steve — Thursday 11th September 2008 8:26 pm #

  6. An alternative method of ensuring \f is not misinterpreted is to use single quotes. Full details at LaTex in WordPress with PHP5.x

    Comment by Steve — Tuesday 7th October 2008 7:08 pm #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


 

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