Okay, you only need to add '-bg Transparent' to the dvipng command in the Ruby script to get it to have a transparent background. I think. I haven't tested it. The antialiasing is messed up for me but I think that's just because I have an older version of dvipng (version 1.5), and it's hardly noticeable on a light background anyway. (By the way, the antialiasing is messed up on mathurl.com as well.)
Anyway, I wrote up a bash script based on the idea above which will turn latex code into the bbcode with an image. This requires latex, dvipng, and openssl.
- Code: Select all
#!/bin/bash
latex -halt-on-error -output-directory /tmp \
'\documentclass[12pt]{article}' \
'\pagestyle{empty}' \
'\begin{document}' \
'\[' \
"$1" \
'\]' \
'\end{document}' > /dev/null
dvipng -gamma 2 -z 9 -T tight -bg Transparent -o /tmp/article.png /tmp/article.dvi > /dev/null
echo -n '[img]'
echo -n 'data://image/png;base64,'
openssl enc -A -a < /tmp/article.png
echo -n '[/img]'
rm -f /tmp/article.aux /tmp/article.log /tmp/article.dvi /tmp/article.png
- Code: Select all
> latex2bbcode '0=e^{i\pi}+1'
[img]data://image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEwAAAARCAMAAABAWbowAAAANlBMVEX///8ZGRkJCQkxMTEkJCSQkJAAAAAEBASpqakBAQEQEBDExMRkZGTh4eFRUVF5eXlAQED///8pVmCYAAAAAXRSTlMAQObYZgAAANRJREFUOMvNkt0OwiAMhTuhUn4KvP/TWsAoy8bA6IW9WAhrvp4eDsBieYbflfLwl8Upizgnla8bc0pxZkhgB8kHGKI4bJUVxF03kxZiaQXd32F3jKEiLMnHzOy9MYLPsBu6k4nll7+XowvjTCCKCRt60ATmGoYNNjRDyTKyoj+RPoH5/Kqn1CgusRq83KfKrM5ZHd+6znPd0AajBovnLLRXmToog3txw1C9ofea1LWsw3QSr8woi7UlLMNYMygah5VrNCYwzJtt9g276yxaW/PbOkTvAez4CDOxjqqXAAAAAElFTkSuQmCC[/img]

It's fairly easy to change it to make it spit out html, or just the URI, or whatever.
Obviously, this isn't appropriate for IM conversations (the URIs are huge), but it might be better for forums without TeX support, since all the data is there, rather than on some other server.