LaTeX in WP

May 24th, 2008

I finally got LaTeX in WP! Now I can write [ tex ] [ / tex ] and voilá! I’m now using a external site for rendering my equations, but as soon as I get the code running on my own server I will of course use my own.

To get this working I had to write a little plugin for WP, which was easier than I thought. Here is the code I’m using:

/*
  1. Plugin Name: LaTeX
  2. Version: 0.1
  3. Author: Ole
  4. */
  5.  
  6. function addLatex($text)
  7. {
  8.  $text = preg_replace("/\[tex\](.+)\[\/tex\]/",'<img src="http://www.codecogs.com/eq.latex?\\1" alt="" />',$text);
  9.  return $text;
  10. }
  11.  
  12. add_filter('the_content','addLatex');

WP need the comment to get data about the plugin and you simply use the add_filter() to apply your own function on given data. Here I’m using addLatex() on the content.

Here is how it works:

[ tex ] V_{ind} = -\frac{d}{dt}{\int_A{\vec B d\vec A } = -\frac{d\Phi_B}{dt} = -\frac{d}{dt}\left( \int_{a+vt}^{a+b+vt}{ \frac{\mu_oI}{2\pi x} cdx \right) = … = -\frac{\mu_0 Ic}{2\pi}\left( \frac{v}{a+b+vt} – \frac{v}{a+vt} \right) [ / tex ]

Gives:

You gotta love LaTeX, and you gotta love physics. This equation is actually the solution to a problem on an old exam.

One Response to “LaTeX in WP”

  1. CNU Says:

    [tex]{v}”>[/tex]

Leave a Reply