Writing mathematic equations..

Writing mathematic equations..

by Frank Park -
Number of replies: 30
Alright. So as you know, I have been trying to get LaTeX to work on our site. As of now, we are only displaying mimetex. We learned that we need to install Latex on our server for latex to work. Marc Grober suggested we use either ascii math or mathjax..

The problem is, we have all of our questions and equations written in LaTeX form, between $$. Does ascii math or math jax use double dollar signs? Other than latex/mimetex, what uses the double dollar signs? Please let me know what the best method for writing math equations would be. It would take too long to change all of our formats of equations to stray away from the double dollar sign.

Should we use mimetex for the time being until we get on our own server and install latex ourselves? Please help with your suggestions and input. Thanks!
Average of ratings: -
In reply to Frank Park

Re: Writing mathematic equations..

by Marc Grober -
Either will work for you. ASCIIMathml may be the simpler to install (see docs), though you will need to tweak your fallback URL and may want to use the fallback version I have described in docs. MathJax is still in beta, though if you have shell access it installs quickly via svn and is as easily invoked via meta.php as asciimathml.
In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
Is it safe to assume the asciimathml looks a lot better than mimetex? as in cleaner edges and smoothly rendered equations? Correct me if I am wrong, but I wouldn't need to convert my equations written in latex format to "asciimathml" format correct?
Your help is much appreciated. Thanks in advance! =)
In reply to Frank Park

Re: Writing mathematic equations..

by Casey Stark -
ASCIIMathML allows many basic TeX commands, but you're right, if you do anything too advanced, it won't recognize the TeX. You can see a list of the supported TeX at http://www1.chapman.edu/~jipsen/mathml/asciimathsyntax.html.

ASCIIMathML will definitely look better than mimeTeX because MathML is rendered by the browser or plugin and mimeTeX just spits out images.

Keep in mind that along with some TeX not working, ASCIIMathML will require users to use Firefox or a MathML plugin.
In reply to Casey Stark

Re: Writing mathematic equations..

by Frank Park -
Hmm. I did not know it only works on FF and only if the user installs a plug in. So asciimathml wont work on IE right out of the box? What do you mean by asciimath wont recognize complex equations? It seems like asciimath is very limited.

All I am looking for is something to read my LaTeX equations instead of using latex or mimetex. Is there such a thing? I sure hope so. =)
In reply to Frank Park

Re: Writing mathematic equations..

by Casey Stark -
Yup, ASCIIMathML outputs MathML which requires a plugin in IE and I believe it doesn't work in Chrome/Safari or Opera at all.

I say you try out MathJax. It's still beta, so it might be too slow for your needs. It takes a while to load if there is a lot of math on the page, but otherwise it should do the job. It can output in MathML and outputs HTML/CSS formatted math if your browser doesn't support it. It should also look better than mimeTeX since it uses fonts instead of images. The 1.0 release will also be a lot faster.
In reply to Casey Stark

Re: Writing mathematic equations..

by Marc Grober -
Casey,

Asciimathml will do fallback for browsers that do not support MathML, and offers the option of falling back to mimetex, mathtex, google chart api or mathtrans.

With the Hub file I published and using FF3.6.3 with STIX installed MathJax is very quick as no web fonts are required and MathML is output. It also plays well enough with other apps invoked via one's theme (Frank, see http://moodle.org/mod/forum/discuss.php?d=142785&parent=650402)

However, part and parcel of Frank's decision is going to have to be based on whether he has shell access. If he does and he wants to be able to extend tex, I would argue he is likely better off installing livetex in his own local bin. If his only access is ftp, then asciimathml would be much quicker and simpler (download meta.php, edit it, and upload it and asciimathml.js at a minimum.) If someone is intending to keep mathjax up to date, I would suggest an svn install, which would be difficult to manage with just ftp access.

BTW, Casey, how are you invoking MathJax in your Moodle? Have you looked at cobbling up a php based filter or doing something akin to the meta.php dodge? I just did a new Moodle 2 install and am going to look at how MathJax plays with it.


In reply to Marc Grober

Re: Writing mathematic equations..

by Casey Stark -
Sorry I forgot to reply to this.

I didn't realize ASCIIMathML had a fallback. They might want to change the name then...

I try to stay out of Moodle development, but I think when I was doing it, I just brute forced it by including it statically in the theme.

I would suggest an SVN install of MathJax as well for now, but it will be fine to FTP 1.0 once that comes out.
In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
Hi Marc.

I wanted to give mathjax a try. I downloaded the zip files for beta2 along with the corresponding fonts zip file. Do I just unzip this inside the public_html folder? I am a bit unsure how to make this available on my moodle site. I hope its nothing like installing it on the server like latex is. Any information on mathjax would be helpful. Thank you.
In reply to Frank Park

Re: Writing mathematic equations..

by Marc Grober -
If you have shell access then the easiest way to install mathjax is via svn, and the instructions for doing that are on the mathjax site.

Yes you can use the beta zip and put that in your public_html folder. and yes if you do use the beta zip then you have to download the fonts and unzip that in the MathJax directory as the instructions indicate.

Once that is done you want to look at the meta.php file I posted which contains a Hub configuration. The meta.php file replaces the one in use for your current theme just like with asciimath. In fact as I recall the file I posted will support asciimath as well.

In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
Can I have the link to the meta.php file you posted? Do I just download that file and replace the meta.php file in my theme?

As of now, all I did was unzip the beta2 zip and fonts zip into the public_html folder.
In reply to Frank Park

Re: Writing mathematic equations..

by Marc Grober -
http://moodle.org/mod/forum/discuss.php?d=142785&parent=650402
Yes, you can download and replace meta.php, but review the settings in the file as you will likely need to change the tokens to be used and if you are not using asciimathml, drop the invocation of asciimathml.
In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
I do not know where I can download the meta.php file. Do you think you can provide a link so that I can download it? Upon downloading the meta.php file, where would I put this file into?

So I just have to acquire that meta.php file, place it in the correct folder, change the tokens and it should work? Id love to give this a try. Please let me know where I can get the meta.php file. Thanks!
In reply to Frank Park

Re: Writing mathematic equations..

by Marc Grober -
Frank,
I posted the URL in this thread in response to your first request for it.
In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
Was the link http://fpg87.netsons.org/eq_editor/editor_eq.php

That link does not work for me. 404 error
is that the wrong one?
In reply to Frank Park

Re: Writing mathematic equations..

by Marc Grober -
Yes, Frank, its the wrong one. Frankly I don't know how you could have missed ther right one. Check here: http://moodle.org/mod/forum/discuss.php?d=149359&parent=658746
In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
Oh ok.. I see it. Did not realize the file was on the top right.

But I am still wondering where this file would go. Would it go in the theme i am using? or the public_html folder? should I rename it meta.php? Or transfer it as is?

Sorry for all the questions. This is the first time I am doing this and I need all the help I can get .. Your help is appreciated.
In reply to Frank Park

Re: Writing mathematic equations..

by Marc Grober -
If you look at the doc on asciimathml, that will explain what you will be doing, as the file you found is simply a standard theme meta.php file amended by addition of references to asciimathml and mathjax.

So download the file and edit it so that it references the correct locations of any files. You can comment out the asciimathml references if you are not using it. Backup your existing meta.php, upload the version with mathjax references and cp to meta.php. You should be in business. Test with tokens identified in meta.php. Assuming it's working, you can tweak the mathjax settings and asciimathml settings so that they work together. The file I posted, I believe, had asciimathml doing Tex, but you can turn that behavior off in asciimathml (or comment out asciimathml altogether) and change/add tokens for online or display use by mathjax.

At some point it would be helpful if moodle.org provided a theme(s) that users could employ to address such features, and there is a tracker item for this for asciimathml which you could vote for.
In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
I am sorry. I am a bit confused. is the metaforasciimathandmathjax php file the meta.php file? Do the contents of that file go into my meta.php file in my theme folder?

For what I did, I placed the metaforasciimathandmathjax php file into my lib folder. I also placed the contents of metaforasciimathandmathjax into my meta.php file in the theme. I am not sure if I am getting close, or if I just totally missed the mark.

Even if I placed the right php files into the right places, I am still unsure what to do inside the php files.

Anyways, thank you for working with me. You have been a lot of help so far.
In reply to Frank Park

Re: Writing mathematic equations..

by Marc Grober -
Yes Frank, it is a replacement for the meta.php file. See my explanation above.
In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
Hi Marc. I am making some progress and I thank you for your help and assistance thus far.

As far as using the language "replace" I mean I changed something in that line.

As far as the line
<script src="http://fqdn/MathJax/MathJax.js" type="text/javascript" >
I changed fqdn with mysite.com Nothing else was changed. so it would read http://mysite.com/MathJax/MathJax.js I even typed that in a web browser and it came out as all text codes.

I deleted the line that invokes asciimath

Based on the meta.php file, I wanted to know if I can have double$ be the delimiter of my math equations. I am confused on what you mean when you advise me to use the tokens that are provided \(texexpression\) or \texexpression\] . Would using double$ as the token cause problems? In other words, what do I need to change in order to have double$ as the tokens?

I think this line
tex2jax: {displayMath: \[','\\]
'">'LB+LB','LB+LB'],['\\[','\\]', inlineMath: \(','\\)'],[MJX,MJX">'double@','double@'],['\\(','\\)'],[MJX,MJX },

needs to be changed. I replaced the double@','double@ for double$','double$ That did not do the trick.

Sorry for naming @@ or $$ with double@ and double$. If I use the real ones, it seems to produce a syntax error.

Id appreciate the assistance. Thank you in advance.


In reply to Frank Park

Re: Writing mathematic equations..

by Marc Grober -
Frank,

Debugging is a slow process that relies on one's ability to isolate and remove causes of error one bit at a time.....

Yes, you will be able to use double dollar signs, but the first think to do is to make sure that the hub file works as it was delivered with only two changes, addition of the fqdn (which you indicate was done properly) and the deletion of the asciimath invocation (one line).

Now create a moodle web page and put a tex expression between the existng tokens, for example between the double@. YOur tex expression should be displayed properly., If so, we can then change tokens, but if that doesn;t work then we have to address other possible issues, and we dont want to confuse things by changing too much at once. I can tell you already that if the file you have in place contains the line you typed above, mathjax will not work.

You can find an explanation of the various brackets and commas in the documentation I added to the meta file. In short, displayMath is set so that you can use ££\frac{2}{3}££. You could also use double euros, but the var Euro has been commented out. Also you can use backslash opensquare bracket texexpression backslash closesquarebracket as in \[\frac{2}{3}\]

For inlineMath the file is currently set to double at signs, slash paren, as in \(\frac{a}{x}\), and MJX

Once you are clear on hos these tokens work, and confirm that they do, then we can carefully edit the file by for example replacing double euros with double dollars.

But note that there is a difference between inlineMath and displayMath, so you want to be careful as to which tokens you use for each (i.e. you don;t want to use the same tokemns for both.)

In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
I am a bit confused by what inlineMath is and what displayMath is. Whats the difference of those two and Mathjax and latex?
So far, double dollars, at, euro, £, slash parenthesis do not display any kind of latex expression or equation.

You note: "// Added displayMath setting to alter from doubledollars. Now set at Alt 128 though I had intended €" in your meta.php file. What does that mean? Do I need to add something myself to that line?

As far as my equations are, they are all in this format:
double$\frac{a}{b}double$
I do not use any @s or parentheses or brackets except when needed.


I have attached my (your) meta.php file. Is there a way you can look at it and see what is wrong with it?
Maybe I am not so close after all. Anyways, I appreciate the help.
In reply to Frank Park

Re: Writing mathematic equations..

by Mauno Korpelainen -

Maybe this image helps:

InlineMath vs displayMath

Attached a simple example of input/output code in meta.php for mathJax - it does not have to be so complex...and if you need asciimathml you can simply add a script tag like

<script src="<?php echo $CFG->httpswwwroot ?>/path_to_your_asciimathml_script/AsciiMathML.js" type="text/javascript"></script>

or if it's an external address replace <?php echo $CFG->httpswwwroot ?> with the actual address...

Note that in this meta.php MathJax.js is installed to my moodle test site sub folder lib/MathJax/ so tags src="<?php echo $CFG->httpswwwroot ?>/lib/MathJax/MathJax.js" find the script from correct place.

In reply to Mauno Korpelainen

Re: Writing mathematic equations..

by Frank Park -
Hi Mauno. Thank you for the meta.php file. Though I have tried to use that in my theme, I still do not display mathjax on my site.

<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>lib/MathJax/MathJax.js">
For this line, I changed lib/MathJax/Mathjax,js to wherever my MathJax.js is and it didn't work. I also placed my whole MathJax Folder into the lib folder, and that didn't work. Do I need to write "public_html/" before lib/? Also, Is there anything else I would need to change on that line? Perhaps place my url somewhere? Everything is pointed to the right direction, I don't see why this wouldn't work.
I have tried double @,$ pound, euro, MJX.

Any assistance would be great, thank you.
In reply to Frank Park

Re: Writing mathematic equations..

by Mauno Korpelainen -

One possible reason is that your custom theme config.php does not have a row

$THEME->metainclude = true;

and it does not read meta.php at all

You could use standard theme meta.php if you custom theme config.php has

$THEME->standardmetainclude = true;

but otherwise it is good to set in your custom theme

$THEME->standardmetainclude = false;

and

$THEME->metainclude = true;

if you use custom meta.php

Both

<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/MathJax/MathJax.js">

and

<script src="http://satmasters.net/MathJax/MathJax.js" type="text/javascript" >

should work if your MathJax folder is in http://satmasters.net/MathJax/

so either meta.php is not read or some other script is blocking MathJax.js ...

In reply to Mauno Korpelainen

Re: Writing mathematic equations..

by Mauno Korpelainen -

You can also test that mathJax itself is working fine in http://satmasters.net/MathJax/test/

And if you don't want to use meta.php for script tags (with $THEME->metainclude = true; in theme config.php) you can always add them for example to theme header.html

In reply to Mauno Korpelainen

Re: Writing mathematic equations..

by Frank Park -
Awesome! Mathjax seems to be working on my moodle site now!! I changed the config.php files to

$THEME->standardmetainclude = false;

and

$THEME->metainclude = true;


that did the trick, and the meta.php file is now read by the theme. Thank you so much for your help. I really appreciate it.

Thanks to Marc as well for being so helpful throughout this whole process. Both of you have been very helpful and I cannot thank you all enough for your time and assistance.

In reply to Frank Park

Re: Writing mathematic equations..

by Marc Grober -
Frank,

Perhaps you might do as I suggested? I have provide below text which should be able to copy and paste into a new Moodle web page to test MathJax.

Once you confirm that MathJax is working by following my directions, you will be able to not only SEE the difference between inline and display math, but you will be able to tweak the Hub file to your hearts content.

However, it is very easy to corrupt the expressions used because of the nested brackets, and you need to start with a known working solution. If MathJax works with the double at signs in the web page you create, then we can proceed to tweak the file to change the tokens.

There are also some other things we need to do to clean up your file, but we will do those ONLY when everything is working.

* * * * * * * * * * * * * * * * * * * * *

This is an exemplar for Frank's MathJax Test web page. Here is an example of inlineMath MJX\frac{x}{y}MJX so that you can see how inlineMath can be used. And here is an example of what we mean by display math using MathJax displayMath settings which currently use double pound sign as in ££\frac{x}{y}££. These alternative tokens demonstrate MathJax's flexibility.
In reply to Marc Grober

Re: Writing mathematic equations..

by Frank Park -
Hey Marc. Thank for your guidance. I went to the moodle docs on Asciimathml.
I downloaded the file, put the contents in a folder called asciimath. I put that into the lib folder in my public_html folder. I then went into my theme folder and changed my meta.php file to the contents of the moodle doc. I made sure the folders and directories were the same. I went to my site, and the equations don't show properly.

$$6\bullet6$$ shows up as 6\bullet6 as a red clickable link.

Interestingly @@\frac{2}{3}@@ shows up as a proper fraction. But @@6\bullet6@@ shows up as a syntax error. Why is that? Im definately doing something wrong.

I also did not know how to install the STIX font. Is that necessary? How would I go about doing that?

Anyways, as you can see, I'm a bit lost. any help would be great. thanks
In reply to Frank Park

Re: Writing mathematic equations..

by Casey Stark -
I agree, you shouldn't change the format. Especially since it's the default in TeX.

MathJax supports almost any string as a math delimiter. You just need to set it up in the config.

By default, the double dollar signs $$ display math  in display/block mode, so "this is text with math $$\phi$$ in it" will render as...

this is text with math

    φ

in it

I'm guessing this is what you're expecting from TeX, but you can change this behavior to display $$'s inline with the text. You can use the configuration:

inlineMath: [['$$','$$']],
displayMath: [['\\[','\\]']],

to have MathJax display the math surrounded by $$ inline with the text instead.

Hope that helps.