ashishkranjan / dabr

Automatically exported from code.google.com/p/dabr
0 stars 0 forks source link

Tweet Math/Render Math on Tweets #121

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
All the modifications are contained in the attached file, but here is a 
little background:

This addition is in the twitter.php file:
---------------------------------------------------------------------
function twitter_parse_tags($input) 
{
    //Links
    $out = preg_replace_callback('#(\w+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)
(?<![.,])#is', 'twitter_parse_links_callback', $input);

//Added for rendering math images
$out = str_replace('$:','<img 
src="http://www.codecogs.com/gif.latex?',$out);
$out = str_replace(':$','" style="vertical-align:middle;" />',$out);

    //Lists (@dabr/mobile)
----------------------------------------------------------------------
That's all you need to render the math.

This uses the codecogs installation of LaTeX, which they seem quite 
willing to share, so long as you don't abuse it.  I am running my website 
on a shared hosting solution and do not have shell access to install my 
own LaTeX, but I do have mimetex, which is not as nice as LaTeX.  If you 
think this might become popular, you might consider installing LaTeX and 
serving up the math from dabr.com.

I have also attached the code for the math buttons.  These were placed 
only in the desktop.php file, though I would like to try it out on the 
other media outlets.  dabr doesn't let me get away with formating the 
buttons (width/height), so they don't look as nicely set as they should.  
Here is how they should look:  http://www.algebrahut.com/mathtype.html .  
I just need to resize the images so they are all a uniform size, then the 
buttons will line up nicely.

There was also some javascript that needs to be placed in the head section 
for show/hide and for inserting the math into the text area.  These are 
included in the attachment as well.

Thanks for letting this twitter client be open source.  I am learning alot 
from it and this would be my first contribution to an open source 
project.  It's fun trying to see what can be done.  Thanks for the 
opportunity to contribute.  I hope the simplicity of it is not 
disappointing.  :)

Original issue reported on code.google.com by dylan.fa...@gmail.com on 23 Feb 2010 at 2:54

Attachments:

GoogleCodeExporter commented 9 years ago
Fascinating. Is the $:[stuff here]:$ syntax commonly used?

I ask because it is a trivial task to add CodeCog's math rendering to Dabr's 
existing
photo services by adding this line into the $services array, around line 430 of
twitter.php:

'#\$:(.*):\$#' => 'http://www.codecogs.com/gif.latex?%s',

I'm less keen on adding the extra buttons into the live site but adding a new 
Mode
(e.g. Math mode) with these extra buttons could be possible. If not, I may
investigate creating a plugin system so people can easily add cool stuff like 
this
into their copies of Dabr without having to do too much hacking away at things.

Thanks!

Original comment by david.carrington on 23 Feb 2010 at 3:36