math equations (with latex)

This forum is now closed as part of retiring phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

Very strange. Where on earth did eqnarray come from, you can't put \LaTeX in that? It also wants a 7pt font which you can't have. Have you changed class.latexrender.php?

You can try using example.php (in otherPHP/latexrender) which is independent of phpBB to see what is happening.
miguel-murcia
Registered User
Posts: 5
Joined: Wed Feb 01, 2006 9:33 am

Re: math equations (with latex)

Post by miguel-murcia »

thank you very much, i changed class.latexrender.php and it's give me some problems. I give this archive from your web and write some new commands and all is works. Thank you.
sisteczko
Registered User
Posts: 8
Joined: Thu Dec 27, 2007 2:16 pm

Re: math equations (with latex)

Post by sisteczko »

I gues most of you still use phpBB2, but there are some posts on this topic which apply to the phpBB3. So, I'd like to advertise an existing topic on the right category (phpBB 3.0.x ‹ 3.0.x Modifications Forums ‹ [3.0.x] MOD Requests ‹ LaTeX support in phpBB3 ).

I write it with some personal interest, since I've got a small little problem with installation of Latex support on phpBB3 with Mathrenderer http://www.phpbb.com/community/viewtopi ... 2&t=653165, and I don't really know where put a question. I guess I ommited somewhere an obvious thing and the remedy is simple. Please be good and help me!... :cry:
lastyou
Registered User
Posts: 3
Joined: Wed Jan 16, 2008 6:50 am

Re: math equations (with latex)

Post by lastyou »

Hi! I have a question about latexrender

I'm using phpbb3 Gold system. and using Latexrender for render maths equations. But step using, I did as steven guided, but has still a error.
That's when type [tex]a'[/tex] or [tex]a{i}[/tex], it didn't display a', alternatively, it displayed a39;

Now, I don't know how do fix this error? Help me!

Thanks so much!
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

Fortunately that's easy to solve. There are 2 ways of doing it and you can use either or both:
1. Use ^{\prime} instead of '
and/or
2. in phpbb_hook_2.php after the line

Code: Select all

$latex_formula = html_entity_decode($tex_matches[1][$i]);
add

Code: Select all

$latex_formula = str_replace("'","'",$latex_formula);
You can use method 2 for any other symbols that sometimes don't display properly. For example & in matrices and tables sometimes comes out as 38; so you add the line:

Code: Select all

$latex_formula = str_replace("&","&",$latex_formula);
lastyou
Registered User
Posts: 3
Joined: Wed Jan 16, 2008 6:50 am

Re: math equations (with latex)

Post by lastyou »

Thank you, Steven. I was done! :D
lastyou
Registered User
Posts: 3
Joined: Wed Jan 16, 2008 6:50 am

Re: math equations (with latex)

Post by lastyou »

Another question, help me!

If I want to use dollar sign $ $, and [tex] [/tex] simultaneous, how do you do ? (I only need one dollar sign, no need 2 or more, example $$ {text} $$).

Thanks a lot.
Best!
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

How have you got $...$ working and which version of phpBB are you using, 2 or 3? Basically all you need do is replace [tex] and [/tex] by $ (or vice versa) then you only have one set of tags to deal with.
trashbox
Registered User
Posts: 53
Joined: Wed Aug 22, 2007 9:25 pm

Re: math equations (with latex)

Post by trashbox »

Hello stevem!
I already had your help around page 33 and I appreciate your attention.
In my site, everything is working on my Linux server using BBCode with latexrender.

Please, I have a new question.
Locally, using Windows Vista, I have the same site for test purpose, using WAMP5.
But, I can't render the TEX BBCode, of course I think because of the latexrender Linux path configuration.
Is there some alternative to do my PHPBB local site render formulas just like my remote does?

I was trying search here and I've seen something about MiKTeX.
Is it the best solution for TEX BBCode in a PHPBB Windows hosted?
What do you say?

Thank you so much!
Equipe AjudaMatemática.com
Exercícios, plantão de dúvidas, desafios, problemas curiosos e repositório de materiais IME-USP do curso de licenciatura em Matemática!
Writing mathematical symbols with LaTeX and BBCode (just a bridge):
http://www.ajudamatematica.com/viewtopi ... p=177#p177
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

MiKTeX will be fine. Remember though as it says in the readme file
# For Windows the paths in class.latexrender.php must use \\ or / not just a single \
# For example
# var $_latex_path = "C:\\texmf\\miktex\\bin\\latex.exe";
# or
# var $_latex_path = "C:/texmf/miktex/bin/latex.exe";
trashbox
Registered User
Posts: 53
Joined: Wed Aug 22, 2007 9:25 pm

Re: math equations (with latex)

Post by trashbox »

stevem, I've just installed MiKTeX, the basic intaller.

I did some path changes in the class.render.php, but I see something still wrong, because I'm still getting the error:
Warning: unlink(C:/Users/user/projects/local/latexrender/tmp/4927e1395ab1d386386a762cad17d7a7.aux) [function.unlink]: No such file or directory in
C:\Users\user\projects\local\latexrender\class.latexrender.php on line 321
The same for: *.log, *.dvi, *.ps and *.png extensions.

I've written some coments here after "***" in the class.latexrender.php:
class LatexRender {

// ====================================================================================
// Variable Definitions
// ====================================================================================
var $_picture_path = ""; //***Should I change this three paths?
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 = "C:/Program Files/MiKTeX 2.7/miktex/bin/latex.exe"; //***"/usr/bin/latex";
var $_dvips_path = "C:/Program Files/MiKTeX 2.7/miktex/bin/dvips.exe"; //***"/usr/bin/dvips";
var $_convert_path = "/usr/local/bin/convert"; //***I couldn't find "convert" in C:/Program Files/MiKTeX 2.7
var $_identify_path="/usr/local/bin/identify"; //***I couldn't find "identify" in C:/Program Files/MiKTeX 2.7


Thank you.
Equipe AjudaMatemática.com
Exercícios, plantão de dúvidas, desafios, problemas curiosos e repositório de materiais IME-USP do curso de licenciatura em Matemática!
Writing mathematical symbols with LaTeX and BBCode (just a bridge):
http://www.ajudamatematica.com/viewtopi ... p=177#p177
trashbox
Registered User
Posts: 53
Joined: Wed Aug 22, 2007 9:25 pm

Re: math equations (with latex)

Post by trashbox »

I've seen that ImageMagick was missing.
Now it's installed and everything is working after local path changes, without spaces like this:
var $_latex_path = "C:/Progra~1/MiKTeX~1.7/miktex/bin/latex.exe"; //"/usr/bin/latex";
var $_dvips_path = "C:/Progra~1/MiKTeX~1.7/miktex/bin/dvips.exe"; //"/usr/bin/dvips";
var $_convert_path = "C:/Progra~1/ImageMagick-6.3.8-Q16/convert.exe"; //"/usr/local/bin/convert";
var $_identify_path= "C:/Progra~1/ImageMagick-6.3.8-Q16/identify.exe"; //"/usr/local/bin/identify";
Thank you.
Equipe AjudaMatemática.com
Exercícios, plantão de dúvidas, desafios, problemas curiosos e repositório de materiais IME-USP do curso de licenciatura em Matemática!
Writing mathematical symbols with LaTeX and BBCode (just a bridge):
http://www.ajudamatematica.com/viewtopi ... p=177#p177
Evgeni Sergeev
Registered User
Posts: 2
Joined: Sun Feb 10, 2008 6:55 am

Re: math equations (with latex)

Post by Evgeni Sergeev »

For anyone interested in setting up LatexRender on phpBB3 with $..$, consider reading about my second-order mod, which is over here http://www.phpbb.com/community/viewtopi ... 5#p4250675.

There is also a clear full guide for getting LatexRender working with phpBB3 in general on that thread, a couple of posts above.
User avatar
TheHighwayman
Registered User
Posts: 28
Joined: Wed Jun 06, 2007 5:05 pm

Re: math equations (with latex)

Post by TheHighwayman »

Hi stevem,
I've exactly the same problem takunfer posted some posts above, that is:
takufner wrote:Hi stevem,

I managed upgrading my forum from 2.0.2.2 to 3.0.0 with the 6000 messages in the old version.

In 2.0.2.2 I had mimetex working fine. And almost all my messages have some sort of equation using mimetex (with the BBCode [tex]).

In my new server I've successfully installed mimetex, it is working properly (the example file can show all the equations and produce the correct cache for those equations written in the example.php).

I've changed the things you instructed in this post (btw, for mimetex there are 8 changes for $text, not just 6).

Now I can use mimetex for my new posts, but without cache for equations in the forum. This is not my biggest problem.
My problem is with the legacy message. No one is showing the equations. The BBcode is not being converted for the old messages. But, if I edit any old message, after saving the equations are ok for this message.

Is there some way to reprocess all messages?

I am using phpBB3 3.0.0 Olympus on a Linux shared server.

Thanks in advance.
How to solve?
I've also followed carefully this post
http://www.phpbb.com/community/viewtopi ... a&start=15
even if I use mimetex.cgi script;
in this post student112 seems to have solved, but I don't manage in understanding how.

I've also tried to simply use directly BBCode html conversion, in ACP, but nothing; it works only for new posts.
I've tried to put on 1 the system disabled option, but nothing changed.
I've tried to use echo command on phpbb_hook_2.php and results it is processed on old posts.
I've tried to use echo command + count tex, on phpbb_hook_2.php and always results there are 0 tex formulae in old posts.

Is there a way to solve?

This is my bbcode.php:

Code: Select all

<?php
/**
*
* @package phpBB3
* @version $Id: bbcode.php,v 1.114 2007/10/07 10:34:45 naderman Exp $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* BBCode class
* @package phpBB3
*/
class bbcode
{
	var $bbcode_uid = '';
	var $bbcode_bitfield = '';
	var $bbcode_cache = array();
	var $bbcode_template = array();

	var $bbcodes = array();

	var $template_bitfield;
	var $template_filename = '';

	/**
	* Constructor
	* Init bbcode cache entries if bitfield is specified
	*/
	function bbcode($bitfield = '')
	{
		if ($bitfield)
		{
			$this->bbcode_bitfield = $bitfield;
			$this->bbcode_cache_init();
		}
	}

	/**
	* Second pass bbcodes
	*/
	function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false)
	{
		if ($bbcode_uid)
		{
			$this->bbcode_uid = $bbcode_uid;
		}

		if ($bbcode_bitfield !== false)
		{
			$this->bbcode_bitfield = $bbcode_bitfield;

			// Init those added with a new bbcode_bitfield (already stored codes will not get parsed again)
			$this->bbcode_cache_init();
		}

		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, '', $message);
			}

			return;
		}

		$str = array('search' => array(), 'replace' => array());
		$preg = array('search' => array(), 'replace' => array());

		$bitfield = new bitfield($this->bbcode_bitfield);
		$bbcodes_set = $bitfield->get_all_set();

		$undid_bbcode_specialchars = false;
		foreach ($bbcodes_set as $bbcode_id)
		{
			if (!empty($this->bbcode_cache[$bbcode_id]))
			{
				foreach ($this->bbcode_cache[$bbcode_id] as $type => $array)
				{
					foreach ($array as $search => $replace)
					{
						${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search);
						${$type}['replace'][] = $replace;
					}

					if (sizeof($str['search']))
					{
						$message = str_replace($str['search'], $str['replace'], $message);
						$str = array('search' => array(), 'replace' => array());
					}

					if (sizeof($preg['search']))
					{
						// we need to turn the entities back into their original form to allow the
						// search patterns to work properly
						if (!$undid_bbcode_specialchars)
						{
							$message = str_replace(array('&#58;', '&#46;'), array(':', '.'), $message);
							$undid_bbcode_specialchars = true;
						}

						$message = preg_replace($preg['search'], $preg['replace'], $message);
						$preg = array('search' => array(), 'replace' => array());
					}
				}
			}
		}
		
		include("c:/xampp/htdocs/phpBB3/mimetex/phpbb_hook_2.php");

		// 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()
	{
		global $user, $phpbb_root_path;

		if (empty($this->template_filename))
		{
			$this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']);
			$this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html';

			if (!@file_exists($this->template_filename))
			{
				trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
			}
		}

		$bbcode_ids = $rowset = $sql = array();

		$bitfield = new bitfield($this->bbcode_bitfield);
		$bbcodes_set = $bitfield->get_all_set();

		foreach ($bbcodes_set as $bbcode_id)
		{
			if (isset($this->bbcode_cache[$bbcode_id]))
			{
				// do not try to re-cache it if it's already in
				continue;
			}
			$bbcode_ids[] = $bbcode_id;

			if ($bbcode_id > NUM_CORE_BBCODES)
			{
				$sql[] = $bbcode_id;
			}
		}

		if (sizeof($sql))
		{
			global $db;

			$sql = 'SELECT *
				FROM ' . BBCODES_TABLE . '
				WHERE ' . $db->sql_in_set('bbcode_id', $sql);
			$result = $db->sql_query($sql, 3600);

			while ($row = $db->sql_fetchrow($result))
			{
				// To circumvent replacing newlines with <br /> for the generated html,
				// we use carriage returns here. They are later changed back to newlines
				$row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
				$row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);

				$rowset[$row['bbcode_id']] = $row;
			}
			$db->sql_freeresult($result);
		}

		foreach ($bbcode_ids as $bbcode_id)
		{
			switch ($bbcode_id)
			{
				case 0:
					$this->bbcode_cache[$bbcode_id] = array(
						'str' => array(
							'[/quote:$uid]'	=> $this->bbcode_tpl('quote_close', $bbcode_id)
						),
						'preg' => array(
							'#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise'	=> "\$this->bbcode_second_pass_quote('\$1', '\$2')"
						)
					);
				break;

				case 1:
					$this->bbcode_cache[$bbcode_id] = array(
						'str' => array(
							'[b:$uid]'	=> $this->bbcode_tpl('b_open', $bbcode_id),
							'[/b:$uid]'	=> $this->bbcode_tpl('b_close', $bbcode_id),
						)
					);
				break;

				case 2:
					$this->bbcode_cache[$bbcode_id] = array(
						'str' => array(
							'[i:$uid]'	=> $this->bbcode_tpl('i_open', $bbcode_id),
							'[/i:$uid]'	=> $this->bbcode_tpl('i_close', $bbcode_id),
						)
					);
				break;

				case 3:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#\[url:$uid\]((.*?))\[/url:$uid\]#s'			=> $this->bbcode_tpl('url', $bbcode_id),
							'#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s'	=> $this->bbcode_tpl('url', $bbcode_id),
						)
					);
				break;

				case 4:
					if ($user->optionget('viewimg'))
					{
						$this->bbcode_cache[$bbcode_id] = array(
							'preg' => array(
								'#\[img:$uid\](.*?)\[/img:$uid\]#s'		=> $this->bbcode_tpl('img', $bbcode_id),
							)
						);
					}
					else
					{
						$this->bbcode_cache[$bbcode_id] = array(
							'preg' => array(
								'#\[img:$uid\](.*?)\[/img:$uid\]#s'		=> str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)),
							)
						);
					}
				break;

				case 5:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s'	=> $this->bbcode_tpl('size', $bbcode_id),
						)
					);
				break;

				case 6:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'!\[color=(#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is'	=> $this->bbcode_tpl('color', $bbcode_id),
						)
					);
				break;

				case 7:
					$this->bbcode_cache[$bbcode_id] = array(
						'str' => array(
							'[u:$uid]'	=> $this->bbcode_tpl('u_open', $bbcode_id),
							'[/u:$uid]'	=> $this->bbcode_tpl('u_close', $bbcode_id),
						)
					);
				break;

				case 8:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise'	=> "\$this->bbcode_second_pass_code('\$1', '\$2')",
						)
					);
				break;

				case 9:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#'	=> "\$1",
							'#(\[list=([^\[]+):$uid\])[\n]{1}#'			=> "\$1",
							'#\[list=([^\[]+):$uid\]#e'					=> "\$this->bbcode_list('\$1')",
						),
						'str' => array(
							'[list:$uid]'		=> $this->bbcode_tpl('ulist_open_default', $bbcode_id),
							'[/list:u:$uid]'	=> $this->bbcode_tpl('ulist_close', $bbcode_id),
							'[/list:o:$uid]'	=> $this->bbcode_tpl('olist_close', $bbcode_id),
							'[*:$uid]'			=> $this->bbcode_tpl('listitem', $bbcode_id),
							'[/*:$uid]'			=> $this->bbcode_tpl('listitem_close', $bbcode_id),
							'[/*:m:$uid]'		=> $this->bbcode_tpl('listitem_close', $bbcode_id)
						),
					);
				break;

				case 10:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#\[email:$uid\]((.*?))\[/email:$uid\]#is'			=> $this->bbcode_tpl('email', $bbcode_id),
							'#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is'	=> $this->bbcode_tpl('email', $bbcode_id)
						)
					);
				break;

				case 11:
					if ($user->optionget('viewflash'))
					{
						$this->bbcode_cache[$bbcode_id] = array(
							'preg' => array(
								'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'	=> $this->bbcode_tpl('flash', $bbcode_id),
							)
						);
					}
					else
					{
						$this->bbcode_cache[$bbcode_id] = array(
							'preg' => array(
								'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'	=> str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))
							)
						);
					}
				break;

				case 12:
					$this->bbcode_cache[$bbcode_id] = array(
						'str'	=> array(
							'[/attachment:$uid]'	=> $this->bbcode_tpl('inline_attachment_close', $bbcode_id)
						),
						'preg'	=> array(
							'#\[attachment=([0-9]+):$uid\]#'	=> $this->bbcode_tpl('inline_attachment_open', $bbcode_id)
						)
					);
				break;

				default:
					if (isset($rowset[$bbcode_id]))
					{
						if ($this->template_bitfield->get($bbcode_id))
						{
							// The bbcode requires a custom template to be loaded
							if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))
							{
								// For some reason, the required template seems not to be available, use the default template
								$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
							}
							else
							{
								// In order to use templates with custom bbcodes we need
								// to replace all {VARS} to corresponding backreferences
								// Note that backreferences are numbered from bbcode_match
								if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
								{
									foreach ($m[0] as $i => $tok)
									{
										$bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
									}
								}
							}
						}
						else
						{
							// Default template
							$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
						}

						// Replace {L_*} lang strings
						$bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl);

						if (!empty($rowset[$bbcode_id]['second_pass_replace']))
						{
							// The custom BBCode requires second-pass pattern replacements
							$this->bbcode_cache[$bbcode_id] = array(
								'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
							);
						}
						else
						{
							$this->bbcode_cache[$bbcode_id] = array(
								'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
							);
						}
					}
					else
					{
						$this->bbcode_cache[$bbcode_id] = false;
					}
				break;
			}
		}
	}

	/**
	* Return bbcode template
	*/
	function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false)
	{
		static $bbcode_hardtpl = array();
		if (empty($bbcode_hardtpl))
		{
			global $user;
			
			$bbcode_hardtpl = array(
				'b_open'	=> '<span style="font-weight: bold">',
				'b_close'	=> '</span>',
				'i_open'	=> '<span style="font-style: italic">',
				'i_close'	=> '</span>',
				'u_open'	=> '<span style="text-decoration: underline">',
				'u_close'	=> '</span>',
				'img'		=> '<img src="$1" alt="' . $user->lang['IMAGE'] . '" />',
				'size'		=> '<span style="font-size: $1%; line-height: normal">$2</span>',
				'color'		=> '<span style="color: $1">$2</span>',
				'email'		=> '<a href="mailto:$1">$2</a>'
			);
		}

		if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id))
		{
			return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false;
		}

		if (empty($this->bbcode_template))
		{
			if (($tpl = file_get_contents($this->template_filename)) === false)
			{
				trigger_error('Could not load bbcode template', E_USER_ERROR);
			}

			// replace \ with \\ and then ' with \'.
			$tpl = str_replace('\\', '\\\\', $tpl);
			$tpl = str_replace("'", "\'", $tpl);

			// strip newlines and indent
			$tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);

			// Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
			$this->bbcode_template = array();

			$matches = preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END (?:.*?) -->#', $tpl, $match);

			for ($i = 0; $i < $matches; $i++)
			{
				if (empty($match[1][$i]))
				{
					continue;
				}

				$this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
			}
		}

		return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false);
	}

	/**
	* Return bbcode template replacement
	*/
	function bbcode_tpl_replace($tpl_name, $tpl)
	{
		global $user;

		static $replacements = array(
			'quote_username_open'	=> array('{USERNAME}'	=> '$1'),
			'color'					=> array('{COLOR}'		=> '$1', '{TEXT}'			=> '$2'),
			'size'					=> array('{SIZE}'		=> '$1', '{TEXT}'			=> '$2'),
			'img'					=> array('{URL}'		=> '$1'),
			'flash'					=> array('{WIDTH}'		=> '$1', '{HEIGHT}'			=> '$2', '{URL}'	=> '$3'),
			'url'					=> array('{URL}'		=> '$1', '{DESCRIPTION}'	=> '$2'),
			'email'					=> array('{EMAIL}'		=> '$1', '{DESCRIPTION}'	=> '$2')
		);

		$tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $tpl);

		if (!empty($replacements[$tpl_name]))
		{
			$tpl = strtr($tpl, $replacements[$tpl_name]);
		}

		return trim($tpl);
	}

	/**
	* Second parse list bbcode
	*/
	function bbcode_list($type)
	{
		if ($type == '')
		{
			$tpl = 'ulist_open_default';
			$type = 'default';
		}
		else if ($type == 'i')
		{
			$tpl = 'olist_open';
			$type = 'lower-roman';
		}
		else if ($type == 'I')
		{
			$tpl = 'olist_open';
			$type = 'upper-roman';
		}
		else if (preg_match('#^(disc|circle|square)$#i', $type))
		{
			$tpl = 'ulist_open';
			$type = strtolower($type);
		}
		else if (preg_match('#^[a-z]$#', $type))
		{
			$tpl = 'olist_open';
			$type = 'lower-alpha';
		}
		else if (preg_match('#[A-Z]#', $type))
		{
			$tpl = 'olist_open';
			$type = 'upper-alpha';
		}
		else if (is_numeric($type))
		{
			$tpl = 'olist_open';
			$type = 'arabic-numbers';
		}
		else
		{
			$tpl = 'olist_open';
			$type = 'arabic-numbers';
		}

		return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl));
	}

	/**
	* Second parse quote tag
	*/
	function bbcode_second_pass_quote($username, $quote)
	{
		// when using the /e modifier, preg_replace slashes double-quotes but does not
		// seem to slash anything else
		$quote = str_replace('\"', '"', $quote);
		$username = str_replace('\"', '"', $username);

		// remove newline at the beginning
		if ($quote == "\n")
		{
			$quote = '';
		}

		$quote = (($username) ? str_replace('$1', $username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote;

		return $quote;
	}

	/**
	* Second parse code tag
	*/
	function bbcode_second_pass_code($type, $code)
	{
		// when using the /e modifier, preg_replace slashes double-quotes but does not
		// seem to slash anything else
		$code = str_replace('\"', '"', $code);

		switch ($type)
		{
			case 'php':
				// Not the english way, but valid because of hardcoded syntax highlighting
				if (strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
				{
					$code = substr($code, 41);
				}

			// no break;

			default:
				$code = str_replace("\t", '&nbsp; &nbsp;', $code);
				$code = str_replace('  ', '&nbsp; ', $code);
				$code = str_replace('  ', ' &nbsp;', $code);

				// remove newline at the beginning
				if (!empty($code) && $code[0] == "\n")
				{
					$code = substr($code, 1);
				}
			break;
		}

		$code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');

		return $code;
	}
}

?>
and this is my phpbb_hook_2.php:

Code: Select all

<?php
/**
 * LaTeX Rendering Class - PHPBB Hook
 * Copyright (C) 2003  Benjamin Zeiss <[email protected]>
 *
 * 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 <[email protected]>
 * @package latexrender
 * Adapted for use with mimetex
 */
		// --------------------------------------------------------------------------------------------------
		// adjust this to match your system configuration
		$mimetex_path = "c:/xampp/htdocs/cgi-bin/mimetex.exe";
		$mimetex_path_http = "http://localhost/phpBB3/mimetex";
		$mimetex_cgi_path_http="http://localhost/cgi-bin/mimetex.exe";
		$pictures_path = "c:/xampp/htdocs/phpBB3/mimetex/pictures";
		// --------------------------------------------------------------------------------------------------

		// change $system_disabled to 1 if you get an error message similar to
		// Warning: system() has been disabled for security reasons
		$system_disabled=0;

		$pictures_path_http = $mimetex_path_http."/pictures";

            preg_match_all("#\[tex:$bbcode_uid\](.*?)\[/tex:$bbcode_uid\]#si",$message,$tex_matches);

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

		    $formula_hash = md5($mimetex_formula);

			$filename = $formula_hash.".gif";
			$full_path_filename = $pictures_path."/".$filename;

			if (is_file($full_path_filename)) {
				$url = $pictures_path_http."/".$filename;
			} else {
				$command = "$mimetex_path -e ".$full_path_filename." ".escapeshellarg($mimetex_formula);

			if ($system_disabled==0) {
				system($command,$status_code);
			} else {
				$status_code=0;
			}

				if ($status_code != 0) {
					$url=false;
				} else {
					$url = $pictures_path_http."/".$filename;
				}
			}

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

			if ($url != false) {
				if ($system_disabled==0) {
					$message = substr_replace($message, "<img src='".$url."' title='".$alt_mimetex_formula."' alt='".$alt_mimetex_formula."' align=absmiddle>",$pos,strlen($tex_matches[0][$i]));
				} else {
					$message = substr_replace($message, "<img src='".$mimetex_cgi_path_http."?".$mimetex_formula."' title='".$alt_mimetex_formula."' alt='".$alt_mimetex_formula."' align=absmiddle>",$pos,strlen($tex_matches[0][$i]));
				}
			} else {
				$message = substr_replace($message, "[Mimetex cannot convert this formula]",$pos,strlen($tex_matches[0][$i]));
			}
		}

?>
Thank you in advance.
TheHighwayman
"The wind was a torrent of darkness among the gusty trees
The moon was a ghostly galleon tossed upon the cloudy seas
The road was a ribbon of moonlight over the purple moor
And the highwayman came riding, riding, riding,
The highwayman came riding, up to the old inn-door..."
(Alfred Noyes)
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

Unfortunately there is a bug when upgrading the forum and appears to be a common problem, not just with latexrender. However there is a solution at http://phpbbacademy.com/community/viewt ... =62&t=4082 which has a script that goes through all the old posts and reparses the old BBcode, adding the missing $bbcode_uid.

Others have reported that this script works so I hope it does for your forum.
Post Reply

Return to “[2.0.x] MOD Requests”