Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Many R/exams exercises employ mathematical notation that needs to be converted and rendered suitably for inclusion in online exams. While R/exams attempts to set suitable defaults, an overview is provided of possible adjustments and when these might be useful or even necessary.

## Overview

A popular use case of the R/exams package is the generation of dynamic exercises for online learning management systems in large-scale courses in mathematics, statistics, or physics. Often, these contain some mathematical notation using LaTeX markup. While LaTeX can be easily rendered into PDF for printing written exams, the options for rendering it into HTML for online exams are somewhat more diverse and the best strategies depend on a number of factors. As these involve a number of technical details this tutorial aims to give a brief overview and makes a few practical recommendations. Factors include the following:

• Original markup in exercise source files:
The R/exams exercises may employ either Markdown or LaTeX for formatting and structuring the text (see the First steps tutorial for more details). In either case LaTeX is used for the mathematical notation. Thus, also in Markdown the mathematical content is embedded as LaTeX code.
• Math markup in HTML:
For display of the formatted text online in a browser, the original markup (Markdown/LaTeX) needs to be converted (see below) to HTML with some suitable formatting for the mathematical content. Either the LaTeX can be preserved or turned into MathML, a dedicated XML format for describing mathematical content.
• Rendering of math markup:
The most widely-used way of rendering mathematical content in web pages is MathJax (see also the corresponding Wikipedia page), an open-source JavaScript library that works in all browsers without any setup by the user (except enabling JavaScript). It can render LaTeX directly but also MathML. Moreover, some browsers (mainly Firefox and Safari but not Chrome) have also native support for displaying MathML, i.e, without the need for an additional display engine such as MathJax. The advantage of employing the browser for MathML rendering is that it is faster and typically blends better into the regular text. The disadvantage is obviously that it is not supported by all browsers and does not support rendering of LaTeX directly.
• Convertesion to HTML:
The original markup from the exercises templates needs to be converted to HTML and the most powerful document converter for this is Pandoc (see also the corresponding Wikipedia page). It can convert both Markdown and LaTeX source files to HTML, either with LaTeX embedded for MathJax or with MathML (among various other options). Moreover, LaTeX (but not Markdown) exercises can be converted to HTML using the TeX-to-MathML converter TtM. (R/exams also provides a few further options which are typically of less interest due to lower quality, such as TtH or rendered images.)
• Defaults in R/exams:
All exams2xyz() functions that produce HTML-based output offer a converter = argument. By default, this is configured to produce HTML with embedded MathML because this can be rendered both by MathJax in all browsers as well as by some browsers directly. The default is is converter = "pandoc" (equivalent to "pandoc-mathml") for R/Markdown exercises and converter = "ttm" for R/LaTeX exercises, respectively. Whether MathJax is enabled varies across output formats or might depend on the learning management system.

## Why does all of this matter?

As a simple illustration of the strengths and weaknesses of the different approaches, the deriv exercise template (computation of a derivative using the product rule) is converted to HTML using exams2html(). Here, the R/LaTeX version of the exercise is used ("deriv" or equivelently "deriv.Rnw") but using the R/Markdown version ("deriv.Rmd") yields almost the same output.

The following examples and resulting screenshots contrast the output between Firefox and Chrome. By clicking on the screenshots you can also see what the HTML pages look like in your own browser.

#### MathML rendered by browser

By default, exams2html() generates HTML with MathML embedded and uses a template that does not enable MathJax.

library("exams")
set.seed(1090)
exams2html("deriv")

The screenshots that the native MathML support in Firefox leads to output that renders fast and smoothly. However, the lack of native MathML support in Chrome means that the exercise cannot be displayed correctly.

#### MathML rendered by MathJax

To easily explore the effect of MathJax rendering exams2html() supports the argument mathjax = TRUE which inserts the MathJax </code> into the template (loaded from RStudio’s content delivery network).</p> <pre><code class="prettyprint ">set.seed(1090) exams2html("deriv", mathjax = TRUE)</code></pre> <p><a href="http://www.r-exams.org/assets/posts/2019-01-28-math//deriv-mathml-mathjax.html" rel="nofollow" target="_blank"><img src="https://i1.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathml-mathjax-firefox.png?w=578" alt="deriv-mathml-mathjax.html" data-recalc-dims="1" data-lazy-src="https://i1.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathml-mathjax-firefox.png?w=578&amp;is-pending-load=1" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class=" jetpack-lazy-image"><noscript><img src="https://i1.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathml-mathjax-firefox.png?w=578" alt="deriv-mathml-mathjax.html" data-recalc-dims="1" /></noscript></a><br /> <a href="http://www.r-exams.org/assets/posts/2019-01-28-math//deriv-mathml-mathjax.html" rel="nofollow" target="_blank"><img src="https://i1.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathml-mathjax-chrome.png?w=578" alt="deriv-mathml-mathjax.html" data-recalc-dims="1" data-lazy-src="https://i1.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathml-mathjax-chrome.png?w=578&amp;is-pending-load=1" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class=" jetpack-lazy-image"><noscript><img src="https://i1.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathml-mathjax-chrome.png?w=578" alt="deriv-mathml-mathjax.html" data-recalc-dims="1" /></noscript></a></p> <p>Now the math output looks good in both browsers. However, for Firefox users the version without MathJax might still be preferable as it renders faster with somewhat smoother output.</p> <h4 id="latex-rendered-by-mathjax">LaTeX rendered by MathJax</4> <p>To preserve the LaTeX equations, the argument <code class="highlighter-rouge">converter = "pandoc-mathjax"</code> can be used. Then, Pandoc converts the LaTeX text to HTML but preserves the LaTeX equations (in minimal HTML markup).</p> <pre><code class="prettyprint ">set.seed(1090) exams2html("deriv", converter = "pandoc-mathjax", mathjax = TRUE)</code></pre> <p><a href="http://www.r-exams.org/assets/posts/2019-01-28-math//deriv-mathjax.html" rel="nofollow" target="_blank"><img src="https://i0.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathjax-firefox.png?w=578" alt="deriv-mathjax.html" data-recalc-dims="1" data-lazy-src="https://i0.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathjax-firefox.png?w=578&amp;is-pending-load=1" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class=" jetpack-lazy-image"><noscript><img src="https://i0.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathjax-firefox.png?w=578" alt="deriv-mathjax.html" data-recalc-dims="1" /></noscript></a><br /> <a href="http://www.r-exams.org/assets/posts/2019-01-28-math//deriv-mathjax.html" rel="nofollow" target="_blank"><img src="https://i1.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathjax-chrome.png?w=578" alt="deriv-mathjax.html" data-recalc-dims="1" data-lazy-src="https://i1.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathjax-chrome.png?w=578&amp;is-pending-load=1" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class=" jetpack-lazy-image"><noscript><img src="https://i1.wp.com/www.r-exams.org/assets/posts/2019-01-28-math/deriv-mathjax-chrome.png?w=578" alt="deriv-mathjax.html" data-recalc-dims="1" /></noscript></a></p> <p>The output is very similar to the MathML rendered MathJax above. However, note that the alignment in the equations is changed (from left to right). This is caused by Pandoc replacing the LaTeX <code class="highlighter-rouge">{eqnarray*}</code> environment employed in the <code class="highlighter-rouge">"deriv"</code> exercise by <code class="highlighter-rouge">{aligned}</code> environments.</p> <h2 id="practical-considerations">Practical considerations</2> <ul> <li><em>Original markup in exercise source files:</em><br /> Whether to use R/Markdown (<code class="highlighter-rouge">.Rmd</code>) or R/LaTeX (<code class="highlighter-rouge">.Rnw</code>) markup in the exercise source files is mostly a matter of taste. The former is probably somewhat easier to learn for beginners but generally differences are small if there is only moderate text formatting. It is also good practice to keep the formatting simple to be robust across the different output formats and more advanced math constructs should be checked carefully.</li> <li><em>MathML as default math markup:</em><br /> As of today (January 2019) it might seem more natural to use LaTeX rendered by MathJax as <code class="highlighter-rouge">rmarkdown</code> does. However, when HTML conversion was added to R/exams in early 2012, MathML rendered by Firefox was the more robust choice. MathML has been preserved as the default since then because it can be rendered both by MathJax and some browsers.</li> <li><em>Pandoc vs. TtM:</em><br /> Pandoc is the default converter for all <code class="highlighter-rouge">.Rmd</code> exercises while TtM is still used by default for <code class="highlighter-rouge">.Rnw</code> exercises. The latter is mostly for backward compatibility but might change to Pandoc in the future. However, differences are not very large for most exercises anyway but some mathematical LaTeX constructs are just supported by one and not the other converter.</li> <li><em>Enabling MathJax rendering:</em><br /> Many modern learning management systems have MathJax enabled by default, e.g., in Moodle, Canvas, or OpenOLAT. There are a couple of caveats, though: First, the default MathJax configuration in Moodle and OpenOLAT switches off rendering of MathML. Second, some systems do not host their own copy of the MathJax library but employ a content delivery network (CDN). Thus, there is a small risk that the learning management system might be up and running but there are problems loading MathJax from the CDN.</li> <li><em>Moodle:</em><br /> As noted above the default configuration for <a href="https://moodle.org/" rel="nofollow" target="_blank">Moodle</a> has MathJax support (via a CDN) but switches off rendering of MathML. As <code class="highlighter-rouge">exams2moodle(...)</code> currently uses MathML markup by default, this necessitates Firefox or Safari for viewing the quizzes in Moodle. In contrast, <code class="highlighter-rouge">exams2moodle(..., converter = "pandoc-mathjax")</code> would use LaTeX math markup and render it by MathJax (unless the Moodle configuration switched off MathJax support).<br /> <strong>Request:</strong> Feedback from Moodle users would be appreciated on whether they prefer the current default or <code class="highlighter-rouge">converter = "pandoc-mathjax"</code>. It would be especially useful to find out whether the latter works in their Moodle installations.</li> <li><em>Canvas:</em><br /> We are currently working on a dedicated <code class="highlighter-rouge">exams2qti12()</code>-based function <code class="highlighter-rouge">exams2canvas()</code> for generating quizzes for <a href="https://www.canvaslms.com/" rel="nofollow" target="_blank">Canvas</a>. This will keep the MathML-based default for the math notation as this is rendered smoothly by Canvas’ own MathJax support.</li> <li><em>OpenOLAT:</em><br /> A new dedicated interface <code class="highlighter-rouge">exams2openolat()</code> for generating quizzes for <a href="https://www.openolat.com/" rel="nofollow" target="_blank">OpenOLAT</a> has been added recently to R/exams (version 2.3-1). By default, this is a wrapper to <code class="highlighter-rouge">exams2qti21(..., converter = "pandoc-mathjax")</code> because OpenOLAT provides MathJax rendering of LaTeX math (but not MathML). Some additional tweaks are necessary, though, because OpenOLAT expects the LaTeX to be embedded slightly differently from standard Pandoc output.</li> </ul> <h2 id="further-technical-details">Further technical details</2> <p>The mathematical equation in the random draw of the <a href="http://www.r-exams.org/templates/deriv/" rel="nofollow" target="_blank">deriv</a> exercise in LaTeX is: <code class="highlighter-rouge">f(x) = x^{8} e^{3.4x}</code>. Here, we highlight that all converters yield almost equivalent output when rendered by MathJax:</p> <table> <thead> <tr> <th style="text-align: left"><code class="highlighter-rouge">"pandoc-mathjax"</code></th> <th style="text-align: left"><code class="highlighter-rouge">"ttm"</code></th> <th style="text-align: left"><code class="highlighter-rouge">"pandoc-mathml"</code></th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><span class="math inline">$$f(x) = x^{8} e^{3.4x}$$</span></td> <td style="text-align: left"> <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msup><mrow><mi>x</mi></mrow><mrow><mn>8</mn></mrow></msup><msup><mrow><mi>e</mi></mrow><mrow><mn>3</mn><mo>.</mo><mn>4</mn><mi>x</mi></mrow></msup></mrow></math> </td> <td style="text-align: left"> <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>x</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><msup><mi>x</mi><mn>8</mn></msup><msup><mi>e</mi><mrow><mn>3.4</mn><mi>x</mi></mrow></msup></mrow><annotation encoding="application/x-tex">f(x) = x^{8} e^{3.4x}</annotation></semantics></math> </td> </tr> </tbody> </table> <p>(<strong>Note:</strong> If you are viewing this on R-bloggers or another aggregator some or all of the equations will not display correctly. Refer to the <a href="http://www.r-exams.org/tutorials/math/" rel="nofollow" target="_blank">R/exams site</a> for a version with MathJax properly enabled.)</p> <p>The underlying LaTeX code generated by <code class="highlighter-rouge">converter = "pandoc-mathjax"</code> is simply the original LaTeX code with some minimal HTML markup:</p> <pre><code class="language-"><span class="math inline">$$f(x) = x^{8} e^{3.4x}$$</span> </code></pre> <p>The MathML code generated by <code class="highlighter-rouge">converter = "ttm"</code> differs slightly from the of <code class="highlighter-rouge">converter = "pandoc"</code> (or equivalently <code class="highlighter-rouge">"pandoc-mathml"</code>). The former yields:</p> <pre><code class="prettyprint "><math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo> <msup><mrow><mi>x</mi></mrow><mrow><mn>8</mn></mrow> </msup> <msup><mrow><mi>e</mi></mrow><mrow><mn>3</mn><mo>.</mo><mn>4</mn><mi>x</mi></mrow> </msup> </mrow></math></code></pre> <p>The Pandoc version is very similar but contains some more markup and annotation:</p> <pre><code class="prettyprint "><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics> <mrow><mi>f</mi> <mo stretchy="false" form="prefix">(</mo><mi>x</mi><mo stretchy="false" form="postfix">)</mo> <mo>=</mo> <msup><mi>x</mi><mn>8</mn></msup><msup><mi>e</mi><mrow><mn>3.4</mn><mi>x</mi></mrow></msup> </mrow><annotation encoding="application/x-tex">f(x) = x^{8} e^{3.4x}</annotation> </semantics></math></code></pre> <script type="text/javascript"> var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; s.src = '//cdn.viglink.com/api/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script')); 

To leave a comment for the author, please follow the link and comment on their blog: R/exams.

 R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

 [{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/www.r-bloggers.com#Organization","name":"R-bloggers","url":"http:\/\/www.r-bloggers.com","sameAs":[],"logo":{"@type":"ImageObject","url":"http:\/\/www.r-bloggers.com\/wp-content\/uploads\/2020\/07\/R_blogger_logo_02.png","width":"1061","height":"304"},"contactPoint":{"@type":"ContactPoint","contactType":"technical support","telephone":"","url":"https:\/\/www.r-bloggers.com\/contact-us\/"}},[],{"@context":"https:\/\/schema.org","@type":"WebPage","@id":"https:\/\/www.r-bloggers.com\/mathematical-notation-in-online-r-exams\/#webpage","name":"Mathematical Notation in Online R\/exams | R-bloggers","url":"https:\/\/www.r-bloggers.com\/mathematical-notation-in-online-r-exams\/","lastReviewed":"2019-01-27T17:00:00-06:00","reviewedBy":{"@type":"Organization","logo":{"@type":"ImageObject","url":"http:\/\/www.r-bloggers.com\/wp-content\/uploads\/2020\/07\/R_blogger_logo_02.png","width":"1061","height":"304"},"name":"R-bloggers"},"inLanguage":"en-US","description":"Many R\/exams exercises employ mathematical notation that needs to be converted and rendered suitably for inclusion in online exams. While R\/exams attempts to set suitable defaults, an overview is provided of possible adjustments and when these might be useful or even necessary.\n \n \n \n \n Overview\n\nA popular use case of the R\/exams package is the generation of dynamic exercises for online learning management systems in large-scale courses in mathematics, statistics, or physics. Often, these contain some mathematical notation using LaTeX markup. While LaTeX can be easily rendered into PDF for printing written exams, the options for rendering it into HTML for online exams are somewhat more diverse and the best strategies depend on a number of factors. As these involve a number of technical details this tutorial aims to give a brief overview and makes a few practical recommendations. Factors include the following:\n\n\n\nOriginal markup in exercise source files:\nThe R\/exams exercises may employ either Markdown or LaTeX for formatting and structuring the text (see the First steps tutorial for more details). In either case LaTeX is used for the mathematical notation. Thus, also in Markdown the mathematical content is embedded as LaTeX code.\n \nMath markup in HTML:\nFor display of the formatted text online in a browser, the original markup (Markdown\/LaTeX) needs to be converted (see below) to HTML with some suitable formatting for the mathematical content. Either the LaTeX can be preserved or turned into MathML, a dedicated XML format for describing mathematical content.\n \nRendering of math markup:\nThe most widely-used way of rendering mathematical content in web pages is MathJax (see also the corresponding Wikipedia page), an open-source JavaScript library that works in all browsers without any setup by the user (except enabling JavaScript). It can render LaTeX directly but also MathML. Moreover, some browsers (mainly Firefox and Safari but not Chrome) have also native support for displaying MathML, i.e, without the need for an additional display engine such as MathJax. The advantage of employing the browser for MathML rendering is that it is faster and typically blends better into the regular text. The disadvantage is obviously that it is not supported by all browsers and does not support rendering of LaTeX directly.\n \nConvertesion to HTML:\nThe original markup from the exercises templates needs to be converted to HTML and the most powerful document converter for this is Pandoc (see also the corresponding Wikipedia page). It can convert both Markdown and LaTeX source files to HTML, either with LaTeX embedded for MathJax or with MathML (among various other options). Moreover, LaTeX (but not Markdown) exercises can be converted to HTML using the TeX-to-MathML converter TtM. (R\/exams also provides a few further options which are typically of less interest due to lower quality, such as TtH or rendered images.)\n \nDefaults in R\/exams:\nAll exams2xyz() functions that produce HTML-based output offer a converter = argument. By default, this is configured to produce HTML with embedded MathML because this can be rendered both by MathJax in all browsers as well as by some browsers directly. The default is is converter = \"pandoc\" (equivalent to \"pandoc-mathml\") for R\/Markdown exercises and converter = \"ttm\" for R\/LaTeX exercises, respectively. Whether MathJax is enabled varies across output formats or might depend on the learning management system.\n\nWhy does all of this matter?\n\nAs a simple illustration of the strengths and weaknesses of the different approaches, the deriv exercise template (computation of a derivative using the product rule) is converted to HTML using exams2html(). Here, the R\/LaTeX version of the exercise is used (\"deriv\" or equivelently \"deriv.Rnw\") but using the R\/Markdown version (\"deriv.Rmd\") yields almost the same output.\n\nThe following examples and resulting screenshots contrast the output between Firefox and Chrome. By clicking on the screenshots you can also see what the HTML pages look like in your own browser.\n\nMathML rendered by browser\n\nBy default, exams2html() generates HTML with MathML embedded and uses a template that does not enable MathJax.\n\nlibrary(\"exams\")\nset.seed(1090)\nexams2html(\"deriv\")\n\n\n\n\nThe screenshots that the native MathML support in Firefox leads to output that renders fast and smoothly. However, the lack of native MathML support in Chrome means that the exercise cannot be displayed correctly.\n\nMathML rendered by MathJax\n\nTo easily explore the effect of MathJax rendering exams2html() supports the argument mathjax = TRUE which inserts the MathJax &lt;script&gt; into the template (loaded from RStudio\u2019s content delivery network).\n\nset.seed(1090)\nexams2html(\"deriv\", mathjax = TRUE)\n\n\n\n\nNow the math output looks good in both browsers. However, for Firefox users the version without MathJax might still be preferable as it renders faster with somewhat smoother output.\n\nLaTeX rendered by MathJax\n\nTo preserve the LaTeX equations, the argument converter = \"pandoc-mathjax\" can be used. Then, Pandoc converts the LaTeX text to HTML but preserves the LaTeX equations (in minimal HTML markup).\n\nset.seed(1090)\nexams2html(\"deriv\", converter = \"pandoc-mathjax\", mathjax = TRUE)\n\n\n\n\nThe output is very similar to the MathML rendered MathJax above. However, note that the alignment in the equations is changed (from left to right). This is caused by Pandoc replacing the LaTeX {eqnarray*} environment employed in the \"deriv\" exercise by {aligned} environments.\n\nPractical considerations\n\n\n\nOriginal markup in exercise source files:\nWhether to use R\/Markdown (.Rmd) or R\/LaTeX (.Rnw) markup in the exercise source files is mostly a matter of taste. The former is probably somewhat easier to learn for beginners but generally differences are small if there is only moderate text formatting. It is also good practice to keep the formatting simple to be robust across the different output formats and more advanced math constructs should be checked carefully.\n \nMathML as default math markup:\nAs of today (January 2019) it might seem more natural to use LaTeX rendered by MathJax as rmarkdown does. However, when HTML conversion was added to R\/exams in early 2012, MathML rendered by Firefox was the more robust choice. MathML has been preserved as the default since then because it can be rendered both by MathJax and some browsers.\n \nPandoc vs. TtM:\nPandoc is the default converter for all .Rmd exercises while TtM is still used by default for .Rnw exercises. The latter is mostly for backward compatibility but might change to Pandoc in the future. However, differences are not very large for most exercises anyway but some mathematical LaTeX constructs are just supported by one and not the other converter.\n \nEnabling MathJax rendering:\nMany modern learning management systems have MathJax enabled by default, e.g., in Moodle, Canvas, or OpenOLAT. There are a couple of caveats, though: First, the default MathJax configuration in Moodle and OpenOLAT switches off rendering of MathML. Second, some systems do not host their own copy of the MathJax library but employ a content delivery network (CDN). Thus, there is a small risk that the learning management system might be up and running but there are problems loading MathJax from the CDN.\n \nMoodle:\nAs noted above the default configuration for Moodle has MathJax support (via a CDN) but switches off rendering of MathML. As exams2moodle(...) currently uses MathML markup by default, this necessitates Firefox or Safari for viewing the quizzes in Moodle. In contrast, exams2moodle(..., converter = \"pandoc-mathjax\") would use LaTeX math markup and render it by MathJax (unless the Moodle configuration switched off MathJax support).Request: Feedback from Moodle users would be appreciated on whether they prefer the current default or converter = \"pandoc-mathjax\". It would be especially useful to find out whether the latter works in their Moodle installations.\n \nCanvas:\nWe are currently working on a dedicated exams2qti12()-based function exams2canvas() for generating quizzes for Canvas. This will keep the MathML-based default for the math notation as this is rendered smoothly by Canvas\u2019 own MathJax support.\n \nOpenOLAT:\nA new dedicated interface exams2openolat() for generating quizzes for OpenOLAT has been added recently to R\/exams (version 2.3-1). By default, this is a wrapper to exams2qti21(..., converter = \"pandoc-mathjax\") because OpenOLAT provides MathJax rendering of LaTeX math (but not MathML). Some additional tweaks are necessary, though, because OpenOLAT expects the LaTeX to be embedded slightly differently from standard Pandoc output.\n\nFurther technical details\n\nThe mathematical equation in the random draw of the deriv exercise in LaTeX is: f(x) = x^{8} e^{3.4x}. Here, we highlight that all converters yield almost equivalent output when rendered by MathJax:\n\n\n\n\"pandoc-mathjax\"\n \"ttm\"\n \"pandoc-mathml\"\n \n\n\$$f(x) = x^{8} e^{3.4x}\$$\n f(x)=x8e3.4x\n f(x)=x8e3.4xf(x) = x^{8} e^{3.4x}\n \n\n(Note: If you are viewing this on R-bloggers or another aggregator some or all of the equations will not display correctly. Refer to the R\/exams site for a version with MathJax properly enabled.)\n\nThe underlying LaTeX code generated by converter = \"pandoc-mathjax\" is simply the original LaTeX code with some minimal HTML markup:\n\n&lt;span class=\"math inline\"&gt;\$$f(x) = x^{8} e^{3.4x}\$$&lt;\/span&gt;\n\n\nThe MathML code generated by converter = \"ttm\" differs slightly from the of converter = \"pandoc\" (or equivalently \"pandoc-mathml\"). The former yields:\n\n&lt;math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"&gt;\n&lt;mrow&gt;&lt;mi&gt;f&lt;\/mi&gt;&lt;mo stretchy=\"false\"&gt;(&lt;\/mo&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;mo stretchy=\"false\"&gt;)&lt;\/mo&gt;&lt;mo&gt;=&lt;\/mo&gt;\n&lt;msup&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;8&lt;\/mn&gt;&lt;\/mrow&gt;\n&lt;\/msup&gt;\n&lt;msup&gt;&lt;mrow&gt;&lt;mi&gt;e&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;3&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;4&lt;\/mn&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;\n&lt;\/msup&gt;\n&lt;\/mrow&gt;&lt;\/math&gt;\n\nThe Pandoc version is very similar but contains some more markup and annotation:\n\n&lt;math display=\"inline\" xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"&gt;&lt;semantics&gt;\n&lt;mrow&gt;&lt;mi&gt;f&lt;\/mi&gt;\n&lt;mo stretchy=\"false\" form=\"prefix\"&gt;(&lt;\/mo&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;mo stretchy=\"false\" form=\"postfix\"&gt;)&lt;\/mo&gt;\n&lt;mo&gt;=&lt;\/mo&gt;\n&lt;msup&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;mn&gt;8&lt;\/mn&gt;&lt;\/msup&gt;&lt;msup&gt;&lt;mi&gt;e&lt;\/mi&gt;&lt;mrow&gt;&lt;mn&gt;3.4&lt;\/mn&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;\/msup&gt;\n&lt;\/mrow&gt;&lt;annotation encoding=\"application\/x-tex\"&gt;f(x) = x^{8} e^{3.4x}&lt;\/annotation&gt;\n&lt;\/semantics&gt;&lt;\/math&gt;","primaryImageOfPage":{"@id":"https:\/\/www.r-bloggers.com\/mathematical-notation-in-online-r-exams\/#primaryimage"},"mainContentOfPage":[[{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Home","url":"https:\/\/www.r-bloggers.com"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"About","url":"http:\/\/www.r-bloggers.com\/about\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"RSS","url":"https:\/\/feeds.feedburner.com\/RBloggers"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"add your blog!","url":"http:\/\/www.r-bloggers.com\/add-your-blog\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Learn R","url":"https:\/\/www.r-bloggers.com\/how-to-learn-r-2\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"R jobs","url":"https:\/\/www.r-users.com\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Submit a new job (it's free)","url":"https:\/\/www.r-users.com\/submit-job\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Browse latest jobs (also free)","url":"https:\/\/www.r-users.com\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Contact us","url":"http:\/\/www.r-bloggers.com\/contact-us\/"}]]},{"@type":"Article","@id":"https:\/\/www.r-bloggers.com\/mathematical-notation-in-online-r-exams\/#article","url":"https:\/\/www.r-bloggers.com\/mathematical-notation-in-online-r-exams\/","inLanguage":"en-US","mainEntityOfPage":"https:\/\/www.r-bloggers.com\/mathematical-notation-in-online-r-exams\/#webpage","headline":"Mathematical Notation in Online R\/exams | R-bloggers","description":"Many R\/exams exercises employ mathematical notation that needs to be converted and rendered suitably for inclusion in online exams. While R\/exams attempts to set suitable defaults, an overview is provided of possible adjustments and when these might be useful or even necessary.\n \n \n \n \n Overview\n\nA popular use case of the R\/exams package is the generation of dynamic exercises for online learning management systems in large-scale courses in mathematics, statistics, or physics. Often, these contain some mathematical notation using LaTeX markup. While LaTeX can be easily rendered into PDF for printing written exams, the options for rendering it into HTML for online exams are somewhat more diverse and the best strategies depend on a number of factors. As these involve a number of technical details this tutorial aims to give a brief overview and makes a few practical recommendations. Factors include the following:\n\n\n\nOriginal markup in exercise source files:\nThe R\/exams exercises may employ either Markdown or LaTeX for formatting and structuring the text (see the First steps tutorial for more details). In either case LaTeX is used for the mathematical notation. Thus, also in Markdown the mathematical content is embedded as LaTeX code.\n \nMath markup in HTML:\nFor display of the formatted text online in a browser, the original markup (Markdown\/LaTeX) needs to be converted (see below) to HTML with some suitable formatting for the mathematical content. Either the LaTeX can be preserved or turned into MathML, a dedicated XML format for describing mathematical content.\n \nRendering of math markup:\nThe most widely-used way of rendering mathematical content in web pages is MathJax (see also the corresponding Wikipedia page), an open-source JavaScript library that works in all browsers without any setup by the user (except enabling JavaScript). It can render LaTeX directly but also MathML. Moreover, some browsers (mainly Firefox and Safari but not Chrome) have also native support for displaying MathML, i.e, without the need for an additional display engine such as MathJax. The advantage of employing the browser for MathML rendering is that it is faster and typically blends better into the regular text. The disadvantage is obviously that it is not supported by all browsers and does not support rendering of LaTeX directly.\n \nConvertesion to HTML:\nThe original markup from the exercises templates needs to be converted to HTML and the most powerful document converter for this is Pandoc (see also the corresponding Wikipedia page). It can convert both Markdown and LaTeX source files to HTML, either with LaTeX embedded for MathJax or with MathML (among various other options). Moreover, LaTeX (but not Markdown) exercises can be converted to HTML using the TeX-to-MathML converter TtM. (R\/exams also provides a few further options which are typically of less interest due to lower quality, such as TtH or rendered images.)\n \nDefaults in R\/exams:\nAll exams2xyz() functions that produce HTML-based output offer a converter = argument. By default, this is configured to produce HTML with embedded MathML because this can be rendered both by MathJax in all browsers as well as by some browsers directly. The default is is converter = \"pandoc\" (equivalent to \"pandoc-mathml\") for R\/Markdown exercises and converter = \"ttm\" for R\/LaTeX exercises, respectively. Whether MathJax is enabled varies across output formats or might depend on the learning management system.\n\nWhy does all of this matter?\n\nAs a simple illustration of the strengths and weaknesses of the different approaches, the deriv exercise template (computation of a derivative using the product rule) is converted to HTML using exams2html(). Here, the R\/LaTeX version of the exercise is used (\"deriv\" or equivelently \"deriv.Rnw\") but using the R\/Markdown version (\"deriv.Rmd\") yields almost the same output.\n\nThe following examples and resulting screenshots contrast the output between Firefox and Chrome. By clicking on the screenshots you can also see what the HTML pages look like in your own browser.\n\nMathML rendered by browser\n\nBy default, exams2html() generates HTML with MathML embedded and uses a template that does not enable MathJax.\n\nlibrary(\"exams\")\nset.seed(1090)\nexams2html(\"deriv\")\n\n\n\n\nThe screenshots that the native MathML support in Firefox leads to output that renders fast and smoothly. However, the lack of native MathML support in Chrome means that the exercise cannot be displayed correctly.\n\nMathML rendered by MathJax\n\nTo easily explore the effect of MathJax rendering exams2html() supports the argument mathjax = TRUE which inserts the MathJax &lt;script&gt; into the template (loaded from RStudio\u2019s content delivery network).\n\nset.seed(1090)\nexams2html(\"deriv\", mathjax = TRUE)\n\n\n\n\nNow the math output looks good in both browsers. However, for Firefox users the version without MathJax might still be preferable as it renders faster with somewhat smoother output.\n\nLaTeX rendered by MathJax\n\nTo preserve the LaTeX equations, the argument converter = \"pandoc-mathjax\" can be used. Then, Pandoc converts the LaTeX text to HTML but preserves the LaTeX equations (in minimal HTML markup).\n\nset.seed(1090)\nexams2html(\"deriv\", converter = \"pandoc-mathjax\", mathjax = TRUE)\n\n\n\n\nThe output is very similar to the MathML rendered MathJax above. However, note that the alignment in the equations is changed (from left to right). This is caused by Pandoc replacing the LaTeX {eqnarray*} environment employed in the \"deriv\" exercise by {aligned} environments.\n\nPractical considerations\n\n\n\nOriginal markup in exercise source files:\nWhether to use R\/Markdown (.Rmd) or R\/LaTeX (.Rnw) markup in the exercise source files is mostly a matter of taste. The former is probably somewhat easier to learn for beginners but generally differences are small if there is only moderate text formatting. It is also good practice to keep the formatting simple to be robust across the different output formats and more advanced math constructs should be checked carefully.\n \nMathML as default math markup:\nAs of today (January 2019) it might seem more natural to use LaTeX rendered by MathJax as rmarkdown does. However, when HTML conversion was added to R\/exams in early 2012, MathML rendered by Firefox was the more robust choice. MathML has been preserved as the default since then because it can be rendered both by MathJax and some browsers.\n \nPandoc vs. TtM:\nPandoc is the default converter for all .Rmd exercises while TtM is still used by default for .Rnw exercises. The latter is mostly for backward compatibility but might change to Pandoc in the future. However, differences are not very large for most exercises anyway but some mathematical LaTeX constructs are just supported by one and not the other converter.\n \nEnabling MathJax rendering:\nMany modern learning management systems have MathJax enabled by default, e.g., in Moodle, Canvas, or OpenOLAT. There are a couple of caveats, though: First, the default MathJax configuration in Moodle and OpenOLAT switches off rendering of MathML. Second, some systems do not host their own copy of the MathJax library but employ a content delivery network (CDN). Thus, there is a small risk that the learning management system might be up and running but there are problems loading MathJax from the CDN.\n \nMoodle:\nAs noted above the default configuration for Moodle has MathJax support (via a CDN) but switches off rendering of MathML. As exams2moodle(...) currently uses MathML markup by default, this necessitates Firefox or Safari for viewing the quizzes in Moodle. In contrast, exams2moodle(..., converter = \"pandoc-mathjax\") would use LaTeX math markup and render it by MathJax (unless the Moodle configuration switched off MathJax support).Request: Feedback from Moodle users would be appreciated on whether they prefer the current default or converter = \"pandoc-mathjax\". It would be especially useful to find out whether the latter works in their Moodle installations.\n \nCanvas:\nWe are currently working on a dedicated exams2qti12()-based function exams2canvas() for generating quizzes for Canvas. This will keep the MathML-based default for the math notation as this is rendered smoothly by Canvas\u2019 own MathJax support.\n \nOpenOLAT:\nA new dedicated interface exams2openolat() for generating quizzes for OpenOLAT has been added recently to R\/exams (version 2.3-1). By default, this is a wrapper to exams2qti21(..., converter = \"pandoc-mathjax\") because OpenOLAT provides MathJax rendering of LaTeX math (but not MathML). Some additional tweaks are necessary, though, because OpenOLAT expects the LaTeX to be embedded slightly differently from standard Pandoc output.\n\nFurther technical details\n\nThe mathematical equation in the random draw of the deriv exercise in LaTeX is: f(x) = x^{8} e^{3.4x}. Here, we highlight that all converters yield almost equivalent output when rendered by MathJax:\n\n\n\n\"pandoc-mathjax\"\n \"ttm\"\n \"pandoc-mathml\"\n \n\n\$$f(x) = x^{8} e^{3.4x}\$$\n f(x)=x8e3.4x\n f(x)=x8e3.4xf(x) = x^{8} e^{3.4x}\n \n\n(Note: If you are viewing this on R-bloggers or another aggregator some or all of the equations will not display correctly. Refer to the R\/exams site for a version with MathJax properly enabled.)\n\nThe underlying LaTeX code generated by converter = \"pandoc-mathjax\" is simply the original LaTeX code with some minimal HTML markup:\n\n&lt;span class=\"math inline\"&gt;\$$f(x) = x^{8} e^{3.4x}\$$&lt;\/span&gt;\n\n\nThe MathML code generated by converter = \"ttm\" differs slightly from the of converter = \"pandoc\" (or equivalently \"pandoc-mathml\"). The former yields:\n\n&lt;math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"&gt;\n&lt;mrow&gt;&lt;mi&gt;f&lt;\/mi&gt;&lt;mo stretchy=\"false\"&gt;(&lt;\/mo&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;mo stretchy=\"false\"&gt;)&lt;\/mo&gt;&lt;mo&gt;=&lt;\/mo&gt;\n&lt;msup&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;8&lt;\/mn&gt;&lt;\/mrow&gt;\n&lt;\/msup&gt;\n&lt;msup&gt;&lt;mrow&gt;&lt;mi&gt;e&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;3&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;4&lt;\/mn&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;\n&lt;\/msup&gt;\n&lt;\/mrow&gt;&lt;\/math&gt;\n\nThe Pandoc version is very similar but contains some more markup and annotation:\n\n&lt;math display=\"inline\" xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"&gt;&lt;semantics&gt;\n&lt;mrow&gt;&lt;mi&gt;f&lt;\/mi&gt;\n&lt;mo stretchy=\"false\" form=\"prefix\"&gt;(&lt;\/mo&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;mo stretchy=\"false\" form=\"postfix\"&gt;)&lt;\/mo&gt;\n&lt;mo&gt;=&lt;\/mo&gt;\n&lt;msup&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;mn&gt;8&lt;\/mn&gt;&lt;\/msup&gt;&lt;msup&gt;&lt;mi&gt;e&lt;\/mi&gt;&lt;mrow&gt;&lt;mn&gt;3.4&lt;\/mn&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;\/msup&gt;\n&lt;\/mrow&gt;&lt;annotation encoding=\"application\/x-tex\"&gt;f(x) = x^{8} e^{3.4x}&lt;\/annotation&gt;\n&lt;\/semantics&gt;&lt;\/math&gt;","articleBody":"Many R\/exams exercises employ mathematical notation that needs to be converted and rendered suitably for inclusion in online exams. While R\/exams attempts to set suitable defaults, an overview is provided of possible adjustments and when these might be useful or even necessary. Overview A popular use case of the R\/exams package is the generation of dynamic exercises for online learning management systems in large-scale courses in mathematics, statistics, or physics. Often, these contain some mathematical notation using LaTeX markup. While LaTeX can be easily rendered into PDF for printing written exams, the options for rendering it into HTML for online exams are somewhat more diverse and the best strategies depend on a number of factors. As these involve a number of technical details this tutorial aims to give a brief overview and makes a few practical recommendations. Factors include the following: Original markup in exercise source files: The R\/exams exercises may employ either Markdown or LaTeX for formatting and structuring the text (see the First steps tutorial for more details). In either case LaTeX is used for the mathematical notation. Thus, also in Markdown the mathematical content is embedded as LaTeX code. Math markup in HTML: For display of the formatted text online in a browser, the original markup (Markdown\/LaTeX) needs to be converted (see below) to HTML with some suitable formatting for the mathematical content. Either the LaTeX can be preserved or turned into MathML, a dedicated XML format for describing mathematical content. Rendering of math markup: The most widely-used way of rendering mathematical content in web pages is MathJax (see also the corresponding Wikipedia page), an open-source JavaScript library that works in all browsers without any setup by the user (except enabling JavaScript). It can render LaTeX directly but also MathML. Moreover, some browsers (mainly Firefox and Safari but not Chrome) have also native support for displaying MathML, i.e, without the need for an additional display engine such as MathJax. The advantage of employing the browser for MathML rendering is that it is faster and typically blends better into the regular text. The disadvantage is obviously that it is not supported by all browsers and does not support rendering of LaTeX directly. Convertesion to HTML: The original markup from the exercises templates needs to be converted to HTML and the most powerful document converter for this is Pandoc (see also the corresponding Wikipedia page). It can convert both Markdown and LaTeX source files to HTML, either with LaTeX embedded for MathJax or with MathML (among various other options). Moreover, LaTeX (but not Markdown) exercises can be converted to HTML using the TeX-to-MathML converter TtM. (R\/exams also provides a few further options which are typically of less interest due to lower quality, such as TtH or rendered images.) Defaults in R\/exams: All exams2xyz() functions that produce HTML-based output offer a converter argument. By default, this is configured to produce HTML with embedded MathML because this can be rendered both by MathJax in all browsers as well as by some browsers directly. The default is is converter \"pandoc\" (equivalent to \"pandoc-mathml\") for R\/Markdown exercises and converter \"ttm\" for R\/LaTeX exercises, respectively. Whether MathJax is enabled varies across output formats or might depend on the learning management system. Why does all of this matter? As a simple illustration of the strengths and weaknesses of the different approaches, the deriv exercise template (computation of a derivative using the product rule) is converted to HTML using exams2html(). Here, the R\/LaTeX version of the exercise is used (\"deriv\" or equivelently \"deriv.Rnw\") but using the R\/Markdown version (\"deriv.Rmd\") yields almost the same output. The following examples and resulting screenshots contrast the output between Firefox and Chrome. By clicking on the screenshots you can also see what the HTML pages look like in your own browser. MathML rendered by browser By default, exams2html() generates HTML with MathML embedded and uses a template that does not enable MathJax. library(&quot;exams&quot;) set.seed(1090) exams2html(&quot;deriv&quot;) The screenshots that the native MathML support in Firefox leads to output that renders fast and smoothly. However, the lack of native MathML support in Chrome means that the exercise cannot be displayed correctly. MathML rendered by MathJax To easily explore the effect of MathJax rendering exams2html() supports the argument mathjax TRUE which inserts the MathJax &lt;script&gt; into the template (loaded from RStudio\u2019s content delivery network). set.seed(1090) exams2html(&quot;deriv&quot;, mathjax TRUE) Now the math output looks good in both browsers. However, for Firefox users the version without MathJax might still be preferable as it renders faster with somewhat smoother output. LaTeX rendered by MathJax To preserve the LaTeX equations, the argument converter \"pandoc-mathjax\" can be used. Then, Pandoc converts the LaTeX text to HTML but preserves the LaTeX equations (in minimal HTML markup). set.seed(1090) exams2html(&quot;deriv&quot;, converter &quot;pandoc-mathjax&quot;, mathjax TRUE) The output is very similar to the MathML rendered MathJax above. However, note that the alignment in the equations is changed (from left to right). This is caused by Pandoc replacing the LaTeX {eqnarray*} environment employed in the \"deriv\" exercise by {aligned} environments. Practical considerations Original markup in exercise source files: Whether to use R\/Markdown (.Rmd) or R\/LaTeX (.Rnw) markup in the exercise source files is mostly a matter of taste. The former is probably somewhat easier to learn for beginners but generally differences are small if there is only moderate text formatting. It is also good practice to keep the formatting simple to be robust across the different output formats and more advanced math constructs should be checked carefully. MathML as default math markup: As of today (January 2019) it might seem more natural to use LaTeX rendered by MathJax as rmarkdown does. However, when HTML conversion was added to R\/exams in early 2012, MathML rendered by Firefox was the more robust choice. MathML has been preserved as the default since then because it can be rendered both by MathJax and some browsers. Pandoc vs. TtM: Pandoc is the default converter for all .Rmd exercises while TtM is still used by default for .Rnw exercises. The latter is mostly for backward compatibility but might change to Pandoc in the future. However, differences are not very large for most exercises anyway but some mathematical LaTeX constructs are just supported by one and not the other converter. Enabling MathJax rendering: Many modern learning management systems have MathJax enabled by default, e.g., in Moodle, Canvas, or OpenOLAT. There are a couple of caveats, though: First, the default MathJax configuration in Moodle and OpenOLAT switches off rendering of MathML. Second, some systems do not host their own copy of the MathJax library but employ a content delivery network (CDN). Thus, there is a small risk that the learning management system might be up and running but there are problems loading MathJax from the CDN. Moodle: As noted above the default configuration for Moodle has MathJax support (via a CDN) but switches off rendering of MathML. As exams2moodle(...) currently uses MathML markup by default, this necessitates Firefox or Safari for viewing the quizzes in Moodle. In contrast, exams2moodle(..., converter \"pandoc-mathjax\") would use LaTeX math markup and render it by MathJax (unless the Moodle configuration switched off MathJax support). Request: Feedback from Moodle users would be appreciated on whether they prefer the current default or converter \"pandoc-mathjax\". It would be especially useful to find out whether the latter works in their Moodle installations. Canvas: We are currently working on a dedicated exams2qti12()-based function exams2canvas() for generating quizzes for Canvas. This will keep the MathML-based default for the math notation as this is rendered smoothly by Canvas\u2019 own MathJax support. OpenOLAT: A new dedicated interface exams2openolat() for generating quizzes for OpenOLAT has been added recently to R\/exams (version 2.3-1). By default, this is a wrapper to exams2qti21(..., converter \"pandoc-mathjax\") because OpenOLAT provides MathJax rendering of LaTeX math (but not MathML). Some additional tweaks are necessary, though, because OpenOLAT expects the LaTeX to be embedded slightly differently from standard Pandoc output. Further technical details The mathematical equation in the random draw of the deriv exercise in LaTeX is: f(x) x^{8} e^{3.4x}. Here, we highlight that all converters yield almost equivalent output when rendered by MathJax: \"pandoc-mathjax\" \"ttm\" \"pandoc-mathml\" \$$f(x) x^{8} e^{3.4x}\$$ f(x)x8e3.4x f(x)x8e3.4xf(x) x^{8} e^{3.4x} (Note: If you are viewing this on R-bloggers or another aggregator some or all of the equations will not display correctly. Refer to the R\/exams site for a version with MathJax properly enabled.) The underlying LaTeX code generated by converter \"pandoc-mathjax\" is simply the original LaTeX code with some minimal HTML markup: &lt;span class\"math inline\"&gt;\$$f(x) x^{8} e^{3.4x}\$$&lt;\/span&gt; The MathML code generated by converter \"ttm\" differs slightly from the of converter \"pandoc\" (or equivalently \"pandoc-mathml\"). The former yields: &lt;math xmlns&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt; &lt;mrow&gt;&lt;mi&gt;f&lt;\/mi&gt;&lt;mo stretchy&quot;false&quot;&gt;(&lt;\/mo&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;mo stretchy&quot;false&quot;&gt;)&lt;\/mo&gt;&lt;mo&gt;&lt;\/mo&gt; &lt;msup&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;8&lt;\/mn&gt;&lt;\/mrow&gt; &lt;\/msup&gt; &lt;msup&gt;&lt;mrow&gt;&lt;mi&gt;e&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;3&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;4&lt;\/mn&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;\/mrow&gt; &lt;\/msup&gt; &lt;\/mrow&gt;&lt;\/math&gt; The Pandoc version is very similar but contains some more markup and annotation: &lt;math display&quot;inline&quot; xmlns&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;semantics&gt; &lt;mrow&gt;&lt;mi&gt;f&lt;\/mi&gt; &lt;mo stretchy&quot;false&quot; form&quot;prefix&quot;&gt;(&lt;\/mo&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;mo stretchy&quot;false&quot; form&quot;postfix&quot;&gt;)&lt;\/mo&gt; &lt;mo&gt;&lt;\/mo&gt; &lt;msup&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;mn&gt;8&lt;\/mn&gt;&lt;\/msup&gt;&lt;msup&gt;&lt;mi&gt;e&lt;\/mi&gt;&lt;mrow&gt;&lt;mn&gt;3.4&lt;\/mn&gt;&lt;mi&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;\/msup&gt; &lt;\/mrow&gt;&lt;annotation encoding&quot;application\/x-tex&quot;&gt;f(x) x^{8} e^{3.4x}&lt;\/annotation&gt; &lt;\/semantics&gt;&lt;\/math&gt;","keywords":"","datePublished":"2019-01-27T17:00:00-06:00","dateModified":"2019-01-27T17:00:00-06:00","author":{"@type":"Person","name":"R\/exams","description":"","url":"https:\/\/www.r-bloggers.com\/author\/rexams\/","sameAs":["http:\/\/www.R-exams.org\/"],"image":{"@type":"ImageObject","url":"https:\/\/secure.gravatar.com\/avatar\/fefbfabd646a37d7e4b34c0dc8b37b03?s=96&d=mm&r=g","height":96,"width":96}},"publisher":{"@id":"https:\/\/www.r-bloggers.com#Organization"},"image":[{"@type":"ImageObject","url":"http:\/\/www.r-exams.org\/images\/laptop_on_table_deriv2.title.jpg","width":970,"height":485,"@id":"https:\/\/www.r-bloggers.com\/mathematical-notation-in-online-r-exams\/#primaryimage"},{"@type":"ImageObject","url":"http:\/\/www.r-exams.org\/assets\/posts\/2019-01-28-math\/deriv-mathml-firefox.png","width":379,"height":286},{"@type":"ImageObject","url":"http:\/\/www.r-exams.org\/assets\/posts\/2019-01-28-math\/deriv-mathml-chrome.png","width":379,"height":286},{"@type":"ImageObject","url":"http:\/\/www.r-exams.org\/assets\/posts\/2019-01-28-math\/deriv-mathml-mathjax-firefox.png","width":379,"height":286},{"@type":"ImageObject","url":"http:\/\/www.r-exams.org\/assets\/posts\/2019-01-28-math\/deriv-mathml-mathjax-chrome.png","width":379,"height":286},{"@type":"ImageObject","url":"http:\/\/www.r-exams.org\/assets\/posts\/2019-01-28-math\/deriv-mathjax-firefox.png","width":379,"height":286},{"@type":"ImageObject","url":"http:\/\/www.r-exams.org\/assets\/posts\/2019-01-28-math\/deriv-mathjax-chrome.png","width":379,"height":286}],"isPartOf":{"@id":"https:\/\/www.r-bloggers.com\/mathematical-notation-in-online-r-exams\/#webpage"}}]}] var snp_f = []; var snp_hostname = new RegExp(location.host); var snp_http = new RegExp("^(http|https)://", "i"); var snp_cookie_prefix = ''; var snp_separate_cookies = false; var snp_ajax_url = 'https://www.r-bloggers.com/wp-admin/admin-ajax.php'; var snp_ajax_nonce = 'fe262801c3'; var snp_ignore_cookies = false; var snp_enable_analytics_events = false; var snp_enable_mobile = false; var snp_use_in_all = false; var snp_excluded_urls = []; snp_excluded_urls.push(''); Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts. (You will not see this message again.) Click here to close (This popup will not appear again).snp-pop-109583 .snp-theme6 { max-width: 700px;} .snp-pop-109583 .snp-theme6 h1 {font-size: 17px;} .snp-pop-109583 .snp-theme6 { color: #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field ::-webkit-input-placeholder { color: #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field :-moz-placeholder { color: #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field :-ms-input-placeholder { color: #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field input { border: 1px solid #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field { color: #000000;} .snp-pop-109583 .snp-theme6 { background: #f2f2f2;}jQuery(document).ready(function() { }); var CaptchaCallback = function() { jQuery('.g-recaptcha').each(function(index, el) { grecaptcha.render(el, { 'sitekey' : '' }); }); }; window.FPConfig= { delay: 0, ignoreKeywords: ["\/wp-admin","\/wp-login.php","\/cart","add-to-cart","logout","#","?",".png",".jpeg",".jpg",".gif",".svg"], maxRPS: 3, hoverDelay: 50 }; _stq = window._stq || []; _stq.push([ 'view', {v:'ext',j:'1:7.3.2',blog:'11524731',post:'176635',tz:'-6',srv:'www.r-bloggers.com'} ]); _stq.push([ 'clickTrackerInit', '11524731', '176635' ]); jQuery(document).ready(function ($) { //$( document ).ajaxStart(function() { //}); for (var i = 0; i < document.forms.length; ++i) { var form = document.forms[i]; if ($(form).attr("method") != "get") {$(form).append('<input type="hidden" name="GHNaODVTJFSYB" value="op7Odnce_NhG]" />'); } if ($(form).attr("method") != "get") {$(form).append('<input type="hidden" name="ML_x-YAPOWRitp" value="rSVJs@[UOxp*6i" />'); } if ($(form).attr("method") != "get") {$(form).append('<input type="hidden" name="TCtPxySXocwH" value="]prG[vyHFTbx" />'); } if ($(form).attr("method") != "get") {$(form).append('<input type="hidden" name="gRDJ_Wn" value="cErYB4J" />'); } } $(document).on('submit', 'form', function () { if ($(this).attr("method") != "get") { $(this).append('<input type="hidden" name="GHNaODVTJFSYB" value="op7Odnce_NhG]" />'); } if ($(this).attr("method") != "get") { $(this).append('<input type="hidden" name="ML_x-YAPOWRitp" value="rSVJs@[UOxp*6i" />'); } if ($(this).attr("method") != "get") { $(this).append('<input type="hidden" name="TCtPxySXocwH" value="]prG[vyHFTbx" />'); } if ($(this).attr("method") != "get") { \$(this).append('<input type="hidden" name="gRDJ_Wn" value="cErYB4J" />'); } return true; }); jQuery.ajaxSetup({ beforeSend: function (e, data) { //console.log(Object.getOwnPropertyNames(data).sort()); //console.log(data.type); if (data.type !== 'POST') return; if (typeof data.data === 'object' && data.data !== null) { data.data.append("GHNaODVTJFSYB", "op7Odnce_NhG]"); data.data.append("ML_x-YAPOWRitp", "rSVJs@[UOxp*6i"); data.data.append("TCtPxySXocwH", "]prG[vyHFTbx"); data.data.append("gRDJ_Wn", "cErYB4J"); } else { data.data = data.data + '&GHNaODVTJFSYB=op7Odnce_NhG]&ML_x-YAPOWRitp=rSVJs@[UOxp*6i&TCtPxySXocwH=]prG[vyHFTbx&gRDJ_Wn=cErYB4J'; } } }); }); `