LaTeX support in 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)
Anti-Spam Guide
student12
Registered User
Posts: 17
Joined: Sun Jan 22, 2006 8:51 pm
Location: tif
Contact:

it is work for the new posts

Post by student12 »

hi dr. stevem :)
I have upgraded my board to phpbb3
and I use the Howto (quoted abov)
while I adding the tex tags from the admin CP
i have found the latex is rendered provided that I ignore the "replace HTML" field
in the BBcode configure page.
in fact, no rendered image when i filled it in by

Code: Select all

<tex>{TEXT}</tex>
So for me, latex works fine on the new posts.

With respect to the old posts I have a tiny problem, it is stay [tex]latexcode[/tex] without any rendering !!

But if i click on "edit" button and send the same post again (with out any change) then the latex is rendering perfectly.

Any suggest about this issue ? ;)
_____________

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

Re: LaTeX support in phpBB3

Post by stevem »

That means the latex code is not being processed when viewing the page. The only reason that I think that this happens is that maybe the include code in phpbb_hook_2.php is in the wrong place in bbcode.php so it isn't seen. You can confirm this by putting echo commands in phpbb_hook_2.php and seeing if they appear.

If the echo commands are seen then put them in various places in phpbb_hook_2.php to see where things go wrong.

student12
Registered User
Posts: 17
Joined: Sun Jan 22, 2006 8:51 pm
Location: tif
Contact:

Re: LaTeX support in phpBB3

Post by student12 »

but i see the images of latex when i view the page (the new page)

the image disappeared only on the old topics
_____________

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

Re: LaTeX support in phpBB3

Post by stevem »

Have you viewed the source of the old pages to see if they are pointing to the right image?

student12
Registered User
Posts: 17
Joined: Sun Jan 22, 2006 8:51 pm
Location: tif
Contact:

Re: LaTeX support in phpBB3

Post by student12 »

sorry,
I mean the latex expressions like [tex]latexcode[/tex] in the pre-phpbb3 pages
dont display as images.
Wile the latex in new pages that created after I upgraded to phpbb3 display as images

so if the place of include code is wrong , way the latex rendered in the new pages??
_____________

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

Re: LaTeX support in phpBB3

Post by stevem »

One of two things has happened:
1. you are seeing the alt tag for the image which means that the image is not being found and View Source will tell you why, usually a path problem.
or
2, the code is not being processed and you need to find out where this is happening. Either
a) the phpbb_hook_2.php file is not being found or
b) the file is found but the code is not being converted.
In these two cases adding echo commands temporarily in phpbb_hook_2.php will tell you what is happening.

student12
Registered User
Posts: 17
Joined: Sun Jan 22, 2006 8:51 pm
Location: tif
Contact:

Re: LaTeX support in phpBB3

Post by student12 »

i have put the echo in phpbb_hook_2.php file
then i write:

Code: Select all

solve in Z the equation
[tex]x^x+y^y=z^z[/tex]
then i make preview and found header errors and my post with image of the equation.
_____________

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

Re: LaTeX support in phpBB3

Post by stevem »

Ignore header errors - they are due to it not expecting echo commands which are only temporary.
You should be looking at pages with old posts since new posts are fine. In phpbb_hook_2.php put something like:
echo "processing line 30 <br>";
then
echo "processing line 40: $latex_formula<br>";
using whatever line numbers are relevant. Then look at a page with old posts and see what lines are being processed.

student12
Registered User
Posts: 17
Joined: Sun Jan 22, 2006 8:51 pm
Location: tif
Contact:

Re: LaTeX support in phpBB3

Post by student12 »

hi dr :)
1) I have put the two line
echo "processing line 30 <br>";
echo "processing line 40: $latex_formula<br>";

into phpbb_hook_2.php file with no line blank line

and view several of old posts. Ignoring the header errors, I see only the old equations (the old posts) with its tags like:

Code: Select all

if you have
[tex] 
\[ 
\begin{array}{l} 
for\quad \quad x \in \;R^* \\ 
\\ 
x.\coth (x) = 1 + \frac{{x^2 }}{{3 + \frac{{x^2 }}{{5 + \frac{{x^2 }}{{7 + \frac{{x^2 }}{ \ddots }}}}}}}\quad \quad \quad \quad \quad * \\ 
\\ 
\end{array} 
\] 






[/tex] 

then prove that

[tex] 
\[ 
\begin{array}{l} 
\\ 
\frac{2}{{e - 1}} = 1 + \frac{1}{{6 + \frac{1}{{10 + \frac{1}{{14 + \frac{1}{{18 + \frac{1}{ \ddots }}}}}}}}}\quad \quad \quad \quad \quad * \\ 
\end{array} 
\] 
[/tex] 


and deduce that:

[tex] 
\[ 
\begin{array}{l} 
\\ 
e = 1 + \frac{4}{{2 + \frac{4}{{12 + \frac{4}{{20 + \frac{4}{{28 + \frac{4}{{36 + \ddots }}}}}}}}}} \quad \quad \quad \quad \quad *\\ 
\end{array} 
\] 



[/tex]
2) Then I have changed the line numbers and put the followng two line:
echo "processing line 5 <br>";
echo "processing line 10: $latex_formula<br>";

and I have get the same results.

3) then I deleted that two lines and get the following errors in the header of all the new an old posts:

Code: Select all

Now in phpbb_hook_2.php processing [tex:1g1xbk0v]x^x+y^y=z^z[/tex:1g1xbk0v]
Now in phpbb_hook_2.php processing 
Now in phpbb_hook_2.php processing 
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3391: Cannot modify header information - headers already sent by (output started at /latexrender/phpbb_hook_2.php:37)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3393: Cannot modify header information - headers already sent by (output started at /latexrender/phpbb_hook_2.php:37)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3394: Cannot modify header information - headers already sent by (output started at /latexrender/phpbb_hook_2.php:37)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3395: Cannot modify header information - headers already sent by (output started at /latexrender/phpbb_hook_2.php:37)
4) By the way, in new posts , new code like [tex](a+b)[/tex]converted to 40;a+b41; image
what should i do now?

regards
_____________

student12
Registered User
Posts: 17
Joined: Sun Jan 22, 2006 8:51 pm
Location: tif
Contact:

Re: LaTeX support in phpBB3

Post by student12 »

------------
_____________

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

Re: LaTeX support in phpBB3

Post by stevem »

Please post your copies of bbcode.php and phpbb_hook_2.php in case the problem is in one of them.

student12
Registered User
Posts: 17
Joined: Sun Jan 22, 2006 8:51 pm
Location: tif
Contact:

Re: LaTeX support in phpBB3

Post by student12 »

with pleasure :)

the 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("/home/math2/public_html/xyza3/latexrender/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;
	}
}

?>
the 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 = "/home/math2/public_html/xyza3/latexrender";
    $latexrender_path_http = "/xyza3/latexrender";

    // --------------------------------------------------------------------------------------------------
    include_once($latexrender_path."/class.latexrender.php");

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

    $latex = new LatexRender($latexrender_path."/pictures",$latexrender_path_http."/pictures",$latexrender_path."/tmp");
   echo "Now in phpbb_hook_2.php processing $message<br>";
    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]));
        }
    }
?>
_____________

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

Re: LaTeX support in phpBB3

Post by stevem »

It looks as if phpbb_hook_2.php is being processed but matches are not being made.
Change the line
echo "Now in phpbb_hook_2.php processing $message<br>";
to
echo "Now in phpbb_hook_2.php with ".count($tex_matches[0])." tex codes found in $message<br>";

Try viewing an old post only, preferably on a page with only one tex posting. Then you should get the message:
Now in phpbb_hook_2.php with 1 tex codes found in ...

If you get
Now in phpbb_hook_2.php with 0 tex codes found in ...
then the message dooesn't have any tex codes and they have been lost somewhere.

If you get "1 tex code" then try different lines further on.
Ignore all header errors as they are irrelevant.

student12
Registered User
Posts: 17
Joined: Sun Jan 22, 2006 8:51 pm
Location: tif
Contact:

Re: LaTeX support in phpBB3

Post by student12 »

I did what you have already suggest
And go to view old post with only on tex code
Then I see these lines

Code: Select all

Now in phpbb_hook_2.php with 0 tex codes found in ' [center] here just the txt of the post [/center] '
Now in phpbb_hook_2.php with 0 tex codes found in [center] [tex] A_n = \left( {\frac{{a \cdot n^2 + b \cdot n + 22}}{{c \cdot n^2 + d \cdot n + 11}}} \right)^n :\quad a,b,c,d \in \mathbb{R}^{* + } [/tex][/center].
By the way, i cut these lines from the header because I didn't see any such line in the post pody.

For old page with more than one tex code I get lines of the form:

Code: Select all

Now in phpbb_hook_2.php with 0 tex codes found in …..
:oops:
_____________

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

Re: LaTeX support in phpBB3

Post by stevem »

I have the answer. You are using <tex>...</tex> for new posts but [tex]...[/tex] for old posts, so the old posts were not being compiled.
sisteczko wrote:8. Open the Administrative Control Panel of phpBB3 using the web interface, and under posting->BBCode usage put the

Code: Select all

[tex]{TEXT}[/tex]
and check the Display on Posting, and click Submit.
but you put
student12 wrote:in fact, no rendered image when i filled it in by

Code: Select all

<tex>{TEXT}</tex>
Last edited by stevem on Tue Feb 26, 2008 10:10 am, edited 1 time in total.

Locked

Return to “[3.0.x] MOD Requests”