Asciisvg

Asciisvg

by Björn Isebaert -
Number of replies: 16

Hi!

I'm using Moodle 1.9 and have installed the Asciimath-filter, which works fine. However, unless I didn't understand everything correctly, I thought this filter was able to create svg graphics? Could someone help me out with the syntax used to create such graphics? I have MathPlayer and Adobe SVGviewer installed.

(I hardly know anything of math (I'm a teach of Latin and Greek), but I'm setting up a test environment for our school, and am trying out different math filters.)

Many thanks in advance!

Average of ratings: -
In reply to Björn Isebaert

Re: Asciisvg

by Björn Isebaert -

I forgot to add: I've tried using e.g. agraph plot(sin(x)) endagraph but I get no graph. The graphs on http://mathcs.chapman.edu/~jipsen/math/index.php/ASCIIMathML/ASCIIMathGraphs.html display fine, though. So I guess I did something wrong? Asciimath is working fine for the rest.

In reply to Björn Isebaert

Re: Asciisvg

by Mauno Korpelainen -

Try if these example ASCIIsvg figures work:

\begin{graph} width=300; height=200; ymin=-1.5; line((-4,-1),(4,3)); \end{graph}

\begin{graph} width=200; height=200; xmin=-10; xmax=10; xscl=1; ymin=-10;ymax=6; plot((2-sin(x))/(2+sin(x))); \end{graph}

\begin{graph} xmin=-6.3; xmax=6.3; xscl=1; plot(x*sin(1/x),null,null,1000); width=200; height=200; border=25; xmin=-1; xmax=6; xscl=1; ymin=-1; plot(sin(x)+2.5); a = [0,0]; b = [5,5]; marker = "dot"; line(a,b); text(b,"b",aboveleft) ; stroke = "red"; path([a,[0,5],b,[5,0]]) ; stroke = "green"; marker = "none"; curve([a,[.25,0],[.5,.5],[1,1],[1.5,1.5]]) ; stroke = "blue"; circle([5,0],1); ellipse([0,5],1,2); stroke = "purple"; rect([0,0],[2,2],null,.5,1) ; marker = "arrowdot"; line(a,[5,0]);\end{graph}

\begin{graph} width=200; height=200; xmin=-6.3; xmax=6.3; xscl=1; fill="blue"; fillopacity=0.5; sector([0,0],[5,0],[0,5] ,1); fill="red"; fillopacity=0.5; sector([0,0],[3.53, 3.53],[-3.53,3.53],2); \end{graph}

In reply to Mauno Korpelainen

Re: Asciisvg

by Björn Isebaert -

Thanks for the quick reply! I've reinstalled the filters and the SVG viewer, and now it works - except for the third example: I get an error:

TypeError 'doc' is empty or no an object -2146823281 'doc' is empty or not an object

(translated from Dutch)

Strange ...

In reply to Björn Isebaert

Re: Asciisvg

by Björn Isebaert -
Another correction (sorry): I figured out the problem lies with the fact that I choose an Essay-question to try everything: apparently, graphs don't work in Essay questions?
In reply to Björn Isebaert

Re: Asciisvg

by Marc Grober -
I think one problem is that there are some issues when it comes to using asciimathml and asciisvg via the php filter with various quiz modules.

You may want to reference asciimathml via meta.php (Mauno posted the changes necessary) and turn off the filter. This results in asciimath working in the message block and in the quiz module and I think results in a bit quicker performance.
In reply to Marc Grober

Re: Asciisvg

by Björn Isebaert -
Thanks again for the quick reply! I tried to find the code from Mauno but I'm a little confused. Could you point me to the right place? Also, I'm not using the standard Moodle theme, does this matter?
In reply to Björn Isebaert

Re: Asciisvg

by Marc Grober -
You will have a meta.php in your theme's directory and it will look something like the code below....
Note the inclusion of the two script stanzas. Just make sure the second points to the correct directory.

<script type="text/javascript">
_editor_skin = "xp-blue"; // If you want use a skin, add the name (of the folder) here
_editor_lang = "en"; // And the language we need to use in the editor.
var mathcolor = "black"; // You may change the color the formulae are displayed (default: red)
var mathfontfamily = "Arial"; //and the font (default: serif, which is good I think)
</script>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/editor/htmlarea/plugins/Equation/ASCIIMathML.js"></script>
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpsthemewww ?>/standard/styles_ie7.css" />
<![endif]-->
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpsthemewww ?>/standard/styles_ie6.css" />
<![endif]-->
In reply to Marc Grober

Re: Asciisvg

by Björn Isebaert -

Hmm ... I'm using the Knowledge Library-theme from Themza, and there's no meta.php-file in the directory, so I first switched to the standard theme and edited meta.php and made sure the referenced directory was right, also disabled the filter in the Moodle admin section, but then I got a problem in IE7: when I open the question, the MathPlayer splash screen coms up, but nothing appeared, and when I tried to resize the window, IE7 froze, so I had to end it via the task manager. In Firefox 3, it worked fine though, and indeed faster.

Since there's no meta.php-file in the Knowledge Library-directory, I suppose the theme refers to meta.php of the standard theme?

(Thanks for your support, anyway: I've been testing several math editors for Moodle now, and if I had known how easy Asciimath was, I hadn't bothered with others: I surely hope it will be implemented in future builds of Moodle!)

In reply to Björn Isebaert

Re: Asciisvg

by Mauno Korpelainen -

It depends on two settings in theme config.php:

$THEME->metainclude = true;

When this is enabled (or not set!) then Moodle will try to include a file meta.php from this theme into the <head></head> part of the page.

 $THEME->standardmetainclude = true;

 When this is enabled (or not set!) then Moodle will try to include a file meta.php from the standard theme into the <head></head> part of the page.

So if you want to use extra meta tags for all themes place the tags to standard theme meta.php and make sure that standardmetainclude is true in theme config.php - otherwise place tags to custom theme meta.php and make sure that metainclude in custom theme config.php is not false...

In reply to Mauno Korpelainen

Re: Asciisvg

by Björn Isebaert -

Thanks, Mauno, but the problem persists. Here's what I did:

- added $THEME->metainclude = true; to the config.php of the custom theme

- created a meta.php file with the <script>-sections of the code posted by Marc (but with references to the correct asciimath-directory in my setup).

In reply to Björn Isebaert

Re: Asciisvg

by Mauno Korpelainen -

IE does not obviously understand some part of the 3rd example (sorry!)

\begin{graph} xmin=-6.3; xmax=6.3; xscl=1; plot(x*sin(1/x),null,null,1000); width=200; height=200; border=25; xmin=-1; xmax=6; xscl=1; ymin=-1; plot(sin(x)+2.5); a = [0,0]; b = [5,5]; marker = "dot"; line(a,b); text(b,"b",aboveleft) ; stroke = "red"; path([a,[0,5],b,[5,0]]) ; stroke = "green"; marker = "none"; curve([a,[.25,0],[.5,.5],[1,1],[1.5,1.5]]) ; stroke = "blue"; circle([5,0],1); ellipse([0,5],1,2); stroke = "purple"; rect([0,0],[2,2],null,.5,1) ; marker = "arrowdot"; line(a,[5,0]);\end{graph}

It also looks like IE can stop responding (it keeps sending the alert message) due this kind of unexpected error with the fallback version of asciimathml - the old non fallback version of asciimathml.js gave the same error but only once.

Using only Firefox with asciisvg or asciimathml may be safer...IE has never had and probably will never have sufficient support for svg in any form even with SVG Viewer installed.

Edit: Just tested taking away

xmin=-6.3; xmax=6.3; xscl=1; plot(x*sin(1/x),null,null,1000);

and IE did not show the error. This is again one of those mysterious IE issues.

In reply to Mauno Korpelainen

Re: Asciisvg

by Björn Isebaert -

Indeed, the third example now works fine ... I wish I could say that all students at our school use Firefox, but ... alas!

We did have a meeting today, and the possibilities of asciimath exceed the teachers' expectations!

In reply to Björn Isebaert

Re: Asciisvg

by Marc Grober -
Sorry I have not been more active but here in Anchorage it is the end of the quarter for a college I teach at, beginning of the semester at another college I teach at and the start of the tear for the local public school district for some of whose teachers I provide Moodle services... and it has been a bit hectic ;=}

I am glad things are working! If you are using the fallback code that I have posted then yes there are some things that need to be fixed and I am going to have to work with Mauno to make sure I understand what may have happened to your usage.

Yes, asciimath is wonderful and I encourage you, based on the sentiments you have expressed here to VOTE to include asciimath as a core Moodle 2 technology and a complement to DragMath. See this forum link for details!
http://moodle.org/mod/forum/discuss.php?d=102954&parent=455471

Firefox is SOOOOO simple because the fonts can easily be installed and you need nothing additional to do SVG but d.svg installed in the same directory. Additionally, if you have looked about you have noted that asciimath comes with a calculator and you can use that as a source to actually construct lots o stuff (one example is EqEd, the asciimathml equation editor, which is included with xinha in Mauno dropin xinharepla replacement for htmlarea (plug, plug, plug)

However, because not everyone is using firefox (yet) I think it important that Moodle users have a simple solution that includes fallback when the browser is unable to do the MathML, for whatever reason. Its for that reason I am trying to find the time to finish the fiddling I am doing with David Lippman's fallback script so that a) users only get one warning per session, b) the warning simply indicates what needs to be installed (if the browser will support MathML/SVG with incremental installs) and advises that asciimathml will fall back to using mimetex or mathtran c) and admins have adequate details so that they can install via theme so as to avoid conflicts in other modules and speed processing s well as point the fallback at an appropriate mimetex or mathtran server.

Frankly, I am disappointed that Moodle .org does not use it for Moodle (you can post a tracker request to that end)

In any event, while some of the asciimath code can be quite confusing, you will see if you look that you can change the delimiter tokens (your versin should use <amath>...</endamath>, <agraph> and <endagraph>, as well as <`>...<`> and <$>...<$> (I am using "<" and ">" for illustration purposes only, asciimathml does not use this style of xml tag) the /$ not the same as /$/$ (the former used to tell asciimath to parse tex, the latter being ignored by asciimath) . SO, you can fiddle about with tokens and the symbol tables and just generally have a ball.
In reply to Marc Grober

Re: Asciisvg

by Björn Isebaert -

There's one thing I noticed: on our Belgian Azery keyboards, we have the single 'straight' quotes (') on our keyboard, not `, which reduces confusion.

I posted a short comment on the tracker forum. It surprises me that Moodle still has no extended native math support that is easily understandable. Even our oldest math teacher understood the basics immediately ...

In reply to Björn Isebaert

Re: Asciisvg

by shaun english -
Hi, I came accross this thread while geting ready to write something about asciisvg and internet explorer.

Anyway it got me thinking- mainly because like you I can't force my students to use Firefox. Yes IE is not great but it shouldn't be that bad. So having a closer look at that equation.

\begin{graph} xmin=-6.3; xmax=6.3; xscl=1; plot(x*sin(1/x),null,null,1000); width=200; height=200; border=25; xmin=-1; xmax=6; xscl=1; ymin=-1; plot(sin(x)+2.5); a = [0,0]; b = [5,5]; marker = "dot"; line(a,b); text(b,"b",aboveleft) ; stroke = "red"; path([a,[0,5],b,[5,0]]) ; stroke = "green"; marker = "none"; curve([a,[.25,0],[.5,.5],[1,1],[1.5,1.5]]) ; stroke = "blue"; circle([5,0],1); ellipse([0,5],1,2); stroke = "purple"; rect([0,0],[2,2],null,.5,1) ; marker = "arrowdot"; line(a,[5,0]);\end{graph}

I got that pop up error in IE but it still drew a graph. When compared to firefox's version they were exactly the same. But then I realised that neither had drawn the first plot.

So is IE just being more correct by notifying that there is a problem where FF just ignores it and moves on.

Anyway I believe that this graph statement should not have two versions of xmax and xmin, and I would think it is at least best practise to define the graph area before plotting anything. If you take out the first set as they are over-riddent by the second set, and move the first plot statement so it is after the scale statements i.e.

\begin{graph} width=200; height=200; border=25; xmin=-1; xmax=6; xscl=1; ymin=-1; plot(x*sin(1/x),null,null,1000); plot(sin(x)+2.5); a = [0,0]; b = [5,5]; marker = "dot"; line(a,b); text(b,"b",aboveleft) ; stroke = "red"; path([a,[0,5],b,[5,0]]) ; stroke = "green"; marker = "none"; curve([a,[.25,0],[.5,.5],[1,1],[1.5,1.5]]) ; stroke = "blue"; circle([5,0],1); ellipse([0,5],1,2); stroke = "purple"; rect([0,0],[2,2],null,.5,1) ; marker = "arrowdot"; line(a,[5,0]);\end{graph}

it now works in both IE and firefox. (although it did take about 40 seconds more to load in IE than firefox.

regards
Shaun

ps - I too think asciimathml is a great little script. Been using it since moodle1.5. What I was going to write about was the difficulty I have in getting graphs to display at all from moodle to IE. Way back then it was a small bug in asciimathml if I remember. Anyway I upgrading to 1.9 and again could not get graphs to show in IE. I have finally got it to work but I had to actually set the full path to d.svg in asciimathml and voila graphs now work correctly. (don't reply to this problem here as I will now go back and start a new thread about it)

In reply to shaun english

Re: Asciisvg

by Marc Grober -
Shaun,

There is actually a good deal of work being done on this. Mauno has been working hard on development as has David Lippman. I hope to post a stable version of asciimathml 2.0.x with fallback and instructions soon and I think that will be followed by a neat little package for tinyMCE thast includes everything but the kitchen sink,

If you are interested, Peter Jipsen started a google group for asciimath at http://groups.google.com/group/asciimath