\sqrt not working

\sqrt not working

by Suresh kumar -
Number of replies: 8
Kindly look at the two objective questions written in GIFT format. Neither moodle 1.5 nor moodle 1.7 import these questions correctly. Am I missing something?

//////////////// GIFT FORMAT ASCII FILE///////////////////
the standard deviation of a uniformly distributed random variable
from 2 to 14 is{
=$$2\sqrt{3}$$
~$$4\sqrt{3}$$
~$$2\sqrt{2}$$
~$$7\sqrt{0.3}$$
}

$$C$$ and $$D$$ are two independent Gaussian random variables. Then
$$\sqrt{C^{2} + D^{2}}$$ is{
=Rayleigh
~Gaussian
~uniformly distributed
~binomial
}random variable

////////////////////////////////// end of file

Thanks
suresh
Average of ratings: -
In reply to Suresh kumar

Re: \sqrt not working

by Jeff Forssell -
I tried importing your file into my 1.7 and it didn't work. But I discovered that my TeX filter wasn't working at all there. So I tried my 1.6 Moodle, but it didn't work there either.

So I tried to recreate one of the questions directly in Moodle and exporting it as GIFT:

See the included file

So seems like you must escape all your { and }. (But I haven't tried importing it yet. So no guarantees!)


In reply to Jeff Forssell

Re: \sqrt not working

by Suresh kumar -
Hi Jeff Forssell,
Thanks for the idea. But I am surprised, why moodle doc doesnot say that, latex symbols must be escaped...
suresh
In reply to Suresh kumar

Re: \sqrt not working

by Jeff Forssell -
I used to be surprised about things that weren't documented too. But now I'm not surprised. Moodle is so complex and rapidly changing and mainly built up by people that aren't employed to do it. And those few that are paid have bugs, feature requests, ... waiting for them piled in the bugtracker.

We have to help each other with the documentation! It is all in WIKI form. It is easy to create a login that is needed if you are to contribute.

It is best to write something you have discovered as soon as possible, without worrying whether it is perfect. If you see something that is wrong or incomplete in the DOCs fix it!

I've now gone to http://docs.moodle.org/en/Import_questions#GIFT
and written this:

If you want to use curly braces, { or }, or equal sign, =, in a GIFT file (for example in a math question including TeX expressions) you must "escape" them by preceding them with a \ directly in front of each { or } or =. It is possible to use a replace program/macro/editor filter to do this conversion before importing to Moodle.

Log in and make it better! Copy good things from the forums into the docs!

In reply to Suresh kumar

Re: \sqrt not working

by John Isner -
Jeff is correct. The curly braces in LaTeX markup confuse the GIFT parser. The curly braces must be escaped with a backslash ('\'). You must also escape equals signs ('='). I have a small sed script which I use on Linux (or on Windows with Cygwin) that will do the escaping for you (you don't want to do this manually!). I use it just before uploading. It requires that you format your GIFT file in a certain way. If you're interested, I'll post it with instructions.

IMHO GIFT import without support for LaTeX is another example of the "digitial divide" that exists between math and the other disciplines that use Moodle.
In reply to John Isner

Re: \sqrt not working

by Suresh kumar -
Hi John Isner,
Thanks. I would appreciate if you could post your sed script. But I am surprised why the escaping of latex symbol is not documented in moodle GIFT docs...
suresh
In reply to Suresh kumar

Re: \sqrt not working

by John Isner -
Suresh,
The need to escape special characters is documented. Click the help icon next to the import button (the small orange question mark), then click on the link "More info about the GIFT format." You will see the following:

Special Characters ~ = # { } :
These symbols ~ = # { } control the operation of this filter and cannot be used as normal text within questions. Since these symbols have a special role in determining the operation of this filter, they are called "control characters." But sometimes you may want to use one of these characters, for example to show a mathematical formula in a question. The way to get around this problem is "escaping" the control characters. This means simply putting a backslash (\) before a control character so the filter will know that you want to use it as a literal character instead of as a control character.


Here is my sed script:

s/=/\\=/g
s/~/\\~/g
s/#/\\#/g
s/{/\\{/g
s/}/\\}/g
s/\t\\=/\t=/
s/\t\\~/\t~/
s/\t\\#/\t#/
s/\\{$/{/
s/\\{\r$/{/
s/^\\}/}/

If you are on a Unix machine, you can run sed from the command line:

sed -f scriptfile infile > outfile

where scriptfile is a file containing the above script, infile is the original GIFT file (with special characters unescaped) and outfile is the new GIFT file (with special characters escaped). Of course you will import outfile into Moodle.

If you're on Windows, you can install Cygwin which gives you all the Unix commands, including sed. Then you can run the same command in Cygwin.

To use the script requires that you format infile as follows.
  1. Always put the opening curly brace (which precedes the answer(s)) at the very end of a line
  2. always put the closing curly brace (which follows the answer(s)) at the very beginning of a new line
  3. start each answer on a new line preceded by a tab
From your original post I see that you are already following these rules except for (3).
In reply to John Isner

Re: \sqrt not working

by Jeff Forssell -
I notice that I didn't think of these nice (?) help links. They are often pretty good and they're always very close at hand. (One of the features I liked from my first contact with Moodle!)

Sometimes I've found that there have been mistakes in the help link which depend on a local language pack, so it can be good to change to English to see if there is anything different or more there.
In reply to John Isner

Re: \sqrt not working

by Suresh kumar -
Thanks Forssell, Isner

I understand better now. Thanks for the script also

suresh