Skip to content →

Tag: latexrender

latexrender plugin for wordpress under tiger

Promises and pie-crusts are made to be broken, a wiser man once
said. Still, promises have a much longer life-span and sometimes their
real content becomes redundant over time.

A year ago, I
promised
to document how I got the
LaTeXRender Plugin for WordPress
working under OS X. The procedure
consisted of some trial-and-error operations, installing non-standard
versions of software and hardcoding certain directories throughout
certain files…

Not something I was looking forward
to when I decided to upgrade this WordPress blog but,
surprisingly, things went pretty smoothly this time (Mac-technology
has improved a lot). So, please don’t worry too much about this
post
and follow the (late) instructions below.

First
things first : I will assume you have the ‘generic’ LaTeX
running under Tiger (10.4),that is, use the i-Installer to download BOTH
LaTeX and Imagemagick! Further, in order to get WordPress up and
running, have the standard
MySQL 4.0 package
installed for 10.3 (not version
4.1…) and don’t use the generic Mac-PHP version, but
instead download Marc
Liyanage’s PHP5 package
which has plenty of additional
packages installed (notably, GDlib and MCRYPT which comes in handy if
you want to fight spam-comments using BotCheck).

\r
\n

Download wp-
latexrender.zip
and follow the instructions given to the letter
(there is one undocumented extra directory you have to fill in at the
start of the latexrender-plugin.php file). There is
just one additional thing to do. Find in the
class.latexrender.php file the line starting
with

// convert dvi file to postscript using
  dvips

and include the following lines just before it
:

// begin of workaround // extending the PATH
  environmental variable Soldpath =
  getenv(“PATH”); Swhere_imagemagick_is =
  “/usr/local/bin”; if (Soldpath) { Swhere_imagemagick_is .=
  “:Soldpath”;} putenv(“PATH=Swhere_imagemagick_is”); //
  end of workaround 

activate the plugin and it
should work! Still, there are three things you may want to change. In
the latex.php file uncomment the indicated lines as
you will be using htmlArea to input your posts. In addition, if you
have the MarkDown-plugin enabled, it is best to append additional
lines such as

 Slatex_formula =
  str_replace(“_”,”_”,Slatex_formula);     Slatex_formula
  =
  str_replace(“_”,”_”,Slatex_formula); 

(
between the first ” ” should be the beginning and end
em-tag respectively) or underscores will be interpreted as em-tags.
If you run into additional similar problems, the procedure is to
comment-out the line

 
  unlink(Sthis->_tmp_dir.”/”.Sthis->_tmp_filename.”.tex”); 
  

near the end of class.latexrender.php , look in the
tmp directory for the TeX-file, detect the problem and add similar
lines to the ones above to solve it. Another useful thing to do
is to add TeX-packages in the class.latexrender.php file. My own
version has the following predefined symbols and loaded
packages

 function wrap_formula(Slatex_formula) { 
  Sstring  =
  “\\documentclass[“.Sthis->_font_size.”pt]{“.Sthis->_latexclass
  .”}\\n”;  Sstring .=
  “\\usepackage[latin1]{inputenc}\\n”;  Sstring .=
  “\\usepackage{amsmath}\\n”;  Sstring .=
  “\\usepackage{amsfonts}\\n”;  Sstring .=
  “\\usepackage{amssymb}\\n”;  Sstring .=
  “\\usepackage{xy}\\n”;  Sstring .=
  “\\xyoption{all}\\n”;  Sstring .=
  “\\\\newcommand{\\vtx}[1]{*+[o][F-]{Scriptscriptstyle
  #1}}\\n”;  Sstring .= “\\\\newcommand{\\mathbb{C}c}{\\Bbbk}\\n”; 
  Sstring .= “\\\\newcommand{\\mathbb{C}}{\\mathbb{C}}\\n”;  Sstring .=
  “\\\\newcommand{\\mathbb{Q}}{\\mathbb{Q}}\\n”;  Sstring .=
  “\\\\newcommand{\\mathbb{Z}}{\\mathbb{Z}}\\n”;  Sstring .=
  “\\\\newcommand{\\mathbb{N}}{\\mathbb{N}}\\n”;  Sstring .=
  “\\\\newcommand{\\mathbf}[1]{{\\\\text{\\em \\usefont{OT1}{cmtt}{m}{n}
  #1}}}\\n”;  Sstring .= “\\pagestyle{empty}\\n”;  Sstring
  .= “\\begin{document}\\n”;  Sstring .=
  “S”.Slatex_formula.”S\\n”;  Sstring .=
  “\\end{document}\\n”;          return Sstring;     }  
  

which, among other things, allow all commenters to add
quiver-pictures using xymatrix and vtx to depict vertices. Oh yes, you
can allow comments to include LaTeX-code by uncommenting the
line

  // add_filter(‘comment_text’,
  ‘addlatex’); 

in the latexrender-plugin.php
file (but before you do make sure you have spam under control, such as
with BotCheck mentioned above). That’s all for now. If you want
to use TeX in a comment, make sure to put the code between tags [ tex
] and [ /tex ] (omitting the extra spaces). If you want me to add
other LaTeX-packages, leave a comment.

Leave a Comment

markLaTeXdown

Clearly,
an extended version of Markdown
including LaTeX-commands would be useful for mathematicians and surely
I’m not the first to think about this. In fact, I found a somewhat
pompous text New adventures
if hifi text
by someone claiming to have done precisely that (though
he doesn’t give much details nor post a version of his altered program).

Still, it is pretty clear how to convert a _Markdown+LaTeX_
textfile to plain LaTeX (at least for regex-lovers
). Modify the _Markdown.pl_ script so that the Markdown markup is
translated not to HTML-tags but to LaTeX-commands.

More
interesting material can be found in a thread on _Markdown and
Mathematics_ starting with this post. In it, they search for a good way to include
LaTeX-mathematical commands in a MarkDown text. In fact, this is part of
a more general quest for a good _escape character_ in Markdown to
create _Markdown plus something_ versions. They opt for
{{ and }} rather than the usual
$ signs.

I think the alternatives [
tex ]
and [ /tex ] are slightly better because
then you could feed the text to a functional WordPress installation with the
LaTeXRender
plugin installed and copy the relevant part from the HTML-source of
the resulting post to get a HTML-version of the mathematical text with
all LaTeX-code converted to pictures. Clearly, typing the suggested tags
is somewhat cumbersome so I would type them using the
{{ and }} proposal (one
{ is not enough because a lot a LaTeX code uses single
curly brackets) and then do a global replace to get the
LaTeXRender-tags.

Even more interesting would be to have a
version of the html2txt.py script for LaTeX, that is,
converting a LaTeX-file to Markdown + LaTeXcode which would give an easy
way to convert your existing papers to HTML if you feed the LaTeXRender
plugin with all the required newcommands and packages.

Leave a Comment

tiger days 1

It
should be really day 2 but yesterday evening I was a bit overoptimistic
and tried to get MySQL, Ruby, Rails & Tracks installed and in the
process totally wrecked my Ruby-system (and probably a few things more).
Besides, I found out that the _Carbon Copy Cloner_ work-around
doesn\’t really work (that is, one canNOT boot from the cloned copy)
etc. etc. In short, a lot of frustration. So today, I started all over
again (using the install notes below to guide me and so I could reduce
the total time to about 2 hrs). But, as this was the easy bit (still to
come : MySQL, PHP, WordPress+LatexRender, Ruby&Tracks etc.) and I
don\’t want to redo everything again when I do something horribly wrong
I changed my overall tactics. I\’ll keep identical copies on my iBook
and on my iMac and do the next batch of installs on just one machine and
check whether everything works before syncing it to the other. If
something gets messed up I resync to the state of the previous day. Just
one question left : what program to use for the backup/restore now that
CCC seems to be broken? Fortunately, there is still PsyncX which still
seems to work fine (at least today…). Below, for what it is worth,
yesterday\’s log of events :

Okay, I checked that I can still
TeX papers and connect to the printer on the iMac (after Archive/Install
to Tiger). Most other things have broken down, such as my mind on tracks
and my MySQL-database, but I\’m quite hopeful I can rebuild them all.
So, time for a drastic _Erase/Install_ on my iBook.

12:04 : One final safety check. Connect the external
HD, select the _Carbon Copy Cloned_ partition as StartUp Disk and
do a Restart to verify that it can be cloned back should everything go
terribly wrong. Seems to work nicely, so change again from StartUp disk,
restart and disconnect the external HD.

12:16
: Printed the macdevcenter install
tips
and made a fresh pot of coffee. Took the unread part of the
newspaper with me, connected Jan\’s iPod, made it the new StartUp disk
and did another Restart.

12:24 : Selected
\’English\’ as the main language. Selected _DiskUtility_ from the
_Utilities_ menu (before you have to select a Disk destination).
Selected the HD, clicked _Erase_ and choose _Erase Free
Space_ first, then choose the SecurityOption to \’zero out data\’.
(Both steps require a lot of extra time but what is the point of doing
an Erase if you don\’t erase properly? Btw. the macdev-article does not
agree with me on this point.) Meanwhile, had some coffee and a
read…

13:23 : Did quit DiskUtility
which brought me back to the Installer. Selected the HD and clicked on
_Options_ to select Erase&Install and clicked Continue. Then
clicked on _Custom Install_ to choose which Packages to Install.
Did choose _all_ Printer Drivers but in _Language
Translations_ only selected : French, German and Dutch. Didn\’t
select X11! Clicked : _Install_ and had yet another cup of
coffee…

13:45 : Restarted! Got me into
the SetupAssistant. Didn\’t choose to transfer info from another Mac. It
selected our wireless network immediately, and asked me for my .Mac
account info. Did create my main account and finished at
13:53 Only had to stop iTunes from wanting to put
PodSoftware onto the connected iPod… Checked for SoftwareUpdate
but there was none. Am connected to internet but had to add my other
mail-account. Done and received email at 14:05 Found
our Printer but did gray out two-sided printing (have to remember later
how I did set this up…).

14:12 : Time
to add the _Xcode Tools_ : opened the folder on the iPod and
clicked on _XcodeTools.mpkg_ . Followed he default installation.
Finished and deconnected the iPod at 14:24 Took a break
to decide how to continue. (21.97Gb available) Update today : do a
custom install using also cross-development!

14:37 : Okay, first things first : get myself a
working TeX-system starting from this page
to get the latest version of TeXShop and the i-Installer and place both
in the Applications folder and in the Dock. Placed the _To Your
Library_ folder of TeXShop in my ~/Library (containing the texmf
etc. path for pdfsync). Then followed this
page
and the i-Installer to install the packages in the right order
:

  • FreeType 2
  • libwmf
  • Ghostscript
    8
  • ImageMagick
  • FontForge
  • TeX (did a
    Full install with 2005 Devel.)

Had a brief look
through the other packages and maybe I\’ll install _Latex to RTF_
and _RTF 2 Latex_ later. Created a _DMG_ folder and put
the downloaded disk images into it. Created a_PAPERS_ folder and
transferred the last version of the paper with Stijn to check TeX but
clearly it couldn\’t find the _diagrams.sty_ file (I know I have
to quit using this, but I\’ll better get it over for backward
compatibility; put it into ~/Library/texmf/tex/latex/. Ran TeX again
without problems this time and checked the nice source-PDF syncing
(apple-click to jump). Finished : 15:37

15:56 : As long as administration sends me
_Word_ documents and expects me to read them, I have no choice
but to install _Office X_ . The upshot was that while searching
for the OfficeCD I found also the HP LaserJet 1320 CD and installed the
driver so now I can print 2-sided (using Printer Setup Utility) . Done :
16:15

16:45 : Used the
_.mac System Preference_ to get syncing started with my iDisk to
get adresses, calendars and passwords etc. on my iBook. Also filled in
the Sharing Preferences. Now that I have the passwords at hand, it is
time to get the latest versions of some of the shareware I own (and copy
their disk image to the DMG folder)

  • DevonThink
  • DenonAgent
  • Pod2Go : the site seems to be down at the
    moment but fortunately, I have a disk image of it which will have to do
    for now (note to self : check later whether the site is permanently
    dead…) Update today : it is up and running again…

and while I\’m at it I may as well get my wallet out and
purchase the full version of _Lite_ versions I like and use a lot
:

Fortunately, there is also a lot of excellent freeware that I
want to use

One of the following days : MySQL, PHP and perhaps Tracks but
first I desperately need to do some maths to kick off from all this
nonsense…

Leave a Comment