Hi,
I have set up LatexRender on phpBB3 without problems, thanks for your good work.
If anyone is getting lost, then the post by sisteczko on Mon Dec 31, 2007 above is all that is necessary. Just make sure you edit bbcode.php in the right place, that is, near the end of the function bbcode_second_pass(..).
Now I wanted the $..$ and the other nice tags. The post
in the big thread shows how it's done on
http://mathlinks.ro. Thanks for those guys for showing us that it's possible. However, I wasn't comfortable with making deep incisions into phpBB. All I really wanted was a shortcut, such that $..$ would be changed to [tex]..[/tex]. That is a clean solution.
The following code is for this. To install:
- Save the file below as phpbb/latexrender/phpbb_hook_dollars.php
- In the file phpbb/include/message_parser.php, find "// Parse BBCode" - for me this is line 1121, and before it insert the line
- Code: Select all
include("/path/to/phpbb/latexrender/phpbb_hook_dollars.php");
- In the Administration Control Panel, go to Posting, BBCode and add the following two codes:
- [indentedblock]{TEXT}[/indentedblock] with replacement
- Code: Select all
<div style="padding-left:4em;">{TEXT}</div>
- [dollar][/dollar] with replacement $
- Done.
phpbb_hook_dollars.php- Code: Select all
<?php
/**
* LaTeX Rendering Class - PHPBB Hook for dollar signs (superficial type)
* Copyright (C) 2008 Evgeni Sergeev
*
* 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 Evgeni Sergeev
* @vetsion 0.1
* @package latexrender
*
*/
/**
* This is for phpBB version 3.
* The idea is to use a pair of dollar signs to contain LaTeX mathematics in forum
* posts, as a shorthand, in the same way we are used to in proper LaTeX documents.
*
* This superficial approach doesn't try to make dollar signs into first-class
* phpBB3 tags -- as soon as the program gets its hands on the message, it replaces
* the dollar signs with [tex][/tex] tags, etc. It just makes the [tex][/tex]
* tags much nicer to use. The downside is that once the message is in the system,
* it is slightly more difficult to cut and paste into a LaTeX document, but I
* find that I hardly ever need to.
*
* The superficial approach is very light, which probably makes it more reusable
* between versions, with less modifications. Just a few lines of code in one
* place.
*
* An issue is how to deal with real dollar signs. We define [dollar][/dollar]
* tags, and allow the user to type \$ as a shorthand.
*
*
* HOW TO INSTALL
*
* SAVE the file you are reading as phpbb/latexrender/phpbb_hook_dollars.php
*
* OPEN phpbb/include/message_parser.php
* In the function parse(), before it parses the BBCode,
* which is roughly at line 1121, and has "// Parse BBCode" near it, insert
* the following line (changing the path):
*
* include("path/to/phpBB3/latexrender/phpbb_hook_dollars.php");
*
* GO TO Administration Control Panel, Posting, BBCodes
* Add a new BBCode as follows:
* BBCode usage is [indentedblock]{TEXT}[/indentedblock]
* HTML replacement is <div style="padding-left:4em;">{TEXT}</div>
* Helpline and "Display on posting page" are probably unnecessary.
*
* Add another BBCode:
* BBCode usage is [dollar][/dollar]
* HTML replacement is $
* Helpline Insert a literal $ sign
* Display on posting page Yes
*
* DONE
*
*/
//First replace \$ signs.
$this->message = preg_replace("#\\\\\\\$#" , "[dollar][/dollar]", $this->message);
//Replace $$..$$.
$this->message = preg_replace("#\\\$\\\$(.*?)\\\$\\\$#si",
"[indentedblock][tex]\\displaystyle{\\1}[/tex][/indentedblock]", $this->message);
//Replace $..$.
$this->message = preg_replace("#\\\$(.*?)\\\$#si",
"[tex]\\1[/tex]", $this->message);
//Replace \[..\].
$this->message = preg_replace("#\\\\\\[(.*?)\\\\\\]#si",
"[indentedblock][tex]\\displaystyle{\\1}[/tex][/indentedblock]", $this->message);
?>
You can see what I've done. This works for any message, even if it doesn't contain any BBCode, just dollars. For [indentedblock][/indentedblock], I could probably have used a <p></p> element instead. All this does is puts the contents on its own line, with a 4 space indent from the left. The [dollar][/dollar] tag is used for a literal dollar. Writing \$ is a shorthand. First it is replaced. Then the only dollar signs left are the demarcation ones. We take the double dollar signs first, as doing single dollar signs would incorrectly parse these, if done first. The replacements contain only BBCode tags, no dollars. Then we process $..$ and \[..\]. By the end of the hook, there are no dollar signs left in the message, unless there were mismatched dollar signs. Then, phpbb replaces [dollar][/dollar] with a dollar sign. And after it has processed all of the system tags, including [indentedblock] now, LatexRender processes the [tex][/tex] tags.
How would we change this to ignore the dollar signs within [code] tags? I would probably store character ranges of these [code] structures, including beginning and end tag, in an array, using preg_match_all with PREG_OFFSET_CAPTURE flag. Then I would split the string along the boundaries of these ranges, and run the sequence of substitutions as in phpbb_hook_dollar.php for all char spans outside of the ranges. And then I would concat them all back. I don't have time for it now.