Printing Mathjax

Printing Mathjax

by Catherine Berry -
Number of replies: 11

I've installed the maths plugins for Moodle 2.1 - they are great, thank you to those who developed them.

I've started to use Mathjax because it looks so much better on the page that plain TeX. However, I'm finding that Mathjax expressions don't print properly - some of the symbols are missing, such as +. This is not a problem with plain TeX.

Can anyone help?

Many thanks.

Average of ratings: -
In reply to Catherine Berry

Re: Printing Mathjax

by Mauno Korpelainen -

The problem occurs if you are using MathJax with mathML output.

In the latest files I have been using attached extras.php in theme layout files (check some layout file of mathstandard theme or stylist theme) that sets

  MathJax.Hub.Config({
    MMLorHTML: { prefer: "HTML" },

...

and with this setting all browsers use HTML output that is printed correctly.

I noticed the same thing about 2 months ago and the first versions of math plugins were using different MathJax configuration - also Moodle Docs about these settings has not been upgraded for some time - but anyway I have the latest plugins upgraded to http://korpelainen.net/mpluga.zip or http://korpelainen.net/mplugb.zip that are now the same as temporary mplugaup.zip and mplugbup.zip

To explain this a little more detailed in Docs the example configuration is

<script type="text/javascript" src="http://111.121.101.131/lib/mathjax/MathJax.js">
MathJax.Hub.Config({
config: ["MMLorHTML.js"],

    extensions: ["tex2jax.js","mml2jax.js","MathMenu.js","MathZoom.js"],
    tex2jax: {displayMath: [ ['@d','@d'] ], inlineMath: [ ['@i','@i'] ] },
    TeX: {
    extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
    }
    });

</script>

but you can in fact use much simpler configuration with MathJax 1.1 (if you don't need to change default settings or don't need for example asciimathml extension):

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    MMLorHTML: { prefer: "HTML" },
    tex2jax: {displayMath: [ ['@d','@d'] ],  inlineMath: [ ['@i','@i'] ] }
  });
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

where configuration TeX-AMS-MML_HTMLorMML is selected with custom tokens for displaymath and inlinemath AND output is always set to HTML (unless user wants to change it with mouse right click over mathjax tags)

Average of ratings: Useful (1)
In reply to Mauno Korpelainen

Re: Printing Mathjax

by Catherine Berry -

Thank you Mauno, that's very helpful. I've downloaded the new version of the plugin - unfortunately I can't get any further at the moment because I'm getting a page error on the Notifications page. I think this is a problem with our php installation.

So once I've got that fixed, I think I just need to copy the extras.php file from the mathstandard theme into my own theme layouts folder, and add require ("extras.php"); just below the </head> line in the layout files.

I assume the extras.php file is instead of adding html on the 'Additional HTML' page, which was what I'd done previously?

In reply to Catherine Berry

Re: Printing Mathjax

by Mauno Korpelainen -

Yes, if you want to add the script tags to your custom theme the easiest option is to copy extras.php (from mathstandard theme) to your custom theme layout folder and add

 <?php require ("extras.php"); ?>

to each of layout files before </head>

If you get a blank page etc it can be caused by cached old files and you can purge old caches directly from your moodledata folder (delete all files inside cache folder) - usually you can simply purge caches from administration menu

Site administration > Development > Purge all caches.

What does the error say - some files might be unzipped to from folders etc ?

Note also that you should not use both additional HTML and theme layout files for adding script tags at least if they use different versions or settings of same scripts - it may cause some odd situations where plugins might use settings and files of math filter + themes might load separate scripts + additional HTML might load again different scripts (that might be different version etc). So if you need the scripts in all themes Additional HTML might be a good option, you just need to use absolute paths for all scripts (php tags don't work) - if you need scripts only in some themes then theme layout files might be the better option (some courses may not want to use math plugins etc and they could use different theme with different editor and so on)

In reply to Mauno Korpelainen

Re: Printing Mathjax

by Catherine Berry -

The error is just a '500 - Internal server error' one. We are getting this on a lot of pages - some pages such as course view pages will work on the second attempt but on some pages the error is consistent. The php error log is giving repeated errors about missing files in the php installation, so my colleague who knows about that sort of thing is looking into it. I'm hoping that this is what is causing all the page errors, rather than any problem with the plugins.

I'm not quite sure what you mean by 'some files might be unzipped to from folders'?

On the plugins update page, it does say that by the Book module 'Higher version already installed'. Could that be a problem? I installed the Book module separately - I don't think the original version of the maths plugin that I installed had a folder for Book, but this new version did.

In reply to Catherine Berry

Re: Printing Mathjax

by Mauno Korpelainen -

Ah, yes, Petr did upgrade book module for moodle 2.1 lately and you should reupload this official 2.1 book version if you had the newer version installed - the book version included to package is functional in all versions of moodle 2.0 to 2.2 but it can't "downgrade" newer version.

The book inside the package can print your maths from Print this book and Print this chapter links but the original book does not add the script tags to header of Book's print version pages. I was going to upgrade the book (2.1) to separate mathbook module but did not yet have the time to check those files...

Once you have reuploaded the original files of Book 2.1 module purge all caches from administration menu.

I had a typo error there - some files might have have been unzipped to wrong folders... blush

In reply to Catherine Berry

Re: Printing Mathjax

by Mauno Korpelainen -

Catherine,

attached a modified version of that official book 2.1 module - I added the missing tags to book/tool/print/index.php

You can replace your current files in mod/book with these (download and extract the package to mod folder) or just use the original files from Petr's module and modify/replace that index.php file according to the settings of your site and printing with that version of book should be avilable again...after purging caches smile

In reply to Mauno Korpelainen

Re: Printing Mathjax

by Catherine Berry -

Thanks Mauno. I have been able to run the plugin update page now, after replacing the Book module with the one from the plugins database - but we are still getting page errors all over the place, including when I switch to the mathstandard theme or add the require('extras.php'); line to my own theme layout files. I'm confident that my colleague will get to the bottom of the problem though - I don't think it's likely to be the maths plugins that are causing it.

In reply to Catherine Berry

Re: Printing Mathjax

by Catherine Berry -

Just to say that my colleague has now sorted out the problems we were having with page errors, and now that I can test the updated maths plugins I've found that Mathjax is printing correctly.

Many thanks for your help Mauno.

I also checked that the Geogebra filter was working, and I found that when I add a Geogebra applet to a page using the Moodle Media button, on the edit page it tells me that it can't display it as a plugin is missing. However, when viewing the actual page, the Geogebra displays correctly, so it's not really a problem.

In reply to Catherine Berry

Re: Printing Mathjax

by Mauno Korpelainen -

To make sure that all necessary files are included in packages and that they are not corrupted I just tested the larger package with the latest moodle 2.2 stable.

While testing I remembered some things that might be good to note too:

- since the latest files can use local asciimathml extension in Mathjax extensions folder it is a good option to add new asciimath commands in a cross browser compatible way but if it is selected in settings of math filter you need to use also local mathJax. This configuration is using a separate asciisvgfile AS.php.

Settings

- if you don't need asciimathml (extension) or asciisvg you don't need to add the corresponding script tags (to additional HTML or theme layout files). I might add an option to allow administrators to disable non-wanted tags directly from administration menu (settings of math filter) to future versions

- if you need tinymath editor only in custom theme (not in all themes) it is better to use

$CFG->texteditors = 'tinymath,textarea';

in that theme config.php or lib.php instead of changing site wide editor setting (then all themes would use tinymath and if other themes do not have the necessary script tags included by additional HTML rendering maths might fail)

The latest packages have the latest GeoGebra filter and JSXGraph files included and MathJax 1.1 but I have not yet upgraded all plugins like Wiris (new version came out a few days ago) and FMath plugins and most of the plugins are still alpha/beta plugins (experimental). From server logs I have however noticed that they have been downloaded hundreds of times and that makes me really happy. smile

In reply to Mauno Korpelainen

Re: Printing Mathjax

by Hilary Lai -

Hi there,

I have installed your great Math tools in my moodle 2 installation. I find that the jsxgraph used is 0.92. How can I change it to 0.93?