Can't get ASCIIMathML to work

74 views
Skip to first unread message

tomas.s...@gmail.com

unread,
May 21, 2007, 2:17:53 AM5/21/07
to TiddlyWiki
Hi!!

I have copied the ASCIIMathML.js file to the same folder as my
TiddlyWiki, added the reference to the javascript file in the shadow
tiddler MarkUpPreHead:

<script type="text/javascript" src="ASCIIMathML.js"></script>

I'm running FireFox, but my equation insertions does not render at
all.

Other tiddlyWikis using the same javascript renders, but not my own!!

Help is appriciated!!

Regards,
Tomas Sandkvist
Sweden

Eric Shulman

unread,
May 21, 2007, 2:51:24 AM5/21/07
to TiddlyWiki
> I have copied the ASCIIMathML.js file to the same folder as my
> TiddlyWiki, added the reference to the javascript file in the shadow
> tiddler MarkUpPreHead:

Tiddler names are highly case sensitive... check the capitalization:
"MarkupPreHead" (correct) versus "MarkUpPreHead" (incorrect)

HTH,
-e
Eric Shulman
TiddlyTools / ELS Design Studios


Jose

unread,
May 31, 2007, 11:26:29 AM5/31/07
to TiddlyWiki

On 21 May, 08:17, "tomas.sandkv...@gmail.com"

<tomas.sandkv...@gmail.com> wrote:
> Hi!!
>
> I have copied the ASCIIMathML.js file to the same folder as my
> TiddlyWiki, added the reference to the javascript file in the shadow
> tiddler MarkUpPreHead:
>
> <script type="text/javascript" src="ASCIIMathML.js"></script>

That is not enough. You have to call the function AMProcessNode at the
appropiate point, since this is the function which renders the
equations.

The appropiate point to put this call depends on the TiddlyWiki
version. I was unable to insert this call without externally modifying
the html file which contains the wiki. I tried to do it via plugin,
but I was unable to (my understanding of the TiddlyWiki architecture
is too insufficient). However, by directly modifying the html source,
I got it running without problems

The modification is very simple, if you want to try it too. You only
have to open your wiki.html file with an ascii editor, search for the
string "prototype.refreshTiddler" (in my file is at line 3834, but I
guess this may be different in your case), and then go to the end of
that function, and insert one line containing:

if (AMprocessNode) AMprocessNode(tiddlerElem,false);

just before the last statement of the function, which reads: return
tiddlerElem;

I hope it works for you too. If you discover an alternative method to
do so without editing the html, please share.

Regards,
--JL Diaz

Xavier Vergés

unread,
May 31, 2007, 5:53:33 PM5/31/07
to TiddlyWiki
Jose, take a look at the first lines of Eric's
http://www.tiddlytools.com/#RearrangeTiddlersPlugin
You'll see the way to change the refreshTiddler behaviour as a plugin
that does not make you edit things whenever the TW version is updated

-Xavier

Eric Shulman

unread,
May 31, 2007, 6:16:50 PM5/31/07
to TiddlyWiki
Here's some code that will add your ASCIIMath processing tweak to the
TW core refreshTiddler() function:
----------------------
Story.prototype.AMHijack_refreshTiddler =
Story.prototype.refreshTiddler;
Story.prototype.refreshTiddler = function(title)
{
var tiddlerElem=this.AMHijack_refreshTiddler.apply(this,arguments);
if (AMprocessNode) AMprocessNode(tiddlerElem,false);
}
----------------------

Jose

unread,
Jun 1, 2007, 5:55:18 AM6/1/07
to TiddlyWiki
On 1 Jun, 00:16, Eric Shulman <elsdes...@gmail.com> wrote:
> Here's some code that will add your ASCIIMath processing tweak to the
> TW core refreshTiddler() function:
> ----------------------
> Story.prototype.AMHijack_refreshTiddler =
> Story.prototype.refreshTiddler;
> Story.prototype.refreshTiddler = function(title)
> {
> var tiddlerElem=this.AMHijack_refreshTiddler.apply(this,arguments);
> if (AMprocessNode) AMprocessNode(tiddlerElem,false);}
>
> ----------------------

Thank you very much! It worked.

I tried already something similar:

Story.prototype.refreshTiddler_old =Story.prototype.refreshTiddler;
Story.prototype.refreshTiddler = function(title,template,force)
{
return this.refreshTiddler(title,template,force);
if (AMprocessNode) output.text=AMprocessNode(output.text,false);
}

I can see that this is not exactly what you did, but I expected this
to work. However, what I got instead was all my tiddlers rendered as
black boxes. Why? I was unable even to undo the change (I had to edit
the html file to remove this plugin tiddler).

--
Jose

Jose

unread,
Jun 1, 2007, 5:59:37 AM6/1/07
to TiddlyWiki
On 1 Jun, 11:55, Jose <jld...@gmail.com> wrote:
Ops, sorry. I pasted the wrong code in the previous post. This is what
I intented to write:

> I tried already something similar:
>
> Story.prototype.refreshTiddler_old =Story.prototype.refreshTiddler;
> Story.prototype.refreshTiddler = function(title,template,force)
> {

> var tiddlerElem= this.refreshTiddler(title,template,force);
> if (AMprocessNode) AMprocessNode(tiddlerElem, false);
> return tiddlerElem;
> }

--Jose

Eric Shulman

unread,
Jun 1, 2007, 6:47:11 AM6/1/07
to TiddlyWiki
> > Story.prototype.refreshTiddler_old =Story.prototype.refreshTiddler;
> > Story.prototype.refreshTiddler = function(title,template,force)
> > {
> > var tiddlerElem= this.refreshTiddler(title,template,force);
> > if (AMprocessNode) AMprocessNode(tiddlerElem, false);
> > return tiddlerElem;
> > }

ummm...

in your hijacked refreshTiddler(), you make a call to
this.refreshTiddler()... which is the SAME hijacked function... which
resulting in *infinite recursion*

What you want to do in your hijacked refreshTiddler() is to make a
call to the *original* saved function, "this.refreshTiddler_old",
instead of:

var tiddlerElem= this.refreshTiddler(title,template,force);

you need to write:

var tiddlerElem= this.refreshTiddler_old(title,template,force);

However, this is NOT good programming form, as it will break if the
params used by the core definition of refreshTiddler() change in
future releases. Fortunately, there is a special "apply()" method
available on all javascript functions that lets you pass-through
whatever params were used to call your hijack:

var tiddlerElem= this.refreshTiddler.apply(this,arguments);

(note: both "this" and "arguments" are automatic variables that are
defined by the JS runtime environment... )

One thing that your code DOES do properly that my quick code snippet
missed was to actually return the "tiddlerElem" value. The original
refreshTiddler() returns this value, so the hijack MUST do the same,
or any calling functions that expect that return value will break.

HTH,
-e

Jose

unread,
Jun 1, 2007, 7:33:04 AM6/1/07
to TiddlyWiki

On 1 Jun, 12:47, Eric Shulman <elsdes...@gmail.com> wrote:
> > > Story.prototype.refreshTiddler_old =Story.prototype.refreshTiddler;
> > > Story.prototype.refreshTiddler = function(title,template,force)
> > > {
> > > var tiddlerElem= this.refreshTiddler(title,template,force);
> > > if (AMprocessNode) AMprocessNode(tiddlerElem, false);
> > > return tiddlerElem;
> > > }
>
> ummm...
>
> in your hijacked refreshTiddler(), you make a call to
> this.refreshTiddler()... which is the SAME hijacked function... which
> resulting in *infinite recursion*

Oh, of course! This was also a typo... I deleted my original code and
I was trying to reconstruct it from memory, but I introduced some
errors doing so.

> What you want to do in your hijacked refreshTiddler() is to make a
> call to the *original* saved function, "this.refreshTiddler_old",

Yes, this is what I did. I tried again my reconstructed code, and now
it works! I'm unable to recall what I did wrong. Nevertheless, it is
encouraging to see that I was on the good track.

> However, this is NOT good programming form, as it will break if the
> params used by the core definition of refreshTiddler() change in
> future releases. Fortunately, there is a special "apply()" method
> available on all javascript functions that lets you pass-through
> whatever params were used to call your hijack:
>
> var tiddlerElem= this.refreshTiddler.apply(this,arguments);

Aha. Very interesting. Thank you for explaining it!

> One thing that your code DOES do properly that my quick code snippet
> missed was to actually return the "tiddlerElem" value. The original
> refreshTiddler() returns this value, so the hijack MUST do the same,
> or any calling functions that expect that return value will break.

Aha. In fact it was a surprise to me that your code worked without
returning "tiddlerElem", but the inners of TiddlyWiki are still a
mistery to me, so I assumed it was ok.

Thanks again,
--Jose

Reply all
Reply to author
Forward
0 new messages