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)
Suggested Hosts
syd16
Registered User
Posts: 6
Joined: Fri Oct 07, 2011 4:32 pm

Re: LaTeX support in phpBB3

Post by syd16 »

Hey, if anyone's interested, im looking for some help with latex here: http://www.phpbb.com/community/viewtopi ... &t=2141552
cooch17
Registered User
Posts: 160
Joined: Mon Feb 18, 2008 4:45 pm
Location: Ithaca, NY

Re: LaTeX support in phpBB3

Post by cooch17 »

I realize this thread had been 'inactive' for a while, but wanted to resurrect it given some recent experiences using LateXRender following upgrades to php.

Specifically, with php 5.4.0, LateXrender no longer works (whereas it did just fine previously). Now, when I try to render a LaTeX expression, phpbb renders the following:
[unparseable or potentially dangerous latex formula]
Just for the information of those folks using this approach to rendering LaTeX expressions in their boards.
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: LaTeX support in phpBB3

Post by stevem »

Make sure that exec is allowed.
cooch17
Registered User
Posts: 160
Joined: Mon Feb 18, 2008 4:45 pm
Location: Ithaca, NY

Re: LaTeX support in phpBB3

Post by cooch17 »

stevem wrote:Make sure that exec is allowed.
Meaning, what? Nothing has changed on the system except an upgrade to php 5.4.0.

Also, in some subsequent tests, phpbb3 throws the following errors when I try to render a tex expression (again, it all worked *perfectly* before).
[phpBB Debug] PHP Warning: in file [ROOT]/latexrender/class.latexrender.php on line 271: copy(25db36d1550c1f2db5a5ccc3884c84aa.gif): failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/latexrender/class.latexrender.php on line 291: unlink([ROOT]/latexrender/tmp/25db36d1550c1f2db5a5ccc3884c84aa.dvi): No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/latexrender/class.latexrender.php on line 292: unlink([ROOT]/latexrender/tmp/25db36d1550c1f2db5a5ccc3884c84aa.ps): No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/latexrender/class.latexrender.php on line 293: unlink([ROOT]/latexrender/tmp/25db36d1550c1f2db5a5ccc3884c84aa.gif): No such file or directory
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: LaTeX support in phpBB3

Post by stevem »

Upgrading PHP can often reset php.ini to the default which is to not allow exec to run, and so you won't be able to run latex. Check by running this php program:

Code: Select all

<?php

$cmd="ls";
exec("$cmd 2>&1", $output);

foreach($output as $outputline){
   echo("$outputline<br>");
}

?>
That's for Linux systems - replace ls by dir in Windows. That will tell you if exec is allowed or not. If not then you need to change php.ini to allow exec in disable_functions.
cooch17
Registered User
Posts: 160
Joined: Mon Feb 18, 2008 4:45 pm
Location: Ithaca, NY

Re: LaTeX support in phpBB3

Post by cooch17 »

stevem wrote:Upgrading PHP can often reset php.ini to the default which is to not allow exec to run, and so you won't be able to run latex. Check by running this php program:

Code: Select all

<?php

$cmd="ls";
exec("$cmd 2>&1", $output);

foreach($output as $outputline){
   echo("$outputline<br>");
}

?>
That's for Linux systems - replace ls by dir in Windows. That will tell you if exec is allowed or not. If not then you need to change php.ini to allow exec in disable_functions.
Hmmm - not sure. Time stamp on php.ini hasn't been touched (still shows a date of 2010).

In the .ini file, I have the following 2 directives:

safe_mode = off
disable_functions =

As far as I understand things, this should allow exec. I would have assumed that if I wanted to shut of exec, I would have had

disable_functions=exec

but that leaving the RHS blank would allow exec (and everything else).

Any other thoughts? Your php script simply lists ll the directories off my webroot directory (i.e., /htdocs...)
cooch17
Registered User
Posts: 160
Joined: Mon Feb 18, 2008 4:45 pm
Location: Ithaca, NY

Re: LaTeX support in phpBB3

Post by cooch17 »

stevem wrote:Upgrading PHP can often reset php.ini to the default which is to not allow exec to run, and so you won't be able to run latex. Check by running this php program:

Code: Select all

<?php

$cmd="ls";
exec("$cmd 2>&1", $output);

foreach($output as $outputline){
   echo("$outputline<br>");
}

?>
That's for Linux systems - replace ls by dir in Windows. That will tell you if exec is allowed or not. If not then you need to change php.ini to allow exec in disable_functions.
Just ran

Code: Select all

<?php
if(function_exists('exec')) {
    echo "exec is enabled";
}
?>
Reports that exec is enabled. Given my last post, and the output from this php script, I'm fairly sure exec *is* enabled, meaning, the problem (latexrender not working) is due to something else.
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: LaTeX support in phpBB3

Post by stevem »

Disable file deletion at the end of class.latexrender.php and check which files have been created. Then add some code into class.latexrender.php to tell you what has happened and where things have gone wrong. For example, if latex hasn't been run there will be no log file and when you execute latex use the exec("$cmd 2>&1", $output); construction to tell you what has gone wrong.
cooch17
Registered User
Posts: 160
Joined: Mon Feb 18, 2008 4:45 pm
Location: Ithaca, NY

Re: LaTeX support in phpBB3

Post by cooch17 »

stevem wrote:Disable file deletion at the end of class.latexrender.php and check which files have been created. Then add some code into class.latexrender.php to tell you what has happened and where things have gone wrong. For example, if latex hasn't been run there will be no log file and when you execute latex use the exec("$cmd 2>&1", $output); construction to tell you what has gone wrong.
Tried the first part (disable file deletion). In /tmp, I see an .aux file, a *.tex file, and a *.log. What is truly weird is what the tex file looks like:

Code: Select all

\documentclass[10pt]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\pagestyle{empty}
\begin{document}
$x=y$
d{document}
So, instead of \end{document} its showing up as d{document}. The \en bit seems to have been chopped off, somehow/somewhere.

Suggestions on where to look? This would seem to imply it doesn't have much (if anything) to do with php changes.
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: LaTeX support in phpBB3

Post by stevem »

That's good as it might be the problem. The log file exists so latex is being run.
The new version of PHP may see \e as an escape character, so in class.latexrender.php you need to use an extra backslash. In the line
$string .= "\end{document}\n";
change it to
$string .= "\\end{document}\n";
and try again.
cooch17
Registered User
Posts: 160
Joined: Mon Feb 18, 2008 4:45 pm
Location: Ithaca, NY

Re: LaTeX support in phpBB3

Post by cooch17 »

stevem wrote:That's good as it might be the problem. The log file exists so latex is being run.
The new version of PHP may see \e as an escape character, so in class.latexrender.php you need to use an extra backslash. In the line
$string .= "\end{document}\n";
change it to
$string .= "\\end{document}\n";
and try again.

Getting closer. Escaping the final element in the wrapper (as you suggested) did the trick. Now, the .tex file is created properly, and a correct .pvi and .ps file are created.

But, the corresponding .gif isn't created. Leading to the following error:
[phpBB Debug] PHP Warning: in file [ROOT]/latexrender/class.latexrender.php on line 271: copy(5e07f1cda7e44b94e3f58ef5b67d5871.gif): failed to open stream: No such file or directory
Next? ;-) Thanks again...
stevem
Registered User
Posts: 398
Joined: Sun Aug 25, 2002 1:59 pm

Re: LaTeX support in phpBB3

Post by stevem »

That sounds like a problem with imagemagick which converts the ps file to gif. Try converting it directly using a shell command. Rename the ps file to test.ps then see if
/usr/bin/convert -density 120 -trim -transparent "#FFFFFF" test.ps test.gif
converts correctly or if there's an error message.
cooch17
Registered User
Posts: 160
Joined: Mon Feb 18, 2008 4:45 pm
Location: Ithaca, NY

Re: LaTeX support in phpBB3

Post by cooch17 »

stevem wrote:That sounds like a problem with imagemagick which converts the ps file to gif. Try converting it directly using a shell command. Rename the ps file to test.ps then see if
/usr/bin/convert -density 120 -trim -transparent "#FFFFFF" test.ps test.gif
converts correctly or if there's an error message.
Indeed, there does seem to be a *major* problem with ImageMagick. I know its installed (has been for some time). But, when I run

/usr/bin/convert -density 120 -trim -transparent "#FFFFFF" test.ps test.gif

I get the following slew of error messages:
Error: /undefinedfilename in (120x120)
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1154/1684(ro)(G)-- --dict:0/20(G)-- --dict:70/200(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 8.70: Unrecoverable error, exit code 1
Error: /undefinedfilename in (120x120)
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1154/1684(ro)(G)-- --dict:0/20(G)-- --dict:70/200(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 8.70: Unrecoverable error, exit code 1
convert: no decode delegate for this image format `test.ps'.
convert: Postscript delegate failed `test.ps'.
convert: missing an image filename `test.gif'.
I did a little digging, and the answer seems to be that the version of ImageMagick available to RHEL/CentOS 5.x machines is 'broken'. See the following

http://centos.org/modules/newbb/print.p ... SC&start=0

My machine is running said distro, and recent updates to 5.8 are probably the culprit. I'll see if I can work out a fix/workaround, and post here. So, probably is a conspiracy of two things -- the new php not handling \e (thanks for point that out), and now ImageMagick.
cooch17
Registered User
Posts: 160
Joined: Mon Feb 18, 2008 4:45 pm
Location: Ithaca, NY

Re: LaTeX support in phpBB3

Post by cooch17 »

cooch17 wrote: I did a little digging, and the answer seems to be that the version of ImageMagick available to RHEL/CentOS 5.x machines is 'broken'. See the following

http://centos.org/modules/newbb/print.p ... SC&start=0

My machine is running said distro, and recent updates to 5.8 are probably the culprit. I'll see if I can work out a fix/workaround, and post here. So, probably is a conspiracy of two things -- the new php not handling \e (thanks for point that out), and now ImageMagick.
So, downgrading to the version of ImageMagick for RHEL/CentOS 5.7 (as described in the link, in the quoted text above) did the trick. Things are now working as they did before.

However, wouldn't even have gotten this far with the patience assistance of stevem. Thanks, very much.
cooch17
Registered User
Posts: 160
Joined: Mon Feb 18, 2008 4:45 pm
Location: Ithaca, NY

Re: LaTeX support in phpBB3

Post by cooch17 »

stevem wrote: The new version of PHP may see \e as an escape character, so in class.latexrender.php you need to use an extra backslash. In the line
$string .= "\end{document}\n";
change it to
$string .= "\\end{document}\n";
and try again.
Confirmed. Dug into the chagelog for php 5.4.0. Found the following
Fixed bug #60350 (No string escape code for ESC (ascii 27), normally \e).
Bingo. So, class.latexrender.php will break with php 5.4.0, unless you add the extra backslash.
Locked

Return to “[3.0.x] MOD Requests”