7

I use org-mode to write documents that are both exported into PDF via latex and HTML.

I use the package siunitx to typeset numbers with si-units. It is a bit tedious to do but I got used to it (unless I figure out how to make this work under org-mode).

When I export to HTML the things written in the siunitx-syntax are exported as plain text. I found out that org-mode uses MathJax for its HTML export. There is a third-party extensions for MathJax that is supposed to export siunitx syntax correctly to HTML.

How do I get org-mode to use this third party extension when exporting via HTML?

UPDATE:

Using the suggestion from @Nick I pasted the code into my user.el file. The code appears correctly in the org-html-mathjax-template variable. The HTML did not how the units correctly in a test file.

Looking at the HTML file, the script appears just before the </head>and beginning of the document in this form:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<script type="text/javascript">
<!--/*--><![CDATA[/*><!--*/
    MathJax.Hub.Config({
        // Only one of the two following lines, depending on user settings
        // First allows browser-native MathML display, second forces HTML/CSS
        jax: ["input/TeX", "output/HTML-CSS"],
        extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js",
                     "TeX/noUndefined.js", "[Contrib]/siunitx/siunitx.js", "[Contrib]/mhchem/mhchem.js"],
        tex2jax: {
            inlineMath: [ ["\\(","\\)"] ],
            displayMath: [ ['$$','$$'], ["\\[","\\]"], ["\\begin{displaymath}","\\end{displaymath}"] ],
            skipTags: ["script","noscript","style","textarea","pre","code"],
            ignoreClass: "tex2jax_ignore",
            processEscapes: false,
            processEnvironments: true,
            preview: "TeX"
        },
        TeX: {extensions: ["AMSmath.js","AMSsymbols.js",  "[Contrib]/siunitx/siunitx.js", "[Contrib]/mhchem/mhchem.js"]},
        showProcessingMessages: true,
        displayAlign: "center",
        displayIndent: "0em",

        "HTML-CSS": {
             scale: 100,
             availableFonts: ["STIX","TeX"],
             preferredFont: "TeX",
             webFont: "TeX",
             imageFont: "TeX",
             showMathMenu: true,
        },
        MMLorHTML: {
             prefer: {
                 MSIE:    "MML",
                 Firefox: "MML",
                 Opera:   "HTML",
                 other:   "HTML"
             }
        }
    });
/*]]>*///-->
</script>

@Nick also suggested to check the developer mode in the browser (Chromium on OSX in my case). However, I have no idea what to look for.

**UPDATE:*

Since MathJax is not hosted on its normal cdn.mathjax.org siunitx and mchem are not working (in addition to accesibility-menu.js ??). I am not able to solve the issue but this is as for as I got:

(setq org-html-mathjax-template
      "
<script type=\"text/javascript\" src=\"%PATH\"></script>
<script type=\"text/javascript\">
<!--/*--><![CDATA[/*><!--*/
MathJax.Ajax.config.path['mhchem'] = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax-mhchem/3.2.0';
MathJax.Ajax.config.path['siunitx']  = 'http://rawgit.com/burnpanck/MathJax-siunitx/master/';
    MathJax.Hub.Config({
        jax: [\"input/TeX\", \"output/HTML-CSS\"],
        extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
                     \"TeX/noUndefined.js\", \"[siunitx]/siunitx.js\", \"[mhchem]/mhchem.js\"],
tex2jax: {
inlineMath:[[\"\\\\(\",\"\\\\)\"] ],
displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
ignoreClass: \"tex2jax_ignore\",
processEscapes: false,
processEnvironments: true,
preview: \"TeX\"
},
TeX: {extensions: [\"AMSmath.js\",\"AMSsymbols.js\",  \"[siunitx]/siunitx.js\", \"[mhchem]/mchem.js\"]},
showProcessingMessages: true,
displayAlign: \"%ALIGN\",
displayIndent: \"%INDENT\",

\"HTML-CSS\": {
scale: %SCALE,
availableFonts: [\"STIX\",\"TeX\"],
preferredFont: \"TeX\",
webFont: \"TeX\",
imageFont: \"TeX\",
showMathMenu: true,
},
MMLorHTML: {
prefer: {
MSIE:    \"MML\",
Firefox: \"MML\",
Opera:   \"HTML\",
other:   \"HTML\"
}
}
});


/*]]>*///-->
</script>"
      )

Any idea how to get them running again? @Nick

1 Answer 1

5

You have to set the variable org-html-mathjax-template appropriately. Assuming you are using the default configuration, loading mathjax from cdn.mathjax.org, then the following setting (which loads the mhchem extension, as well as the siunitx extension, but also contains ancient cruft that might no longer be needed, or might even cause problems) works for me, but I would suggest you look at and save your current setting, before trying to reset it:

;; modify path and mathml
(setq org-html-mathjax-options
  '((path "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML")
    (scale "100")
    (align "center")
    (indent "2em")
    (mathml t)))

(setq org-html-mathjax-template
              "
<script type=\"text/javascript\" src=\"%PATH\"></script>
<script type=\"text/javascript\">
<!--/*--><![CDATA[/*><!--*/
    MathJax.Hub.Config({
        jax: [\"input/TeX\", \"output/HTML-CSS\"],
        extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
                     \"TeX/noUndefined.js\", \"[Contrib]/siunitx/siunitx.js\", \"[Contrib]/mhchem/mhchem.js\"],
        tex2jax: {
            inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
            displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
            skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
            ignoreClass: \"tex2jax_ignore\",
            processEscapes: false,
            processEnvironments: true,
            preview: \"TeX\"
        },
        TeX: {extensions: [\"AMSmath.js\",\"AMSsymbols.js\",  \"[Contrib]/siunitx/siunitx.js\", \"[Contrib]/mhchem/mhchem.js\"]},
        showProcessingMessages: true,
        displayAlign: \"%ALIGN\",
        displayIndent: \"%INDENT\",

        \"HTML-CSS\": {
             scale: %SCALE,
             availableFonts: [\"STIX\",\"TeX\"],
             preferredFont: \"TeX\",
             webFont: \"TeX\",
             imageFont: \"TeX\",
             showMathMenu: true,
        },
        MMLorHTML: {
             prefer: {
                 MSIE:    \"MML\",
                 Firefox: \"MML\",
                 Opera:   \"HTML\",
                 other:   \"HTML\"
             }
        }
    });
/*]]>*///-->
</script>")

The principal changes are the addition of the two extensions to the extensions field as well as to the TeX.extensions field.

Note that the value of org-html-mathjax-template is a single long string.

EDIT: Just for completeness, the last piece that was missing is that the LaTeX code in the org file has to be surrounded by math delimiters - that's what MathJax is looking for in order to process the LaTeX snippet(s). See the comments below for more details.

13
  • I tried simply copying and restarting emacs but nothing seems to change. I am using Scimax from John Kitchin. In the files I found that ox-html.el is defining the variable. However, I thought that changing it manually should overwrite it. If I access org-html-mathjax-template through customize-variable I see the script you posted above. Any other idea what could be happening?
    – Cumol
    Mar 7, 2017 at 15:16
  • Make sure you've copied it exactly first. Then take a look at the html file that the export produces and make sure that everything looks as it should. Then enable the developer tools on your browser, reload the html file and look at the console for errors. It is very finicky (DAMHIKT), so anything you can do to make errors visible will pay you back ten-fold.
    – NickD
    Mar 7, 2017 at 15:28
  • Updated in the main post. I don't exactly know how things are supposed to look. There is no obvious error that jumps up when I open the file in developer mode.
    – Cumol
    Mar 7, 2017 at 15:43
  • 1
    I posted my working example at gist.github.com/ndokos/fe7ad0ea34cf98345b4c02b1f7f014bc - tested with Chrome and Firefox on Fedora 24.
    – NickD
    Mar 7, 2017 at 16:52
  • 1
    You can use any marker that signals math mode: $$ ... $$ and \[ ... \] work for displayed math e.g. The markers are defined in org-html-mathjax-template as well: look for inlineMath and displayMath in texjax. But I think you need markers of some sort in order for MathJax to find and process a snippet.
    – NickD
    Mar 7, 2017 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.