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:
-
Plugin Name: LaTeX
-
Version: 0.1
-
Author: Ole
-
*/
-
-
function addLatex($text)
-
{
-
$text = preg_replace("/\[tex\](.+)\[\/tex\]/",'<img src="http://www.codecogs.com/eq.latex?\\1" alt="" />',$text);
-
return $text;
-
}
-
-
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.
June 18th, 2008 at 11:14:10
[tex]{v}”>[/tex]