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

Using LaTeX in WordPress

Using LaTeX in WordPress

Thursday 5th August 2004

Filed under: — Steve @ 6:59 pm

This is how you can use LatexRender in WordPress. Assuming you have \LaTeX and Imagemagick setup on your server and have downloaded latexrender.zip then:
1. In the download folder, otherPHP/latexrender you just need the 2 files
latex.php and class.latexrender.php
a) in latex.php ensure that
$latexrender_path = "/home/domain_name/public_html/path_to/latexrender";
contains the correct path to where your latexrender files are to go
Change
$latexrender_path_http = "/latexrender";
so it says
$latexrender_path_http = "/path_to/latexrender";


b) in class.latexrender.php ensure that
var $_latex_path = "/usr/bin/latex";
var $_dvips_path = "/usr/bin/dvips";
var $_convert_path = "/usr/bin/convert";
var $_identify_path="/usr/bin/identify";

point to the right places.

2. Create a new latexrender folder in your WordPress folder, with sub folders tmp and pictures. These 2 folders must be chmod to 777

3. Now you need to make changes to WordPress files:
(a) Stop the blog eating backslashes which \LaTeX needs for its commands
(i) wp-includes/functions-formatting.php
Line 233
After
function format_to_edit($content) {
$content = stripslashes($content);
$content = apply_filters('format_to_edit', $content);
$content = htmlspecialchars($content);
return $content;
}

Add
function format_to_edit2($content) {
$content = apply_filters('format_to_edit', $content);
$content = htmlspecialchars($content);
return $content;
}

(ii) wp-admin/post.php
Line 222
After
$content = $postdata->post_content;
Change $content = format_to_edit($content);
to
$content = format_to_edit2($content);

(b) Show \LaTeX images in preview
wp-admin/post.php
Line 248
After

< ?php $content = apply_filters('the_content', $post->post_content);


Add
include_once('../latexrender/latex.php');

(c ) Add a tex button to the edit box
wp-admin/quicktags.js
Line 131
Before
function edLink() {

Add
edButtons[edButtons.length] =
new edButton('ed_tex'
,'tex'
,'[tex ]'
,'[/tex ]'
,'x'
);

remove the spaces between tex and ] above which are required here to stop WordPress thinking it’s maths 🙂

(d) More stop WordPress eating backslashes
wp-includes/functions.php
Line 1081
Change
$content = stripslashes($post->post_content);
to
$content = $post->post_content;
Line 1089
Change
$pages[0] = stripslashes($post->post_content);
to
$pages[0] = $post->post_content;

(e) Show \LaTeX in the blog
wp-includes/template-functions-post.php
Line 62
After
function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);

Add
include_once('latexrender/latex.php');
$content=latex_content($content);

1 Comment »

RSS feed for comments on this post. TrackBack URI

  1. […] no sirve, otra posibilidad es LatexRender, pero esta es más compleja y requiere algunas aplicaciones en el servidor web y tocar algo […]

    Pingback by Miguel Rebollo » Blog Archive » Plugin de LaTeX instalado — Wednesday 19th December 2007 1:10 pm #

Leave a comment

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


 

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