On Wed, Jul 31, 2002 at 02:02:48PM -0700, lcrocker@nupedia.com wrote:
I've hacked the phpwiki code to add a new namespace [[math: ]] so you can write formulas like [[math:a^2+b^2=c^2]] or [[math:\sum_{n=0}^{\infty}\frac{1}{n}=\infty]].
The code will make TeX create an image (PNG) of the formula. Those images will be cached, they will be created only once and will be shared between articles. ( [[math:E=m c^2]] might be used on many pages ).
That's almost exactly what I had in mind; only I think it would be better for the back end to have to have a spearate process communicating with the Wiki code over IPC--the "TeX server"-- which will take formulas and return images, out of a cache if they've been rendered already, calling TeX to render them if needed. The cache will be indexed by a hash function on a canonicalized text of the expression.
The wiki end of this won't be hard. The other server is the real work. I'm afraid I can't take on that project right now, but if that server gets built, I'll be happy to call it.
Hi,
I moved this to wikitech-l since it will be much to detailed for wikipedia-l.
The code is ready. It doesn't use IPC, no client/server. It only exec's a shell script.
The PHP script creates a tempfile with suffix .tex and calls a shellscript with the name of the tempfile as a parameter.
The script - renders TeX to DVI using LaTeX - converts DVI to eps using dvips - renders eps to PNG using convert from ImageMagick - removes all tempfiles created by LaTeX
The .png has the same name as the .tex. The name is the MD5-Hash of the formula. The .png will placed in an image directory of the webserver, in my implementation it's /upload/, but should probably be different, e.g. /upload/math/.
The PHP code than adds the formula and the name of the image file to a new table in the database. Using this cache it decides whether to render a formula.
It then replaces [[math:formula]] by <img src="/upload/imagename.png" alt="formula" align="middle"> (OK, using the TeX-Formula as alt-text is not always really readable, but always better than no alt-text at all)
The only thing still to be done is preparing some TeX preamble to prevent something like
[[math:\mbox{\include{"/etc/passwd"}}]]
Alternatively, everything could be installed chroot, but this would have to include Apache and PHP and LaTeX.
The shell script looks like this:
#!/bin/sh exec >> /tmp/tex2png.log exec 2>&1 set -x cd /tmp
echo $* cat $1 echo
latex $1 dvips -E $1 convert -density 110 $1.ps $1.png cp $1.png /home/jf/wiki/phpwiki/newcodebase/upload/ chmod a+r /home/jf/wiki/phpwiki/newcodebase/upload/$1.png rm ${1}*
$1 is the hashcode of the formula.
Providing the diff of the PHP-code would take a little time - I have to remove my attempts in wiki-table-markup first.
For an example see
http://jeluf.mine.nu/jf/newcodebase/wiki.phtml?title=Triangle
but please keep in mind - it's a 486/DX2 66 with 20 MB RAM, a machine I normaly use for fetching mail only.
Regards,
JeLuF
On Thu, Aug 01, 2002 at 02:11:46AM +0200, Jens Frank wrote:
For an example see
http://jeluf.mine.nu/jf/newcodebase/wiki.phtml?title=Triangle
It looks beautiful. That is going to make a lot of the contributers on mathematics very happy. A few comments though:
I'd prefer a bit shorter and easier-to-read mark-up. Axel Boldt suggested [$ x \leq y $] and Toby Bartels $$ x \leq y $$. Since $$ already means something in LaTeX I'd prefer Axel's suggestion. Maybe we could even let [$$ x \leq y $$] be a displayed formula? There should be a difference between in-line and displayed formula.
It would be nice if we could stay close to what is done on planetmath.org so that it wouldn't be too hard to interchange write-ups. They are working with a separate preamble in which you can include extra packages. That's very nice if you want to do special stuff like commuting diagrams in category theory. However, I can see how that would complicate the implementation and one could ask if it would be worth it. At least our assumed preamble should be very similar to their default preable.
Concerning safety I think I'd prefer Lee's solution including a time-out for TeX that takes too long to compute. It's the most robust solution and other solutions like parsing (a limited subset of) TeX would probably mean that we would have to decide which subset we support which would probably turn out to be too restrictive.
-- Jan Hidders
On Thu, Aug 01, 2002 at 11:37:08AM +0200, Jan.Hidders wrote:
On Thu, Aug 01, 2002 at 02:11:46AM +0200, Jens Frank wrote:
For an example see
http://jeluf.mine.nu/jf/newcodebase/wiki.phtml?title=Triangle
It looks beautiful.
No it doesn't.
On my Konqueror with fairly big fonts all TeX-generated images are much too small and placed too low.
Screenshot of paragraph is attached.
What should be done is: * size of it should be configurable by user * they should always be vertically aligned in a way that looks nice in case of bigger or smaller fonts.
On Thu, Aug 01, 2002 at 01:58:55PM +0200, Tomasz Wegrzanowski wrote:
On my Konqueror with fairly big fonts all TeX-generated images are much too small and placed too low.
Strange, because it says 'align="middle"'. What does Konquerer do on www.planetmath.org? Do you like their set-up if you view with big and small fonts? On my IE it looks acceptable.
-- Jan Hidders
On Thu, Aug 01, 2002 at 02:16:33PM +0200, Jan.Hidders wrote:
On Thu, Aug 01, 2002 at 01:58:55PM +0200, Tomasz Wegrzanowski wrote:
On my Konqueror with fairly big fonts all TeX-generated images are much too small and placed too low.
Strange, because it says 'align="middle"'. What does Konquerer do on www.planetmath.org? Do you like their set-up if you view with big and small fonts? On my IE it looks acceptable.
http://planetmath.org/?op=getobj&from=objects&id=947
On attached screenshot first and third images (heigth 34) are aligned well, the second (heigth 37) is a bit too low, but it's acceptable.
Does TeX have some trick which would allow us to get information about how generated images should be placed in final text ? It certainly uses such algorithm internally. That might be the best solution.
But doing it the way planetmath does is still ok.
wikitech-l@lists.wikimedia.org