mathlinks.ro is heavily customised but they started with the following. There are bound to be undesirable side-effects (like problems with the code tag) which mathlinks.ro will have coded around. What I'm saying is that phpBB is built round the assumption that tags use [...] and [/...] so you need PHP coding expertise to deal with any problems. You may also need to update the code to cope with version 2.0.22. There are no guarantees offered.

Having said that, this is the code that allowed use of $..$ and \[..\]

Code: Select all

```
#######################################################################################
## This will allow you to input latex code using $ and $$ as is used in LaTeX documents
## as featured on http://mathlinks.ro
## [tex] formula [/tex] can still be used
##
## As configured this will give
## [tex] formula [/tex] uses \displaystyle but is not centred
## $ formula $ = inline text
## $$ formula $$ and \[ formula \] both give displayed mathematics which is centred
##
## IMPORTANT NOTES
## 1. phpBB expects to use [ ] for tags so using this method can give
## unexpected results, though it has been tested. Please monitor its use
## 2. Users MUST be warned NOT to use $ in ordinary text as it will give unexpected results
## 3. As $$ formula $$ and \[ formula \] give identical results
## $$ formula $$ is converted to \[ formula \] when editing and quoting
##
## The following code changes assume that you have installed the MOD as in README_phpBB.txt
## Replace phpbb_hook_1.php and phpbb_hook_2.php by the files in this folder
#
#-----[ OPEN ]---------------------------------------------
#
includes/bbcode.php
#
#-----[ FIND ]---------------------------------------------
#
if (! (strpos($text, "[") && strpos($text, "]")) )
#
#-----[ REPLACE WITH ]---------------------------------------
#
if (! (strpos($text, "[") && strpos($text, "]")) && ! (strpos($text, "$")) )
#
#-----[ FIND ]---------------------------------------------
#
$code_entities_match = array('#<#', '#>#', '#"#', '#:#', '#\[#', '#\]#', '#\(#', '#\)#', '#\{#', '#\}#'');
$code_entities_replace = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}');
#
#-----[ REPLACE WITH ]---------------------------------------
#
$code_entities_match = array('#<#', '#>#', '#"#', '#:#', '#\[#', '#\]#', '#\(#', '#\)#', '#\{#', '#\}#', '#\$#');
$code_entities_replace = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}', '$');
#
#-----[ OPEN ]---------------------------------------------
#
search.php
#
#-----[ FIND ]---------------------------------------------
#
$message = strip_tags($message);
#
#-----[ AFTER, ADD ]--------------------------------------
#
$message = str_replace("\$:$bbcode_uid",'',$message);
$message = str_replace("\[:$bbcode_uid",'',$message);
$message = str_replace("\]:$bbcode_uid",'',$message);
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
```

**phpbb_hook_1.php**
Code: Select all

```
<?php
/**
* LaTeX Rendering Class - PHPBB Hook
* Copyright (C) 2003 Benjamin Zeiss <zeiss@math.uni-goettingen.de>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* 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 <zeiss@math.uni-goettingen.de>
* @version v0.8
* @package latexrender
*
*/
$text = preg_replace("#\[tex\](.*?)\[/tex\]#si", "[tex:$uid]\\1[/tex:$uid]", $text);
$text = str_replace("\\\$","dollar:$uid",$text);
$text = preg_replace("#\\\\\[(.*?)\\\\\]#si", "\\\\\[:$uid\\1\\\\\]:$uid", $text);
$text = preg_replace("#\\\$\\\$(.*?)\\\$\\\$#si", "\\\\\[:$uid\\1\\\\\]:$uid", $text);
$text = preg_replace("#\\\$(.*?)\\\$#si", "\\\$:$uid\\1\\\$:$uid", $text);
$text = str_replace("dollar:$uid","\\\$",$text);
?>
```

**phpbb_hook_2.php**
Code: Select all

```
<?php
/**
* LaTeX Rendering Class - PHPBB Hook
* Copyright (C) 2003 Benjamin Zeiss <zeiss@math.uni-goettingen.de>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* 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 <zeiss@math.uni-goettingen.de>
* @version v0.8
* @package latexrender
*
*/
// --------------------------------------------------------------------------------------------------
// adjust this to match your system configuration
$latexrender_path = "/var/www/phpbb/latexrender";
$latexrender_path_http = "/phpbb/latexrender";
// --------------------------------------------------------------------------------------------------
include_once($latexrender_path."/class.latexrender.php");
preg_match_all("#\[tex:$uid\](.*?)\[/tex:$uid\]#si",$text,$tex_matches);
$latex = new LatexRender($latexrender_path."/pictures",$latexrender_path_http."/pictures",$latexrender_path."/tmp");
for ($i=0; $i < count($tex_matches[0]); $i++) {
$pos = strpos($text, $tex_matches[0][$i]);
$alt_latex_formula=$tex_matches[1][$i];;
$latex_formula = "\displaystyle ".$tex_matches[1][$i];
$alt_latex_formula = htmlentities($alt_latex_formula, ENT_QUOTES);
$alt_latex_formula = str_replace("\r"," ",$alt_latex_formula);
$alt_latex_formula = str_replace("\n"," ",$alt_latex_formula);
if (trim($latex_formula)=="") {
$url=false;
} else {
$url = $latex->getFormulaURL($latex_formula);
}
if ($url != false) {
$text = substr_replace($text, "<img src='".$url."' title='".$alt_latex_formula."' alt='".$alt_latex_formula."' align='absmiddle'>",$pos,strlen($tex_matches[0][$i]));
} else {
$text = substr_replace($text, "[unparseable or potentially dangerous latex formula]",$pos,strlen($tex_matches[0][$i]));
}
}
preg_match_all("#\\\$:$uid(.*?)\\\$:$uid#si",$text,$tex_matches2);
for ($i=0; $i < count($tex_matches2[0]); $i++) {
$pos = strpos($text, $tex_matches2[0][$i]);
$latex_formula = $tex_matches2[1][$i];
$alt_latex_formula = htmlentities($latex_formula, ENT_QUOTES);
$alt_latex_formula = str_replace("\r"," ",$alt_latex_formula);
$alt_latex_formula = str_replace("\n"," ",$alt_latex_formula);
if (trim($latex_formula)=="") {
$url=false;
} else {
$url = $latex->getFormulaURL($latex_formula);
}
if ($url != false) {
$text = substr_replace($text, "<img src='".$url."' title='".$alt_latex_formula."' alt='".$alt_latex_formula."' align='absmiddle'>",$pos,strlen($tex_matches2[0][$i]));
} else {
$text = substr_replace($text, "[unparseable or potentially dangerous latex formula]",$pos,strlen($tex_matches2[0][$i]));
}
}
preg_match_all("#\\\\\[:$uid(.*?)\\\\\]:$uid#si",$text,$tex_matches3);
for ($i=0; $i < count($tex_matches3[0]); $i++) {
$pos = strpos($text, $tex_matches3[0][$i]);
$alt_latex_formula=$tex_matches3[1][$i];;
$latex_formula = "\displaystyle".$tex_matches3[1][$i];
$alt_latex_formula = htmlentities($alt_latex_formula, ENT_QUOTES);
$alt_latex_formula = str_replace("\r"," ",$alt_latex_formula);
$alt_latex_formula = str_replace("\n"," ",$alt_latex_formula);
if (trim($latex_formula)=="") {
$url=false;
} else {
$url = $latex->getFormulaURL($latex_formula);
}
if ($url != false) {
$text = substr_replace($text, "<center><img src='".$url."' title='".$alt_latex_formula."' alt='".$alt_latex_formula."' align='absmiddle'></center>",$pos,strlen($tex_matches3[0][$i]));
} else {
$text = substr_replace($text, "[unparseable or potentially dangerous latex formula]",$pos,strlen($tex_matches3[0][$i]));
}
}
?>
```