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)
Get Involved
texasmath
Registered User
Posts: 12
Joined: Tue Feb 19, 2008 2:59 am

Re: LaTeX support in phpBB3

Post by texasmath »

Great! That (and fixing the fact I use two different address systems -- forum.texasmath.org and http://www.texasmath.org/forum) did the trick.

Now, one last question...

I have a lot of old posts that were written in LaTeX. These are now nonfunctioning, and you can see the sourcecode from their entries. How do I go about fixing all these old posts?

Eternal thanks for getting me this far!

TDP.

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

Re: LaTeX support in phpBB3

Post by stevem »

That shouldn't happen since phpBB doesn't know the difference between old and new posts, unless you've changed the type of tags that you are using, as student12 did earlier who had put <tex>{TEXT}</tex> instead of [tex]{TEXT}[/tex] in the Admin Control Panel.

texasmath
Registered User
Posts: 12
Joined: Tue Feb 19, 2008 2:59 am

Re: LaTeX support in phpBB3

Post by texasmath »

I do appreciate all the help.

A representative post of "old LaTex" is http://www.texasmath.org/forum/viewtopic.php?f=7&t=603. They both use the [tex] and [/tex] that I'm currently using.

TDP

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

Re: LaTeX support in phpBB3

Post by stevem »

Did correct bbcode.php so that the line is in the right place

Code: Select all

include("/var/www/phpBB3/latexrender/phpbb_hook_2.php");
and only occurs once as detailed by sisteczko here? Originally you had it in two places both of which were wrong.

texasmath
Registered User
Posts: 12
Joined: Tue Feb 19, 2008 2:59 am

Re: LaTeX support in phpBB3

Post by texasmath »

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("/var/www/texasmath.org/forum/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;
	}
}

?>
Is it in the wrong place? I put it in line 119 instead of line 118 since line 118 puts it as the last line in the scope of the foreach ($bbcodes_set as $bbcode_id) {} statement.

TDP

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

Re: LaTeX support in phpBB3

Post by stevem »

It now seems to be in the right place. What exactly have you done in the Admin Control Panel? You could also try some of the echo commands in phpbb_hook_2.php as detailed for student 12 in the thread above to see what is happening.

texasmath
Registered User
Posts: 12
Joined: Tue Feb 19, 2008 2:59 am

Re: LaTeX support in phpBB3

Post by texasmath »

I edited phpbb_hook_2.php as above, adding

Code: Select all

   echo "Now in phpbb_hook_2.php processing $message<br>";
right before the $latex = new LatexRender... command. I now get this from the post above (http://www.texasmath.org/forum/viewtopic.php?f=7&t=603)

Code: Select all

Now in phpbb_hook_2.php processing American Mathematics Contest & American Invitational Mathematics Examination. See http://www.unl.edu/amc for more information Note:USAMO/IMO-level questions need to go in the Olympiad section.
Now in phpbb_hook_2.php processing American Mathematics Contest & American Invitational Mathematics Examination. See http://www.unl.edu/amc for more information Note:USAMO/IMO-level questions need to go in the Olympiad section.
Now in phpbb_hook_2.php processing A "fez" is a hat worn in Morocco
Now in phpbb_hook_2.php processing oh.. i thought you were telling me i couldnt do guess and check. i guess i just assume everything you tell me is negative.
Now in phpbb_hook_2.php processing

    mathpimp wrote:Are you guys just creating [tex]x[/tex] to solve the problem? Where'd it come from?

I created [tex]m,n[/tex] from the information that came from the problem Basically if [tex]a^5=b^4[/tex], then [tex]a=\sqrt[5]{b^4}[/tex] and then since [tex]c^3=d^2, c=\sqrt[3]{d^2}[/tex] So [tex]a-c=\sqrt[5]{b^4}-\sqrt[3]{d^2}=-19[/tex]. This can be exploited by the difference of two squares factoring. Meaning [tex](\sqrt[5]{b^2}+\sqrt[3]{d})(\sqrt[5]{b^2}-\sqrt[3]{d})=-19[/tex]. Thus [tex]\sqrt[5]{b^2}+\sqrt[3]{d}=19,\sqrt[5]{b^2}-\sqrt[3]{d}=-1[/tex] Then solving you get [tex]2\sqrt[5]{b^2}=18,b=243[/tex] the rest is pretty simple I created [tex]m,n[/tex] to avoid these disgusting radicals
Now in phpbb_hook_2.php processing Okay yeah, that second one is how I started solving it. Then I looked and saw a solution had already been posted. So I was like m, n, wtf? You certainly made it look a lot cleaner, it would be a pain to Latex it up with all those radicals and junk.
Now in phpbb_hook_2.php processing guess and check suc-kers
Now in phpbb_hook_2.php processing Yeah, that works. But is it really the manly way to get it done? Just messin with you Brad. Yeah had I actually been alive and a high school student in 1985 that's probably how I would have done it but I find it more fun to work it out algebraically, since we aren't in a testing situation here.
Now in phpbb_hook_2.php processing don't attack my mathliness/manliness
[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:35)
[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:35)
[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:35)
[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:35)
My BBCodes in the ACP only have tex, which has the following usage:

Code: Select all

[tex]{TEXT}[/tex]
Any ideas?
TDP.

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

Re: LaTeX support in phpBB3

Post by stevem »

That tells us that phpbb_hook_2.php has been found and has seen the message. But phpBB isn't adding the $bbcode_uid required for all tags, so won't be processed.

Are bbcodes turned on for the old posts? Is there one with bold or italic or code etc tags. Are these turned into bold etc?

One temporary workaround that may work (I haven't tested it) is to add the line

Code: Select all

preg_match_all("#\[tex\](.*?)\[/tex\]#si",$message,$tex_matches);
below the previous version with :$bbcode_uid in it.
But it would be better to find out why :$bbcode_uid is not being added to old messages.

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

Re: LaTeX support in phpBB3

Post by stevem »

I have just seen elsewhere on this forum that not adding :$bbcode_uid is a common problem with conversion from phpbb2 to phpbb3, so it isn't a bug in LatexRender :)
At http://phpbbacademy.com/community/viewt ... =62&t=4082 there is a script that will go through all the old posts and reparse them and hence solve the problem.

texasmath
Registered User
Posts: 12
Joined: Tue Feb 19, 2008 2:59 am

Re: LaTeX support in phpBB3

Post by texasmath »

Excellent. The phpbbacademy link seemed to solve the problem.

Thanks so much for your patience and help!

Tony David Potter

User avatar
muggins
Registered User
Posts: 1183
Joined: Fri Feb 22, 2008 5:12 pm
Location: Texas
Name: Donovan
Contact:

Re: LaTeX support in phpBB3

Post by muggins »

I was using mimetex as successfully as any, but one of my users wants chemical diagrams.

I followed the excellent instructions by sisteczko above, and everything parses correctly except this snip from his post, which displayed fine in mimetex:

Code: Select all

At this point, in order to draw a structural formula involves using a bunch of line statements.

Take, for example, Benzene.

\picture(100,100){ (50,50){\circle(60)} (31,12){\line(1,0){39}} (93,50){\line(-3,-5){23}} (93,50){\line(-3,5){23}} (31,87){\line(1,0){39}} (8,50){\line(3,5){23}} (8,50){\line(3,-5){23}}}

Gives us:
[unparseable or potentially dangerous latex formula]

I am new to LaTeX, but I suspect the '\includepackage' lines in class.latexrender.php are the issue. I simply don't know what to add. I have this:

Code: Select all

    function wrap_formula($latex_formula) {
        $string  = "\documentclass[".$this->_font_size."pt]{".$this->_latexclass."}\n";
        $string .= "\usepackage[latin1]{inputenc}\n";
        $string .= "\usepackage{amsmath}\n";
        $string .= "\usepackage{amsfonts}\n";
        $string .= "\usepackage{amssymb}\n";

// Added packages
	$string .="\usepackage{amschemso}\n";
	$string .="\usepackage{bpchem}\n";
	$string .="\usepackage{chemarrow}\n";
	$string .="\usepackage{chemcompounds}\n";
	$string .="\usepackage{chemcono}\n";
// Added packages end

        $string .= "\pagestyle{empty}\n";
        $string .= "\begin{document}\n";
        $string .= "$".$latex_formula."$\n";
        $string .= "\end{document}\n";

        return $string;

    }

I know this isn't the place for me to learn LaTeX, but a swift kick wouldn't hurt me any if I have done something wrong. ;) Help?

Edit: I have the same error with:

Code: Select all

Take, for example, Benzene.

\begin{picture}(100,100){ (50,50){\circle(60)} (31,12){\line(1,0){39}} (93,50){\line(-3,-5){23}} (93,50){\line(-3,5){23}} (31,87){\line(1,0){39}} (8,50){\line(3,5){23}} (8,50){\line(3,-5){23}}}\end{picture}

Gives us:
[unparseable or potentially dangerous latex formula]

Muggins

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

Re: LaTeX support in phpBB3

Post by stevem »

There are 2 problems here.
1. Firstly, the latex code is not correct. Here is the correct version:

Code: Select all

\begin{picture}(100,100) 
\put(50,50){\circle{60}}
\put(31,12){\line(1,0){39}}
\put(93,50){\line(-3,-5){23}}
\put(93,50){\line(-3,5){23}}
\put(31,87){\line(1,0){39}} 
\put(8,50){\line(3,5){23}} 
\put(8,50){\line(3,-5){23}}
\end{picture}
which requires \begin{picture} ...\end{picture} plus \put commands

2. The other problem is that large circles aren't normally allowed. To allow them you need to use the pict2e package, so add to classlatexrender.php:

Code: Select all

$string .="\usepackage{pict2e}\n";
One other thing. When typing chemical equations etc you might find the mhchem package useful. Plenty of examples in the documentation and here.

User avatar
muggins
Registered User
Posts: 1183
Joined: Fri Feb 22, 2008 5:12 pm
Location: Texas
Name: Donovan
Contact:

Re: LaTeX support in phpBB3

Post by muggins »

Thank you very much for a quick and helpful reply. I was sure the error was due to my stupidity, and it was! :lol:

My chemist thanks you, too!

Edit: I tried using your corrected formula and get the same 'unparseable' error again. Back to the books, I guess.
Muggins

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

Re: LaTeX support in phpBB3

Post by stevem »

I re-checked the code and it works fine but it's possible that you may need to add \par before \begin{picture} to force latex to use the correct mode.

User avatar
muggins
Registered User
Posts: 1183
Joined: Fri Feb 22, 2008 5:12 pm
Location: Texas
Name: Donovan
Contact:

Re: LaTeX support in phpBB3

Post by muggins »

I'll try it as soon as I get un-buried. TY.

Edit: Same. I get php errors that go away too quickly to just copy, but there are messages about 'cannot modify header' at the top of the page before the 'unparseable or dangerous' error shows in the post.

sigh...
Muggins

Locked

Return to “[3.0.x] MOD Requests”