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.
User avatar
TheHighwayman
Registered User
Posts: 28
Joined: Wed Jun 06, 2007 5:05 pm

Re: math equations (with latex)

Post by TheHighwayman »

OK stevem,
thank you for the answer.

I'll try it and post results.

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)
User avatar
takufner
Registered User
Posts: 216
Joined: Mon Oct 23, 2006 10:39 am
Location: Rio de Janeiro - Brasil
Name: Prof. Caju
Contact:

Re: math equations (with latex)

Post by takufner »

Hi Stevem,

My first main problem was solved using the script indicated by you. Thanks.

Now, the second problem is still with me. My mimetex is not caching the images.

This is what I've done so far:

In phpbb_hook_2.php (the mimetex version) I made the changes:
1) replaced $uid by $bbcode_uid twice
2) replaced $text by $message eight times

And in includes/bbcode.php I made:

Code: Select all

}
		}
		include("/home/tutorbra/public_html/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
And I made a BBCode that does

Code: Select all

[tex]{TEXT}[/tex]
swaps to

Code: Select all

<img border="0" align="middle" alt="{TEXT}" src="http://www.tutorbrasil.com.br/cgi-bin/mimetex.cgi?{TEXT}"/>
And when I write a new post in my forum, no problem, the equation is there, but the url for the image is not from the cache, it is from the mimetex. And the cache directory (mimetex/pictures) remains empty.

I'd like to use the cache feature.

Thanks
User avatar
takufner
Registered User
Posts: 216
Joined: Mon Oct 23, 2006 10:39 am
Location: Rio de Janeiro - Brasil
Name: Prof. Caju
Contact:

Re: math equations (with latex)

Post by takufner »

Hi,

I realized that there is no mention about the files phpbb_hook_1.php and mimetex.php. And the function mimetex, in mimetex.php, is the responsible in doing such caching work, isn't?
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

in phpBB3 you only need phpbb_hook_2.php. mimetex.php is for the example and other non-phpbb programs. mimetex.php and phpbb_hook_2.php share the same code.

The caching is done in the line

Code: Select all

$command = "$mimetex_path -e ".$full_path_filename." ".escapeshellarg($mimetex_formula);
which gets mimetex to save the images in the pictures file.
For this to happen you need to check that you have

Code: Select all

$system_disabled=0;
and that $full_path_filename is correct. It comes from the line

Code: Select all

$full_path_filename = $pictures_path."/".$filename; 
and so $pictures_path must be correct near the top of phpbb_hook_2.php. I think that in your case it should be something like

Code: Select all

$pictures_path = ("/home/tutorbra/public_html/phpBB3/mimetex/pictures";
though I cannot be sure exactly where it is on your system
Also the /pictures directory must be writeable to so should be chmod 777.
User avatar
takufner
Registered User
Posts: 216
Joined: Mon Oct 23, 2006 10:39 am
Location: Rio de Janeiro - Brasil
Name: Prof. Caju
Contact:

Re: math equations (with latex)

Post by takufner »

Hi Stevem,

Thanks for your quick reply.

All this things you said are all done and all right with my code.

I recently realized that the iteration

Code: Select all

for ($i=0; $i < count($tex_matches[0]); $i++) {
Isn't iterating because count($tex_matches[0]) is always ZERO, no matter how much TeX tags I put in my message.

I discovered this puting the line:

Code: Select all

$message = count($tex_matches[0]);
for ($i=0; $i < count($tex_matches[0]); $i++) {
I think this is the problem because the $command you told me, it's inside this "for".

I am still trying to identify something else, but with this information maybe you can give me some answer...

Thank you for your patience.
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

It looks like no formula is being found. Is the line

Code: Select all

preg_match_all("#\[tex:$bbcode_uid\](.*?)\[/tex:$bbcode_uid\]#si",$message,$tex_matches);
what you have in phpbb_hook_2.php? If so, the code is not getting this far.
After this line try adding temporarily the line

Code: Select all

echo "Message is $message<br>;
That will tell you what text is being seen by phpbb_hook_2.php. You will get a whole bunch of PHP errors about headers which you can ignore (PHP is just saying it didn't expect to print text at this point) but if there is a blank message then the problem is not inside phpbb_hook_2.php.
User avatar
takufner
Registered User
Posts: 216
Joined: Mon Oct 23, 2006 10:39 am
Location: Rio de Janeiro - Brasil
Name: Prof. Caju
Contact:

Re: math equations (with latex)

Post by takufner »

Hi Stevem,

I put the echo indicated by you and discovered that the $message, in the line where the "include" was, was already without TeX tags, they were already swaped to img html tags.

Then, I put the include in other place before the "foreach" iteration:

Code: Select all

		$undid_bbcode_specialchars = false;

		include("/home/tutorbra/public_html/phpBB3/mimetex/phpbb_hook_2.php");
		foreach ($bbcodes_set as $bbcode_id)
And now the caching is working properly.

Are there some other things that this code change could do? Or this place is ok to let the "include" line?
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

bbcode.php seems to have changed probably causing the problem. There shouldn't be a problem with moving the include line since you don't want the search and replace functions altering the LaTeX code; but only trying it out will tell if there are any problems.
User avatar
takufner
Registered User
Posts: 216
Joined: Mon Oct 23, 2006 10:39 am
Location: Rio de Janeiro - Brasil
Name: Prof. Caju
Contact:

Re: math equations (with latex)

Post by takufner »

I discovered that, with the include in this place, all the parenthesis are replaced for the html code. Like this, the code

Code: Select all

[tex](x-1)[/tex]
swaps to an image like this

Code: Select all

&#40;x-1&#41;
but the cache is working fine, hehehe.

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

Re: math equations (with latex)

Post by stevem »

Fortunately that problem is easy to solve. In phpbb_hook_2.php after the line

Code: Select all

$mimetex_formula = html_entity_decode($tex_matches[1][$i]);
add the lines

Code: Select all

$mimetex_formula = str_replace("&#40","(",$mimetex_formula);
$mimetex_formula = str_replace("&#41",")",$mimetex_formula);
You can do the same for any other similar problems.
Le File
Registered User
Posts: 8
Joined: Sun Jun 08, 2008 1:57 pm

Re: math equations (with latex)

Post by Le File »

I want to say sorry first because i post to old topic, but i'm stucked with this problem until now. I want to make Latex in my forum too, but I'm still confuse with the explanation. Some question in my mind is :
1. What should i do first?
2. Must i install latex program like TexnicCenter, or somewhat?
Thanx for your explanation
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

You must have root access to your server and then install TeX, ImageMagick and Ghostscript. You would need to ask your host how to do that as every system is different. You cannot do it on a hosted system where you have no root access. What operating system does your server run?
TexnicCenter is an editor for Windows which you don't need since you are editing in phpBB.
If you don't have root access consider using an external server by using mathTeX.
Le File
Registered User
Posts: 8
Joined: Sun Jun 08, 2008 1:57 pm

Re: math equations (with latex)

Post by Le File »

My operating system is windows, and i use phpBB3.0.x, not 2.0.x. Can latexrender fit in that OS? But i'm still wonder, how the script create an image? Are you sure i shouldn't install the latex editor? Now, i use mimetex, but i can't create cgi file, how to create that? Thanx
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: math equations (with latex)

Post by stevem »

So your server (NOT your own private computer) runs Windows? Then install MiKTeX, Ghostscript and ImageMagick on it and then follow the instructions at LaTeX support in phpBB3 to get LatexRender to work in phpBB3.

Why would you want an editor on the server? TexnicCenter is not meant for internet use but on your own private computer. Also phpBB3 has its own editor where you type the messages like this and then LatexRender converts it to an image so there's no use for another editor.
Le File
Registered User
Posts: 8
Joined: Sun Jun 08, 2008 1:57 pm

Re: math equations (with latex)

Post by Le File »

Yes of course MY SERVER (web hosting) use windows. Ok i'll try later. Last questions, why you don't try to use mimetex? Can Latexrender try in localhost? Thanx
Post Reply

Return to “[2.0.x] MOD Requests”