Issue after course restoration ...

Issue after course restoration ...

by Baptiste Lhoste -
Number of replies: 18

Hi everybody,

I have some issues with mathematics notation after restoring a course from a moodle 2.6.1 to a moodle 2.8.3.

There are some Tex notations (ex: $\Z$) which were correctly displayed in the old moodle.

But in the new one, the notation is not "translate" into the mathematic display, it just show characters.

I thought that default MathJax filter will do the display automatically.

What should I do to correct that ?

Best regards,

Tistou


Average of ratings: -
In reply to Baptiste Lhoste

Re: Issue after course restoration ...

by Baptiste Lhoste -

So after some researches I found some explanations on my issues.

First of all, inline delimiter $...$ is not use by default in mathjax (more details here).

So if you want to define it, you have to go to Administration > Site Administration > Plugin > Filter > MathJax.

Then in MathJax configuration, you have to add tex2jax: { inlineMath: \(','\\)'">'$','$'], ['\\(','\\)', processEscapes: true } in MathJax.Hub.Config({ ... });

This change works for notation inside book resource, however it works neither in the book title nor in a tag / label resource.

I was able to use \( ... \) in the tag / label resource, but that does not work in the book title. Did I miss something ?

Final issue, \Z seems to be unknown, only \mathbb{Z} works. Did I miss something again ?

Best regards,

Tistou

In reply to Baptiste Lhoste

Re: Issue after course restoration ...

by Mauno Korpelainen -

If MathJax does not have some symbols that old latex distribution (Tex filter) had you can use macros or unicode symbols.

For example you could try to add to MathJax configuration inside TeX: { ... } (after extensions)

        TeX: {
                    extensions: ["mhchem.js"],
          Macros: {
            /* Wikipedia compatibility: these macros are used on Wikipedia */
            empty: '\\emptyset',
            P: '\\unicode{xb6}',
            Alpha: '\\unicode{x391}', /* FIXME: These capital Greeks don't show up in bold in \boldsymbol ... */
            Beta: '\\unicode{x392}',
            Epsilon: '\\unicode{x395}',
            Zeta: '\\unicode{x396}',
            Eta: '\\unicode{x397}',
            Iota: '\\unicode{x399}',
            Kappa: '\\unicode{x39a}',
            Mu: '\\unicode{x39c}',
            Nu: '\\unicode{x39d}',
            Pi: '\\unicode{x3a0}',
            Rho: '\\unicode{x3a1}',
            Sigma: '\\unicode{x3a3}',
            Tau: '\\unicode{x3a4}',
            Chi: '\\unicode{x3a7}',
            C: '\\mathbb{C}',        /* the complex numbers */
            N: '\\mathbb{N}',        /* the natural numbers */
            Q: '\\mathbb{Q}',        /* the rational numbers */
            R: '\\mathbb{R}',        /* the real numbers */
            Z: '\\mathbb{Z}',        /* the integer numbers */
 
            /* some extre macros for ease of use; these are non-standard! */
            F: '\\mathbb{F}',        /* a finite field */
            HH: '\\mathcal{H}',      /* a Hilbert space */
            bszero: '\\boldsymbol{0}', /* vector of zeros */
            bsone: '\\boldsymbol{1}',  /* vector of ones */
            bst: '\\boldsymbol{t}',    /* a vector 't' */
            bsv: '\\boldsymbol{v}',    /* a vector 'v' */
            bsw: '\\boldsymbol{w}',    /* a vector 'w' */
            bsx: '\\boldsymbol{x}',    /* a vector 'x' */
            bsy: '\\boldsymbol{y}',    /* a vector 'y' */
            bsz: '\\boldsymbol{z}',    /* a vector 'z' */
            bsDelta: '\\boldsymbol{\\Delta}', /* a vector '\Delta' */
            E: '\\mathrm{e}',          /* the exponential */
            rd: '\\,\\mathrm{d}',      /*  roman d for use in integrals: $\int f(x) \rd x$ */
            rdelta: '\\,\\delta',      /* delta operator for use in sums */
            rD: '\\mathrm{D}',         /* differential operator D */
 
            /* example from MathJax on how to define macros with parameters: */
            /* bold: ['{\\bf #1}', 1] */
 
            RR: '\\mathbb{R}',
            ZZ: '\\mathbb{Z}',
            NN: '\\mathbb{N}',
            QQ: '\\mathbb{Q}',
            CC: '\\mathbb{C}',
            FF: '\\mathbb{F}'
          }
        }

Just remember to use backslash when you type those new macros like \Z.

If you need some special character that does not have latex symbol you can use in mathjax \unicode{...} - for example \unicode{8484} creates \( \unicode{8484} \) - or you can even copy and paste (or write) normal unicode characters inside mathjax delimiters to mathematical notations (the number is useful only if you can't find or type an unicode character otherwise)


In reply to Mauno Korpelainen

Re: Issue after course restoration ...

by Baptiste Lhoste -

Hi Mauno Korpelainen,

Thanks for your answer, it works for me.

I just need to found how to do this in book title. I still have \ (\Z \ ) (or \ (\mathbb{Z}\ ) ) instead of the mathematics symbol.

By any chance, do you have any idea ?

Best regards,

Tistou

In reply to Baptiste Lhoste

Re: Issue after course restoration ...

by Mauno Korpelainen -
One workaround is to use Additional HTML (Site administration > Appearance > Additional HTML) for MathJax tags instead of mathJax filter. There is a drop down option to in Plugins > Filters > manage filters to apply filters to content and Headings but I don't know why it does not work with Activity titles.

I use Additional HTML and no problems there.
In reply to Mauno Korpelainen

Re: Issue after course restoration ...

by Baptiste Lhoste -

I tried to set the drop down option in Administration > Site Administration > Plugins > Filters > Manage filters to content and title, but that made no difference.

I do not understant what I should do with Additional HTML. Can you indicate to me where to find some documentation ?

Best regards,

Tistou

In reply to Baptiste Lhoste

Re: Issue after course restoration ...

by Mauno Korpelainen -

You can add any script tags to Additional HTML anf they are used on (almost) every page of moodle - see for example https://github.com/maths/moodle-qtype_stack/blob/master/doc/en/Installation/Mathjax.md or those configuration examples on mathjax.org ... Or https://moodle.org/mod/forum/discuss.php?d=282305#p1210364

You don't need mathjax filter if you use additional HTML but it is possible to use them both as well


In reply to Mauno Korpelainen

Re: Issue after course restoration ...

by Baptiste Lhoste -

Hi M. Mauno Korpelainen,

I tried to use additional HTML without success. So I still have the same behavior (see attachment).

And now I notice an other issue. Inside the book, mathjax does not work in 2 chapters on 6. And I can not understand why.

Any idea ?

Best regards,

Tistou

Attachment error_mathjax.png
In reply to Baptiste Lhoste

Re: Issue after course restoration ...

by Mauno Korpelainen -

It is obviously a bug - most likely in mathjax filter code. One strange thing is that if you use double dollars in those titles or book names filter converts double dollars to "backslash parentheses" but does not render maths.

Disable Mathjax filter and paste the attached text to your Additional HTML ( see file Mathjax2.txt )

It works fine in book titles on my test site - and change the configuration according to your site needs (extensions, macros, configurations etc)

EDIT: + add that dollar & processEscapes: true to tex2jax at the end of configuration ... I forgot it (in your first post)

In reply to Mauno Korpelainen

Re: Issue after course restoration ...

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

It is not clear if that bug is with the filter or the way that filters are used in a number of places. There is a similar problem in MDL-47712. The MathJax loader does not work with HTML fragments, but other filters do.

In reply to Daniel Thies

Re: Issue after course restoration ...

by Mauno Korpelainen -

Daniel, to my eye these look like different issues. I checked shortly MDL-47712 and the cloze question example there works fine with this example configuration in Additional HTML (mathjax3.txt) and math filters disabled  - and so do emoticons (with filter) in cloze questions. But Mathjax itself can be used within any (body) html tags so obviously the mathjax filter logic just fails in MDL-47712 . Another thing is that dropdown lists in cloze answers do not support mathjax, images etc in all browsers but that's another story (remember that discussion about new question type I suggested a year ago to render maths in elements that look like dropdown lists but are not select elements) wink

In this case it looks like all filters fail in activity names including emoticons that do work in cloze.

I am not personally sure if php filters are the right way to use javascripts like MathJax


In reply to Mauno Korpelainen

Re: Issue after course restoration ...

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

Mauno, I looked at this a little more and you are right. This is not the same  as in MDL-47712.  It seems to be a coding error in the book module and maybe some other values as well.  When title and chapter names are outputted, they should be filtered through the PHP function filter_string.  This seems to be missing in book, but present in many other activity modules.  The function format_string applies only filters that are enabled in headings.  I have attached a git diff of the changes needed to display the book activity correctly.

I am not a fan of treating MathJax as a PHP filter either. thoughtful

In reply to Baptiste Lhoste

Re: Issue after course restoration ...

by Mauno Korpelainen -

So once more here the attached file with both changes wink

In reply to Mauno Korpelainen

Re: Issue after course restoration ...

by Baptiste Lhoste -

Thanks a lot M. Mauno Horpelainen.

Your solution works fine.

I just made a little change :

tex2jax: {displayMath: $$','$$'],['\\[','\\]'">'$$','$$'],['\\[','\\]', inlineMath: \(','\\)'">'$','$'],['\\(','\\)', processEscapes: true }

instead of :

tex2jax: {displayMath: \[','\\]'">'\\[','\\]', inlineMath: $$','$$'],['$','$'],['\\(','\\)'">'$$','$$'],['$','$'],['\\(','\\)', processEscapes: true }

Do I have to create a trac or something for the mathjax filter ?

Best regards,

Tistou

In reply to Baptiste Lhoste

Re: Issue after course restoration ...

by Mauno Korpelainen -

This looks like a common issue for all filters. For example emoticons have the same problem - they work in content but not in activity names. There is a setting to allow HTML tags in activity names and weblib.php checks if formatstringstriptags is enabled to allow or not allow html tags but otherwise - if filters are used - only cleaned text is rendered.

You could create a new issue to bug tracker  - maybe core developers have never thought that things like book titles or activity names could need also mathematical notations or other filtered content. Or perhaps people have just used image tags or unicode characters before MathJax filter came to core moodle - and unchecked Site administration > Appearance > HTML settings > Remove HTML tags from all activity names

M<span class=\(\alpha\)th" style="vertical-align:text-bottom;margin:0 0.5em;" class="img-responsive" height="438" width="393" />

In reply to Mauno Korpelainen

Re: Issue after course restoration ...

by Baptiste Lhoste -

Hi everybody,

I found an other strange behavior.

When I open the week (in the navigation block) with the book title containing some latex, it does not display correctly.

But if I select one entry of this week, it is already expanded in the navigation block and the latex notation is correctly rendered.

Please see the attachments.

I think that the problem is due to the Ajax load of the content of this week in the first case and that the mathjax had already check the html content.

Is there any solution to handle this ?

Best regards,

Tistou

Attachment navigation-ko.png
Attachment navigation-ok.png
In reply to Baptiste Lhoste

Re: Issue after course restoration ...

by Mauno Korpelainen -

It is clearly a bug too and should be fixed in core code.

The easiest solution might be to use only unicode characters in titles - ℤ - or perhaps html entities (editors usually convert html entities to unicode characters) http://symbolcodes.tlt.psu.edu/bylanguage/mathchart.html

It's not perfect anyway because different fonts render different looking characters

http://www.fileformat.info/info/unicode/char/2124/browsertest.htm

In reply to Baptiste Lhoste

Re: Issue after course restoration ...

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

There are at least two different bugs here.  One is in the book activity. It should be formating the heading, and it does not which is why you are including MathJax in additional HTML.  The Moodle core developers really only support MathJax in the MathJaxloader filter.  So it would be better to look at an activity or resource that does properly filter the header like maybe page.  After enabling filter headers and content for the filter you get same behaviour with MathJax in the filter as in additional HTML with page resources.

The reason that it does not work with AJAX is that the expression is not loaded until after MathJax has already finished typesetting everything. MathJax needs to be told to look for new TeX with MathJax.Hub.Typeset. There is a event API to do this that goes with the filter.  The menu AJAX code should do this just as the glossary popups AJAX code does now.

In reply to Daniel Thies

Re: Issue after course restoration ...

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers
Actually, the menu strips all HTML tags from activity titles in the links. Therefore neither MathJax or TeX filter would be expected to work there. Hence that is not realy a bug, but an undocumented feature smile