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
student12
Registered User
Posts: 17
Joined: Sun Jan 22, 2006 8:51 pm
Location: tif
Contact:

Re: LaTeX support in phpBB3

Post by student12 »

Unfortunately , i chick it now
the first field has the correct tags: [tex]{TEXT}[/tex]

the second field is empty,

it was contains <tex>{TEXT}</tex> but I deleted it early.
_____________

typeshige
Registered User
Posts: 1
Joined: Mon Feb 18, 2008 5:19 am

Re: LaTeX support in phpBB3

Post by typeshige »

Hi. Please tell me if this is the wrong area. This is my first post and I'm brand-new to phpBB. I'm working on a project for a client that needs LaTeX support. After reading the excellent tips here, I got it working, but the gif output is essentially unreadable.

Does anyone have any tips on figuring out why it outputs so poorly? It's probably a font issue...


I'm using Gentoo Linux and TeXLive, GS all basically out of the box with as many fonts as I could install.

Thanks,
Shige

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

Now , it is working

Post by student12 »

Dear stevem, it is working far all posts, new and old. :D

But unfortunately, there is some issue
the tex code rendered to incorrect symbols
for example

Code: Select all

[tex]\begin{array}{l}
 \mathop {\lim }\limits_{n \to \infty } \left( {\frac{{\;\;\;a_n \;\;\;}}{{\frac{1}{n}}}} \right) = 0\quad  \Rightarrow \quad  \\ 
  \\ 
 \forall \varepsilon  > 0\;;\;\exists \;n_\varepsilon   \in N\;:\forall n > n_\varepsilon   \Rightarrow \left( {\frac{{\;a_n \;}}{{\frac{1}{n}}}} \right) < \varepsilon  \Rightarrow  \\ 
  \\ 
 for\;\varepsilon  = 1 \Rightarrow a_n  < \frac{1}{n} \\ 
 \end{array}[/tex]
Renderd to:
Image

and

Code: Select all

[tex]e^{m(m + 1)}  \ge \left[ {(m + 1)!} \right]^2[/tex]
Renderd to:
Image

also

Code: Select all

[tex]S = \left( {\sqrt 2  - 1} \right)^k[/tex]
Renderd to:
Image

it seems latexrender convert ( to 40; and convert ) to 41;
i don't understand why this happen?

regards
_____________

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

Re: LaTeX support in phpBB3

Post by stevem »

The brackets ( and ) are being converted by the forum somewhere. But it is easy to repair; all you have to do is convert back again before using LaTeX.
After the line

Code: Select all

$latex_formula = html_entity_decode($tex_matches[1][$i]);
add

Code: Select all

$latex_formula = str_replace("&#40;","(",$latex_formula);
$latex_formula = str_replace("&#41;",")",$latex_formula);

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

Thanks So Much

Post by student12 »

i did your suggestion, and latex is working fine. 8-)

thank you very much dr. stevem for your efforts and time that you have spent for help.
_____________

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

Re: LaTeX support in phpBB3

Post by student12 »

what about if i want to enforce all tex codes to rendered as /displaystyle formulas ?
_____________

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

Re: LaTeX support in phpBB3

Post by stevem »

After the line

Code: Select all

$latex_formula = html_entity_decode($tex_matches[1][$i]);
add

Code: Select all

$latex_formula = "\displaystyle ".$latex_formula;

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

Re: LaTeX support in phpBB3

Post by texasmath »

(Sorry about the delay. Flu's been beating me up something fierce.)

Thanks for all the help, I appreciate it.

Now I'm getting [unparseable or potentially dangerous latex formula]. I commented out the unlink commands in class.latexrender.php and it's creating a .aux, .dvi (which appears correct), .log, and .ps file in the tmp folder, but no picture in the pictures folder.

I do have convert installed, and the path is linked to where the which command lists it at.

Any ideas? I appreciate all the help.

TDP.

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

Re: LaTeX support in phpBB3

Post by stevem »

As there's no gif in /tmp it looks as if ImageMagick can't find Ghostscript which is not uncommon, particularly if the Ghostscript binary gs is not in /usr/bin. ImageMagick does this behind the scenes so the workaround is to add Ghostscript's directory to the path. Try this solution posted at http://sixthform.info/steve/wordpress/?p=34#comments

Code: Select all

// class.latexrender.php 

// begin of workaround
// extending the PATH environmental variable
$oldpath = getenv(”PATH”);
$where_gs_is = “/usr/sfw/bin”;
if ($oldpath) { $where_gs_is .= “:$oldpath”;}
putenv(”PATH=$where_gs_is”);
// end of workaround

// imagemagick convert ps to image and trim picture
$command = $this->_convert_path.” -density “.$this->_formula_density.
” -trim -transparent “#FFFFFF” “.$this->_tmp_filename.”.ps “.
$this->_tmp_filename.”.”.$this->_image_format;
$status_code = exec($command);

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

Re: LaTeX support in phpBB3

Post by texasmath »

...particularly if the Ghostscript binary gs is not in /usr/bin...

Code: Select all

$ which gs
/usr/bin/gs
Nevertheless, I tried (both) of the suggestions on his page (after changing all the "pretty quotes" to real quotes, and changing my path to /usr/bin/), and still have the [unparsable...] error.

I'm now getting these error messages on the top of my page:

Code: Select all

[phpBB Debug] PHP Notice: in file /var/www/texasmath.org/forum/latexrender/class.latexrender.php on line 281: copy(dd6210eb85556bb9343eca2a99d195ba.gif) [function.copy]: failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3391: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3393: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3394: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3395: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
I do appreciate all the help. It's probably something fairly minor that I'm missing out on.

TDP

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

Re: LaTeX support in phpBB3

Post by stevem »

Basically al the error messages are saying is that it can't find gif so can't copy it, then PHP objects to showing those error messages!
If gs in /usr/bin there shouldn't have been a problem. The thing to do now is try a convert from the command line and see what error messages you get. CD to the /tmp diretcory and change the name of one of the long-named .ps files to test.ps. Then use

Code: Select all

convert -density 120 -trim -transparent #FFFFFF test.ps test.gif
If that doesn't work try taking bits of the command out (like -trim etc) to see what is causing the problem.
Maybe it is the same as http://sixthform.info/steve/wordpress/?p=34#comments
http://sixthform.info/steve/wordpress/?p=34#comments wrote:I was getting the same symptoms and I discovered it was because my convert doesn’t support the -trim option. I was able to get it to work by replacing “-trim” with “-crop 0×0″ in the line defining $command.

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

Re: LaTeX support in phpBB3

Post by texasmath »

I tried both commands, and it told me there were problems with the options:

Code: Select all

$ convert -density 120 -crop0x0 -transparent #FFFFFF test.ps test.gif
convert: unrecognized option `-crop0x0'.

$ convert -density 120 -trim -transparent #FFFFFF test.ps test.gif
convert: missing an image filename `-transparent'.
So I tried a straight convert, with no options, just to see what's going on:

Code: Select all

$ convert test.ps test.gif
ERROR: /undefined in #
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1126/1686(ro)(G)--   --dict:0/20(G)--   --dict:81/200(L)--
Current allocation mode is local
Current file position is 2
ESP Ghostscript 815.02: Unrecoverable error, exit code 1
ERROR: /undefined in #
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1126/1686(ro)(G)--   --dict:0/20(G)--   --dict:81/200(L)--
Current allocation mode is local
Current file position is 2
ESP Ghostscript 815.02: 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'.
Any ideas where to go from here?

Thanks for all the help so far.
TDP

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

Re: LaTeX support in phpBB3

Post by stevem »

There's either a problem with the test.ps file or with Ghostscript. Do you have a link to test.ps so I can check if it's OK? Otherwise this looks like a problem with Ghostcript and in that case it may be worth asking in a Ghostscript or ImageMagick forum.

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

Re: LaTeX support in phpBB3

Post by texasmath »

I got convert to work properly. It was a bad ps file. Now the .gif files are being put in the proper directory, but aren't being embedded correctly.

I've got a sample message set up here: http://texasmath.org/forum/viewtopic.php?f=13&t=870

Any ideas would be very much appreciated.

TDP

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

Re: LaTeX support in phpBB3

Post by stevem »

At least it's getting close.
You have an extra /phpbb in the variable $latexrender_path_http in phpbb_hook_2.php which probably says $latexrender_path_http = "/forum/phpbb/latexrender";
Change it to $latexrender_path_http = "/forum/latexrender"; and all should be well.

Locked

Return to “[3.0.x] MOD Requests”