Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

LATEX Parsing

Started by treo, June 18, 2004, 04:25:16 PM

Previous topic - Next topic


From what I can see, my example.php works fine. I was wondering what I'd have to mod is Subs.php to get it to work with SMF 1.1RC2. I'm not using the mimetex version, so I suppose it will be different from the poster above.
McMaster University's Largest Online Community
Powered by SMF and Mambo


I kinda have it working now. However, when I create formulas in the SMF post box, it includes html in the formula. See the attachment. Any ideas why this is?

McMaster University's Largest Online Community
Powered by SMF and Mambo


Okay, I seem to have that fixed now. I used instructions from this page:

Quote from: schamock on June 18, 2006, 07:34:47 AM
hat sich schon erledigt... hätte mir mal die latex.php richtig anschaun solln. Da sind nämlich schon Statements vorbereitet, um die HTML-Kodierung rückgängig zu machen... jaja wer lesen kann... ;)

Falls es wen interessiert, wo ich das eingefügt hab: am Anfang von parse_bbc (ca. Zeile 950). Sieht dann so aus:

function parse_bbc($message, $smileys = true, $cache_id = '')
global $txt, $scripturl, $context, $modSettings, $user_info;
static $bbc_codes = array(), $itemcodes = array(), $no_autolink_tags = array();
static $disabled;

$message = latex_content($message);


und die latex_content() in der latex.php sieht dann so aus:

function latex_content($text) {
// adjust this to match your system configuration
$latexrender_path = "/var/www/_smf/Sources/latex";
$latexrender_path_http = "/_smf/Sources/latex";



$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]);
$latex_formula = $tex_matches[1][$i];

$latex_formula = str_replace("&amp;","&",$latex_formula);
$latex_formula = str_replace("&","&",$latex_formula);
$latex_formula = str_replace("&nbsp;"," ",$latex_formula);
$latex_formula = str_replace("<BR>","",$latex_formula);
$latex_formula = str_replace("<br />","",$latex_formula);
$latex_formula = str_replace("<P>","",$latex_formula);
$latex_formula = str_replace("</P>","",$latex_formula);

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

$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 ($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. Error $latex->_errorcode $latex->_errorextra]",$pos,strlen($tex_matches[0][$i]));
return $text;

Everything works fine with the equations and latex...
Now, When I click my coppermine photo gallery I get:
Fatal error: Call to undefined function: latex_content() in /home/*****/public_html/smf/Sources/Subs.php on line 962. What could the problem be, judging on the code above?
McMaster University's Largest Online Community
Powered by SMF and Mambo



I wrote a small patch to SMF 1.1 to add support for mimetex.  You can fetch it from [nonactive]
There's some more information about it at [nonactive]


What do I do with and ERROR 4.
It says I can't create a DVI File. [nonactive]

Here is my demo


how to change color text with math expressions? with this theme

i see expressions in aliased white.
Loop code example:
The following statement is FALSE
The previous statement is TRUE.


thank you Orstio for the instructions.

In the mimetex instructions there is one additional change that asks replacing some text (full instructions here [nonactive] )
For some reason I cannot find the text the author refers to in Subs.php. Has anybody followed those 'new' instructions and made mimetex work?

I need some help deciding if the following are correct. The location of the key files are
htdocs/smf/  ---> parent forum folder

Are my parameters below correct?

$mimetex_path = "/cgi-bin/mimetex.cgi";
$mimetex_path_http = "http://localhost/smf/Sources//mimetex";
$pictures_path = "/htdocs/smf/Sources/mimetex/pictures";

In Orstio's instructions it says to add two lines after line 728. In the recent Subs.php, that appears to be the middle of a function. Is that correct?

I have not had any luck with this, even after changing the settings so I'd appreciate some feedback or ideas. I am using the most recent version of SMF, downloaded yesterday.




Just found this mod and installed it on 2.0RC3, it failed on install, but is very easy to modify to work with newer version for all your math homework needs


Would love to know how you made it work...   Thanks! ;D