Topic: Math Code Interpreter

Hi, again...
This is quite an old idea I fealt should be resurrected. Sometimes it could be useful to display formulas and such and to do it with ascii-graphics is not always such a good idea. So I thought it might be a good idea to incorporate such a mod for punBB, especially for Universities and the like. The initial idea was to use LaTeX2HTML as an engine for creating gifs that are displayed on the forum (in simple words). This could be done I guess, since php works in a fire-forget manner (right?), so that the first time someone enters a formula, a message will be displayed to the user; "please wait while processing your formula(s)" or something and then the resulting gif will be sent to a image-cache (eg; /img/formulas/) which then can be pruned at the same time as the posts are pruned. The html-files produced, among with other gifs (like "next", "prev" and "home" -buttons) are then immediately removed of course.

Any thoughts on this idea?

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

2 (edited by Razmooze 2004-06-19 19:37)

Re: Math Code Interpreter

I have tried to experiment with LaTeX2HTML but it seems it (or I) doesn't work properly. So I have been thinking about converting from .tex to .gif the following way:

tex -> dvi -> ps -> gif

however since I get the image of the whole page, I want to (auto)crop the image. Does anyone know a way to do this, by using GhostScript (or something else available on most unix/linux-systems)?

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

3 (edited by Razmooze 2004-06-21 01:43)

Re: Math Code Interpreter

Ok... I have it almost figured it out by now. That is, the formula to image conversion part. However there is just a tiny problem left sad. I use the convert command from ImageMagick in order both to trim the excess white canvas around the formula, and to convert the ps file to a png-file. However nohting appears to be generated. I've looked virtually everywhere for answers (Google, usenet, php.net, etc...) but didn't find much. However I found a norwegian smile thread on usenet with the same(?) problem. It seems that convert is dependent on the library-file libdpstk.so.5, but I've failed to add the path in the environmental variable LD_LIBRARY_PATH.
The code I've made looks like this:

<?php

$oldld = getenv('LD_LIBRARY_PATH');
$newld = "/lib:/usr/lib:/usr/openwin/lib";
if ($oldld) $newld .= ":$oldld";
putenv("LD_LIBRARY_PATH=$newld");
echo getenv("LD_LIBRARY_PATH")."<BR>";

$FNAME = 'formula';

$cmd[0]="/usr/ed-pkg/sup.phc/b/binh/latex ".$FNAME.".tex";
$cmd[1]="/usr/ed-pkg/sup.phc/b/binh/dvips -f ".$FNAME.".dvi > ".$FNAME.".ps";
$cmd[2]="/usr/ed-pkg/sup.phc/b/binh/convert -trim ".$FNAME.".ps ".$FNAME.".png";
$cmd[3]="rm *.dvi";
$cmd[4]="rm *.log";
$cmd[5]="rm *.aux";

exec($cmd[0]);
exec($cmd[1]);
//exec($cmd[2]);
passthru($cmd[2]." 2> /dev/stdout");
exec($cmd[3]);
exec($cmd[4]);
exec($cmd[5]);

?>

and the error I get is:

ld.so.1: convert: fatal: libdpstk.so.5: open failed: No such file or directory

This is quite frustrating >:(
any hints would be appreciated!


Edit: I've updated the code above a little. I found that the libdpstk.so.5 library exists under the /usr/openwin/lib/ directory. However it didn't solve anything. It still doesn't understand where the library/ies are. *sigh*

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

4

Re: Math Code Interpreter

If you want to use mathml instead of gifs check out itex2mml or asciimath (just google for them).

Hadley

Re: Math Code Interpreter

Mmmm... nah... mathml seems to complicated to use compared to LaTeX (which I've decided to use, mainly due to its versatility) and the results from asciimath doesn't look good enough IMHO. hmm

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

6 (edited by jchristophm 2004-10-07 09:32)

Re: Math Code Interpreter

I realize this thread has gotten a little old, but I found a pretty simple solution for punBB. Mimetex parses a LaTeX math expression and emits the corresponding gif image on-the-fly. It is a separate program that doesn't use TeX or its fonts in any way. It's just one cgi that you put in your site's cgi-bin directory. More at http://www.forkosh.com/mimetex.html.

Because the punBB code is soooo easy to understand and work with, I was able to get LaTeX support on my board using mimetex and adding only two lines of code to parser.php.

Here's what you do: download mimeTex from the URL above and compile it. Upload the cgi file into your cgi-bin directory. Open parser.php and add the following lines of code:

207         '#\[email=(.*?)\](.*?)\[/email\]#',
208         '#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#s',
209    ADD  '#\[tex\](.*?)\[/tex\]#');

217           '<a href="mailto:$1">$2</a>',
218               '<span style="color: $1">$2</span>',
219    ADD      '<img src="http://ilovephysics.com/cgi-bin/mimetex/mimetex.cgi?$1">');

That's it!

Do you love physics? :) http://www.ilovephysics.com
Interested in Internet Marketing? http://www.keyliberty.com

Re: Math Code Interpreter

Nice :)

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Math Code Interpreter

hmm... I followed these instructions but it didn't quite work. Almost!

at my test forum everything goes thru without error except the picture does not appear. any ideas?

Re: Math Code Interpreter

wow I just realized how old this thread is. hmm...

10 (edited by capitol 2006-04-08 18:33)

Re: Math Code Interpreter

I just wrote some code to integrate LatexRender from http://www.mayer.dial.pipex.com/tex.htm with punBB, its just a quick hack but it caches the formulas and produces a little bit nicer output (depending on the fonts used). If anyone wants it i could produce a patch against 1.2.11 and post.

Re: Math Code Interpreter

hello capitol, i am very interested in your patch against 1.2hello capitol, i am very interested in your patch against 1.2.11, because I'd like to integrate a maths option in my forum. Thanx

Re: Math Code Interpreter

bump

Sorry to ask this, where I can find the mod for this?

13

Re: Math Code Interpreter

Look at this french contribution: Punbb with mimetex cache

14 (edited by Razmooze 2006-07-12 02:44)

Re: Math Code Interpreter

Humm.. ok, seems that cgi script solves it quite nicely.

Should've mentioned this much earlier: I've already solved the issues I had and the result is available as the LaTeX Mod which is available on punres since some time back.

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

Re: Math Code Interpreter

Tucks wrote:

Look at this french contribution: Punbb with mimetex cache

So I tried using this tutorial. I am new to the environment. I'm trying to set up tex compatibility with punBB using mimetex on a solaris 10 server.

I called the following command:
gcc -static -DAA -DREFERER=\"xxx.yyyy.zzzz.edu\" -DCACHEPATH=\"../esc/latex/pictures/\" mimetex.c gifsave.c -lm -o latex.cgi

CGI is supported.

In the root there are two folders, esc and mimetex.
the latex and pictures folders are in esc and I am compiling from the mimetex folder. I have made pictures 777 access for now.

When I run the gcc command above I get the following error:
ld: fatal: library -lm: not found
ld: fatal: library -lc: not found
ld: fatal: library -lc: not found
ld: fatal: File processing errors. No output written to latex.cgi
collect2: ld returned 1 exit status

any ideas why this may be happening?

thanks in advance

Re: Math Code Interpreter

3 year old thread, lol.  Just post a new topic with a proper subject.

Re: Math Code Interpreter

Fracture wrote:

3 year old thread, lol.  Just post a new topic with a proper subject.

done