Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX symbols are not been converted correctly to Moodle

Tags:

r

r-exams

When I use exams2moodle() to generate a cloze quiz, LaTeX symbols are not generated correctly.

Example: (in .Rmd file): ... $\hat{p}$

In Moodle it is presented as: \hat{p}

(Observation: It works in exams2html().)

It is converted as: <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mover><mi>p</mi><mo accent="true">^</mo></mover><annotation encoding="application/x-tex">\hat{p}</annotation></semantics></math>

And finally: If I edit the question in Moodle and change to $$\hat{p}$$, every thing works. But this way, I will have a lot of editions, and that is very bad.

like image 534
Eduardo Silva Avatar asked Jan 29 '26 15:01

Eduardo Silva


1 Answers

Edits:

  • The solution described below is the default in recent versions of exams2moodle().
  • More detailed explanations about mathematical notation in HTML general are now available at http://www.R-exams.org/tutorials/math/.

Original answer:

For including LaTeX in HTML-based output in R/exams there is no single best solution. And all solutions have potential drawbacks.

  • By default, exams2moodle() converts the mathematical equations to MathML which can be rendered directly by various browsers (Firefox is recommended). Advantage: MathML looks good in Firefox and needs no further support either on server-side or client-side. Disadvantage: Does not work in some browsers, specifically not in Chrome.

  • As an alternative the equations can also be embedded in LaTeX and rendered by MathJax (on the server side, i.e., not by the browser). Advantage: Works in all browsers. Disadvantage: Needs to have the MathJax scripts installed and available on the server. Users need to have JavaScript enabled in their browser.

As MathJax appears to be available in your Moodle installation I would recommend to leverage this in your exercises (which will also solve your reported problem). This can simply be switched on by

exams2moodle(..., converter = "pandoc-mathjax")
like image 62
Achim Zeileis Avatar answered Feb 01 '26 08:02

Achim Zeileis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!