## 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.
MB_MathemaTeX
Registered User
Posts: 50
Joined: Wed Feb 15, 2006 10:52 am
Contact:

### Re: math equations (with latex)

stevem wrote:1. changes $...$ to $$...$$ or
On posting I suppose.
It's not a really good solution for me because I want use my phpbb2 database (with dollars) and also for reading or editing a message, dollars are more usefull.
stevem wrote:2. adds in a harmless [ b][ /b] somewhere. If that's not good enough then you could put [ b]...[ /b] round the $...$ as it won't have any effect on the image.
On posting also I suppose.

I think it is better to work on viewing.
It may be possible to convert $et $$in tex bbcode before the test on the bitfield and modify this at this moment. But not easy for me. MB :: MathemaTeX :: MB_MathemaTeX Registered User Posts: 50 Joined: Wed Feb 15, 2006 10:52 am Contact: ### Re: math equations (with latex) I give you my solution. I can use formula or$$formula$$(for centering). If the user need a normal dollar he must use \$ instead of $(like in tex). The syntax with $ans$ is not possible. So, I have made 3 new files in the latexrender directory : phpbb_hook_mathematex_functions.php : Code: Select all <?php function texify_message($message)
{
$message = " " .$message;

$char = preg_split('//',$message, -1, PREG_SPLIT_NO_EMPTY);
$nb = count($char);

$i=0;$bbcode_actif=0;
$latex_actif=0;$dollar_count=0;
$ddollar_count=0; while ($i <= ($nb-1) ) { if ($char[$i]=="<") { if ($char[$i+1]=="c" &&$char[$i+2]=="o" &&$char[$i+3]=="d" &&$char[$i+4]=="e" &&$char[$i+5]==">" ) {$bbcode_actif=1;
}
if ($char[$i+1]=="/" && $char[$i+2]=="c" && $char[$i+3]=="o" && $char[$i+4]=="d" && $char[$i+5]=="e" && $char[$i+6]==">")
{
$bbcode_actif=0; } } if ($char[$i]=="[") { if ($char[$i+1]=="t" &&$char[$i+2]=="e" &&$char[$i+3]=="x" && ($char[$i+4+11]=="]" or$char[$i+4]=="]")) {$latex_actif=1;
}

if ($char[$i+1]=="/" && $char[$i+2]=="t" && $char[$i+3]=="e" && $char[$i+4]=="x" && ($char[$i+5+11]=="]" or $char[$i+5]=="]"))
{
$latex_actif=0; } } elseif ($bbcode_actif==1)
{
}

elseif ($char[$i]=="$") { if ($char[$i-1]=="\\") { if ($latex_actif==1)
{
}
else
{
$char[$i-1]="";
}
}

else
{
if ($char[$i+1]=="$") { if ($ddollar_count==0)
{
$char[$i] = "<DIV ALIGN='CENTER'>"; $char[$i+1] = "$$"; // ou [center] ddollar_count=1; latex_actif=1; } else { char[i] = "$$"; $char[$i+1] = "</DIV>"; // ou [/center]
$ddollar_count=0;$latex_actif=0;
}
}
else
{
if ($dollar_count==0) {$char[$i] = "$$"; dollar_count=1; latex_actif=1; } else { char[i] = "$$";$dollar_count=0;
$latex_actif=0; } } } }$i=$i+1; }$message = implode($char); return substr($message, 1);
}

function bbcode_second_pass_tex($message,$bbcode_uid = '')
{
$message = " ".$message;
$message = preg_replace("#$tex$(.*?)$/tex$#si", "[tex:$bbcode_uid]\\1[/tex:$bbcode_uid]",$message);
include("/yourpath/phpBB3/latexrender/phpbb_hook_2.php");
$message = str_replace(':' .$bbcode_uid, '', $message); return substr($message, 1);
}

?>
phpbb_hook_mathematex_posting.php :

Code: Select all

<?php

include_once("/yourpath/phpBB3/latexrender/phpbb_hook_mathematex_functions.php");

if ( eregi('$',$preview_message ) or eregi('[tex]', $preview_message ) ) {$preview_message = texify_message($preview_message);$preview_message = bbcode_second_pass_tex($preview_message,$post_data['bbcode_uid']);
}

?>
phpbb_hook_mathematex_viewtopic.php :

Code: Select all

<?php

include_once("/yourpath/phpBB3/latexrender/phpbb_hook_mathematex_functions.php");

if ( eregi('$',$message ) or eregi('[tex]', $message ) ) {$message = texify_message($message);$message = bbcode_second_pass_tex($message,$row['bbcode_uid']);
}

?>
Now, 2 modifications of the phpBB3 files !

In viewtopic.php line 1239 :

Code: Select all

include("/yourpath/phpBB3/latexrender/phpbb_hook_mathematex_viewtopic.php");
In posting.php line 1021 :

Code: Select all

include("/yourpath/phpBB3/latexrender/phpbb_hook_mathematex_posting.php");
I think that the function texify_message may be optimized (if you have suggestions) ... but it works.
MB :: MathemaTeX ::
trashbox
Registered User
Posts: 53
Joined: Wed Aug 22, 2007 9:25 pm

### Re: math equations (with latex)

Hi.

Can I use this MOD methods in phpBB3 RC5?

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

### Re: math equations (with latex)

It certainly works with phpBB3, though I haven't tried RC5. See http://www.phpbb.com/community/viewtopic.php?p=2669402
trashbox
Registered User
Posts: 53
Joined: Wed Aug 22, 2007 9:25 pm

### Re: math equations (with latex)

stevem wrote:It certainly works with phpBB3, though I haven't tried RC5. See http://www.phpbb.com/community/viewtopic.php?p=2669402
stevem, It really worked like a charm with my phpBB3 RC5!
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
trashbox
Registered User
Posts: 53
Joined: Wed Aug 22, 2007 9:25 pm

### Re: math equations (with latex)

Hi.

Is there a way to implement in phpBB3 a javascript copy to clipboard, similar to the LatexRender Demo do?

Code: Select all

<u>Result</u><br><br>Example Text:<br />
This is just text but <a href="javascript:void(0)">
<img src='/demo/pictures/d21848cdd835abcb491be1f151e9b6c6_1188847842.gif' title='\sqrt{2}' alt='\sqrt{2}' border=0 align=absmiddle onclick="newWindow=window.open('/demo/latexcode.php?code=%5Csqrt%7B2%7D','latexCode','toolbar=no,location=no,scrollbars=yes,resizable=yes,status=no,width=375,height=100,left=200,top=100');"></a>

It could be just clicking in the image, without the popup window.

Or, an alternative to forum's user easily copy the formula, maybe a Mod?

Here's the popup source code:

Code: Select all

<HTML>
<TITLE>LaTeX Code</TITLE>
<SCRIPT TYPE="text/javascript">
<!--
window.focus();
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">

function Copy()
{
text="\\frac {43}{12} \\sqrt {43}";
window.clipboardData.setData("Text", text);
}

</SCRIPT>
<BODY BGCOLOR=#E5E5E5>
<center><tt>\frac {43}{12} \sqrt {43}</tt>
<P>
<BUTTON onclick="Copy();">Copy to Clipboard</BUTTON>
</center>
</BODY>
</HTML>

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
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

### Re: math equations (with latex)

The problem with the copy to clipboard function used in the demo is that it only works in IE. I was unable to find at the time code that was guaranteed to work in all browsers on all operating systems. I don't know if, since then, someone has published code that works.
MB_MathemaTeX
Registered User
Posts: 50
Joined: Wed Feb 15, 2006 10:52 am
Contact:

### Re: math equations (with latex)

Hello, I have a problem with the cache directory (pictures) with phpBB3 and Latexrender.
The directory become really big (more than 1GB in one week) and I don't understand why. I have not found in the code where the cache directory is cleaned. But the cache directory wasn't so big with phpBB2.
Some ideas ?
MB :: MathemaTeX ::
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

### Re: math equations (with latex)

I see no reason why phpBB3 should behave differently to phpBB2. I presume you mean the \pictures directory? Something else must be using the cache directory or else the images are too large for some reason. Have a look at the directory and see what is there - it should consist only of gif or png files and each of them should be no more than a few KB - a really large picture would be less than 40KB. These pictures aren't deleted so they don't have to be regenerated.

On the other hand if you mean the \tmp directory, this should be empty and this is cleared via the 6 lines starting unlink at the end of class.latexrender.php. Perhaps they were commented out during testing?
MB_MathemaTeX
Registered User
Posts: 50
Joined: Wed Feb 15, 2006 10:52 am
Contact:

### Re: math equations (with latex)

Yes I have 30.000 files with an average size less than 2KB. It's not the problem.
Sorry, it was a bug without any link with latexrender.
MB :: MathemaTeX ::
Anakim
Registered User
Posts: 6
Joined: Fri Sep 14, 2007 1:54 pm

### Re: math equations (with latex)

Hi all,

I'd like to install latexrender on my v.3rc5 phpBb forum.. I follow all the instruction and i also red the 30 pages of this topic(ouch) and i try a lot of things, but it still don't work..
In phpbb_hook_2.php, how should i fill the paths ? These are mine :

Code: Select all

$latexrender_path = "http://univ-mad.info/phpBB3/latexrender";$latexrender_path_http = "/www/phpBB3/latexrender";
This is the "tree" of my ftp :

Moreover, in bbcode.php, i don't know what type of path do I put in the include line.. this is mine..

Code: Select all

include("http://univ-mad.info/phpBB3/latexrender/phpbb_hook_2.php");

I set the latexrender, pictures and tmp chmod to 755 and create a bbcode in the control panel.
Still, here are the errors I have when I'd like to write something in TeX :

Code: Select all

Fatal error: Cannot instantiate non-existent class: latexrender in /home.10.7/anakimin/www/phpBB3/latexrender/phpbb_hook_2.php on line 35
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4209: Cannot modify header information - headers already sent by (output started at http://univ-mad.info/phpBB3/latexrender/phpbb_hook_2.php:3)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4211: Cannot modify header information - headers already sent by (output started at http://univ-mad.info/phpBB3/latexrender/phpbb_hook_2.php:3)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4212: Cannot modify header information - headers already sent by (output started at http://univ-mad.info/phpBB3/latexrender/phpbb_hook_2.php:3)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4213: Cannot modify header information - headers already sent by (output started at http://univ-mad.info/phpBB3/latexrender/phpbb_hook_2.php:3)
Thank you so much for your help.
P.S : I'm sorry for my bad english.. I'm french :p

Anakim.

Edit 1 : http://www.univ-mad.info/phpBB3/latexre ... render.php gives me a blank page.. How does it mean ?
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

### Re: math equations (with latex)

Anakim wrote:

Code: Select all

$latexrender_path = "http://univ-mad.info/phpBB3/latexrender";$latexrender_path_http = "/www/phpBB3/latexrender";
Moreover, in bbcode.php, i don't know what type of path do I put in the include line.. this is mine..

Code: Select all

include("http://univ-mad.info/phpBB3/latexrender/phpbb_hook_2.php");

You are confusing the URL (which is the web address starting http) with the path on the server. Only $latexrender_path_http should use http, everything else should be the path on your server. So you should have:$latexrender_path = "/home.10.7/anakimin/www/phpBB3/latexrender";
$latexrender_path_http = "http://univ-mad.info/phpBB3/latexrender"; and in bbcode.php it should be include("/home.10.7/anakimin/www/phpBB3/latexrender/phpbb_hook_2.php"); Anakim wrote:I set the latexrender, pictures and tmp chmod to 755 and create a bbcode in the control panel. /pictures and /tmp must be set to 777 as the program needs to write to these directories. Anakim wrote:http://www.univ-mad.info/phpBB3/latexre ... render.php gives me a blank page.. How does it mean ? That's correct as class.latexrender.php doesn't write anything; it makes the pictures. It is phpbb_hook_2.php that puts them on the page. Anakim Registered User Posts: 6 Joined: Fri Sep 14, 2007 1:54 pm ### Re: math equations (with latex) First thank you for your quick reply, I follow all your instructions and edit the concerned lines. But now, these errors appears : Code: Select all [phpBB Debug] PHP Notice: in file /home.10.7/anakimin/www/phpBB3/latexrender/class.latexrender.php on line 289: unlink(/d33cd31292d1c1ad19dc1ba1e99b482d.aux) [function.unlink]: No such file or directory [phpBB Debug] PHP Notice: in file /home.10.7/anakimin/www/phpBB3/latexrender/class.latexrender.php on line 290: unlink(/d33cd31292d1c1ad19dc1ba1e99b482d.log) [function.unlink]: No such file or directory [phpBB Debug] PHP Notice: in file /home.10.7/anakimin/www/phpBB3/latexrender/class.latexrender.php on line 291: unlink(/d33cd31292d1c1ad19dc1ba1e99b482d.dvi) [function.unlink]: No such file or directory [phpBB Debug] PHP Notice: in file /home.10.7/anakimin/www/phpBB3/latexrender/class.latexrender.php on line 292: unlink(/d33cd31292d1c1ad19dc1ba1e99b482d.ps) [function.unlink]: No such file or directory [phpBB Debug] PHP Notice: in file /home.10.7/anakimin/www/phpBB3/latexrender/class.latexrender.php on line 293: unlink(/d33cd31292d1c1ad19dc1ba1e99b482d.gif) [function.unlink]: No such file or directory [phpBB Debug] PHP Notice: in file /includes/functions.php on line 4209: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3720) [phpBB Debug] PHP Notice: in file /includes/functions.php on line 4211: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3720) [phpBB Debug] PHP Notice: in file /includes/functions.php on line 4212: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3720) [phpBB Debug] PHP Notice: in file /includes/functions.php on line 4213: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3720) " No such file or directory " ? An other permission problem ? >_< Thanks.. Edit : I'm looking to class.latexrender.php and it seems to be the function cleanTemporaryDirectory().. is the function trying to delete non existent files ? Edit2 : When putting these 6 lines into // , i have this error : Code: Select all [unparseable or potentially dangerous latex formula] and only ceea7e8913020d5945fbc728ec98538b.tex in the tmp directory .. stevem Registered User Posts: 398 Joined: Sun Aug 25, 2002 1:59 pm ### Re: math equations (with latex) That means that latex isn't running. Check that the line var$_latex_path = "/usr/bin/latex";
in class.latexrender.php is the correct path for latex.
Check also in php.ini that the exec() command is allowed.
Anakim
Registered User
Posts: 6
Joined: Fri Sep 14, 2007 1:54 pm

### Re: math equations (with latex)

stevem wrote:That means that latex isn't running. Check that the line
var \$_latex_path = "/usr/bin/latex";
in class.latexrender.php is the correct path for latex.
Check also in php.ini that the exec() command is allowed.
latex isn't running ? I don't understand .. What is that path for latex ? The latexrender directory ?
Should I have an executable ?