Help with Latex Render Installation for phpBB3

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Suggested Hosts
Registered User
Posts: 1
Joined: Sun Jan 11, 2009 8:10 pm

Help with Latex Render Installation for phpBB3

Post by jmerrin » Sun Jan 11, 2009 8:55 pm

Hi all,

I am trying install a latex enabled phpBB3 board. I have gone through the instructions and seem to be stuck at the moment. I would like to describe what I did so it may be helpful to others trying to do the same sort of installation.

I already have an up and running phpBB3 board running on

The first thing I did was install ImageMagick and a Latex installation on my Ubuntu 8.10 system.
The latex system is tex-live.
I believe that perl is required so you can also install that

Code: Select all

sudo apt-get install libperl-dev

Code: Select all

sudo apt-get install imagemagick 

Code: Select all

sudo apt-get install texlive texlive-latex-extra texlive-math-extra texlive-pstricks texlive-science latex-beamer 
I was able to test the latex on a sample file
latex filename.tex ...
I was able to test the imagemagick works by typing
convert logo: logo.gif
You can also just type display and the program comes up.

Next I downloaded the latex render software from

I unpacked the file system into

My normal board is in

Change the permissions on the pictures and tmp folders

Code: Select all

chmod ugo=rwx tmp

Code: Select all

chmod ugo=rwx pictures
Now you have to modify the path in the php files to work with phpBB3
File 1: phpbb_hook_2.php

Code: Select all

 * LaTeX Rendering Class - PHPBB Hook
 * Copyright (C) 2003  Benjamin Zeiss <>
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * --------------------------------------------------------------------
 * @author Benjamin Zeiss <>
 * @version v0.8
 * @package latexrender
    // --------------------------------------------------------------------------------------------------
    // adjust this to match your system configuration
    $latexrender_path = "/var/www/phpbb/latexrender";
    $latexrender_path_http = "http://localhost/phpbb/latexrender";

    // --------------------------------------------------------------------------------------------------


    $latex = new LatexRender($latexrender_path."/pictures",$latexrender_path_http."/pictures",$latexrender_path."/tmp");

    for ($i=0; $i < count($tex_matches[0]); $i++) {
        $pos = strpos($message, $tex_matches[0][$i]);
        $latex_formula = html_entity_decode($tex_matches[1][$i]);

        $url = $latex->getFormulaURL($latex_formula);

		$alt_latex_formula = htmlentities($latex_formula, ENT_QUOTES);
		$alt_latex_formula = str_replace("\r","&#13;",$alt_latex_formula);
		$alt_latex_formula = str_replace("\n","&#10;",$alt_latex_formula);

        if ($url != false) {
            $message = substr_replace($message, "<img src='".$url."' title='".$alt_latex_formula."' alt='".$alt_latex_formula."' align='absmiddle'>",$pos,strlen($tex_matches[0][$i]));
        } else {
            $message = substr_replace($message, "[unparseable or potentially dangerous latex formula]",$pos,strlen($tex_matches[0][$i]));

The next step is to modify the class file class.latexrender.php
the main changes are that you have to input the path of latex, identify, dvips, and convert
which can be found with commands like

Code: Select all

 which identify 

Code: Select all

 // ====================================================================================
    // Variable Definitions
    // ====================================================================================
    var $_picture_path = "";
    var $_picture_path_httpd = "";
    var $_tmp_dir = "";
    // i was too lazy to write mutator functions for every single program used
    // just access it outside the class or change it here if nescessary
    var $_latex_path = "/usr/bin/latex";
    var $_dvips_path = "/usr/bin/dvips";
    var $_convert_path = "/usr/bin/convert";
    var $_identify_path="/usr/bin/identify";
    var $_formula_density = 120;
    var $_xsize_limit = 500;
    var $_ysize_limit = 500;
    var $_string_length_limit = 500;
	var $_font_size = 10;
	var $_latexclass = "article"; //install extarticle class if you wish to have smaller font sizes
    var $_tmp_filename;
	var $_image_format = "gif"; //change to png if you prefer
    // this most certainly needs to be extended. in the long term it is planned to use
    // a positive list for more security. this is hopefully enough for now. i'd be glad
    // to receive more bad tags !
    var $_latex_tags_blacklist = array(
        "\\read","\\write","csname","\\newhelp","\\uppercase", "\\lowercase","\\relax","\\aftergroup",
    var $_errorcode = 0;
	var $_errorextra = "";
Now there are a couple more tweaks

In phpbb_hook_2.php
find and replace $uid with $$bbcode_uid
In phpbb_hook_2.php find and replace six cases of $text with $message

These tweaks are already done above in the code listing

now go to your folder containing the bb which is in my case /var/www/phpBB3
open includes/bbcode.php

Find // Remove the uid from tags that have not been transformed into HTML then add then insert on the line above it

Code: Select all

                if (!$this->bbcode_bitfield)

// Remove the uid from tags that have not been transformed into HTML
                        if ($this->bbcode_uid)
                                $message = str_replace(':' . $this->bbcode_uid,$

The next part I am not so sure of I go to adminstrator control panel
then I go to postings then click on bbcodes and add [tex][TEXT][/tex]
with display on postings page clicked.

I type some messages on the board but they look like in plain tex.

The program does not seem to be connected to my board cause I get no indications that it is doing anything.

I think I need to test somehow the latexrender program. Can someone help me with a basic php file to generate an image of an equation? I am sort of clueless about php, but understand basic linux. Any help on the final steps of getting this going would be greatly appreciated.


Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: Help with Latex Render Installation for phpBB3

Post by stevem » Tue Jan 13, 2009 10:48 am

1. You don't need Perl but you do need to install Ghostscript.
2. In bbcode.php the line
needs to go in a different place - unfortunately there are two places that say
// Remove the uid from tags that have not been transformed into HTML
and you need the other one

Code: Select all

		// Remove the uid from tags that have not been transformed into HTML
		$message = str_replace(':' . $this->bbcode_uid, '', $message);

	* Init bbcode cache
	* requires: $this->bbcode_bitfield
	* sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
	function bbcode_cache_init()


Return to “[3.0.x] MOD Requests”