Latex BBcode with phpBB3

Discussion of general topics related to the new version and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Post Reply
user99
Registered User
Posts: 63
Joined: Thu Jan 04, 2007 9:36 pm

Latex BBcode with phpBB3

Post by user99 »

Has anyone created bbCode for maths typesetting? What linux program would be best to use?

I am running successfully using MimeTex, but its image quality is not so good.

User avatar
VinDuv
Registered User
Posts: 73
Joined: Wed May 03, 2006 8:10 pm
Location: France

Re: Latex BBcode with phpBB3

Post by VinDuv »

I used phpMathPublisher, with some tweaks :
The default script returns the URL of the created image, it is not very easy to use it in a custom BBCode... I wrote a small script, imgmath.php, which directly returns the image corresponding to the math calculation given in the URL, so I can use <img src='math/imgmath.php?[URL encoded calculation]' /> for BBCode replacement of my [math] BBCode.

Code: Select all

<?php
// imgmath.php
include('mathpublisher.php');

$size = 12;

if(!$_SERVER['QUERY_STRING']) die('');
$text = str_replace('+', '%2B', $_SERVER['QUERY_STRING']);
$text = urldecode($text);

$text = preg_replace('/<!--.*(-->){0,1}/', '', $text);

$formula = new expression_math(tableau_expression(trim($text)));
$formula->dessine($size);
$path = 'img/' . (1000-imagesy($formula->image)+$formula->base_verticale+3) . md5($text).'.png';
if(!file_exists($path)) ImagePNG($formula->image, $path) or die('');
header('Content-type: image/png');
readfile($path);
?>

Chris_
Registered User
Posts: 1
Joined: Thu Sep 20, 2007 6:06 pm

Re: Latex BBcode with phpBB3

Post by Chris_ »

Hi!
VinDuv, could you explain how did you manage to URL encode math expression? Custom bbcode allows only few substitions like {TEXT}, {SIMPLETEXT} etc. {TEXT} is the one I'd like to use, because it's the only one than can contain multiple lines. Using <img src="blah/blah.cgi?{TEXT}" /> is not acceptable. What for are those <!-- --> in your example? I would be really grateful for detailed answer. Thanks in advance.

ticapix
Registered User
Posts: 1
Joined: Wed Nov 28, 2007 9:54 am

Re: Latex BBcode with phpBB3

Post by ticapix »

Hi

For those who are interested, I managed to make phpmathpublisher working with a bbcode.
You need to create a bbcode

Code: Select all

[eq]{TEXT}[/eq]
making this replacement

Code: Select all

<script type="text/javascript" src="phpmathpublisher/rendermaths.php?message={TEXT}"></script>
This way, you are able to call a remote php script via a html tag.
rendermaths.php

Code: Select all

<?php
include("mathpublisher.php");
$message = $HTTP_GET_VARS['message'];
$size = $HTTP_GET_VARS['size'];
$pathtoimg = $HTTP_GET_VARS['pathtoimg'];
if (!isset($pathtoimg))
  $pathtoimg="phpmathpublisher/img/";
if ((!isset($size)) || $size<10)
  $size=14;
if ( isset($message) && $message!='' )
  {
    $message = addslashes($message);
    $output = mathfilter($message, $size, $pathtoimg);
    echo "window.document.write('".$output."');";
  }
?>
Finally I put everything - rendermaths.php, mathpublisher.php, the directories font/ and img/ in a subfolder phpmathpublisher/ of my forum root dir.

Once done, you only need to set correctly the paths in the header of mathpublisher.php.

NB: this tip ables to call php scripts from a bbcode, so it can be extended to a lot of other uses
pierre

Maaadin
Registered User
Posts: 1
Joined: Sun Mar 23, 2008 7:49 pm

Re: Latex BBcode with phpBB3

Post by Maaadin »

First of all, sorry for writing in such an old topic, but I'm stuck!

Second of all, I'm totally new in phpbb and php, so please describe everything slowly as if you would explain it to your 2 years old sister =)

Alright, so here's my problem:

I'm tryting to implement Latex via BBCode in our phpbb3-Forum. I'm using phpmathpublisher and tried to do what ticapix wrote.
So her is what I did:

I downloaded phpmathpublisher and copied the folder into the phpbb Folder on my server. I created the rendermaths.php file and copied into the phpmathpublisher folder. I created the BBCode in the admin section and placed this code in:

Code: Select all

<script type="text/javascript" src="phpmathpublisher/rendermaths.php?message={TEXT}"></script>
Yea..... that's how far I got.... and now I'm completely lost to be honest... I have no clue what to do and hope that you guys can help me.

Best regads,

Maaadin

paxos
Registered User
Posts: 2
Joined: Thu Apr 10, 2008 5:48 pm

Re: Latex BBcode with phpBB3

Post by paxos »

This will not work for "+". If you use for example math code "x+y" the "+" will not be shown.

The reason is, that http encoding uses this char for its own encoding. Has anyone a solution for this?

ElbertF
Registered User
Posts: 583
Joined: Fri Dec 03, 2004 4:35 pm
Location: tracing..
Contact:

Re: Latex BBcode with phpBB3

Post by ElbertF »

"+" Won't be URL encoded, it's a perfectly valid character.

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: Latex BBcode with phpBB3

Post by naderman »

A + in the url normally encodes a space character.

paxos
Registered User
Posts: 2
Joined: Thu Apr 10, 2008 5:48 pm

Re: Latex BBcode with phpBB3

Post by paxos »

yeah, thats the reason its not visible in the math code

Post Reply