0

I’m trying to use org-mode to export something as an HTML document, with MathJax equations. I know that MathJax supports the physics package, so it seems like it should be possible to tell emacs to tell MathJax to load physics. But how?

The code suggested in the link above is

window.MathJax = {
  loader: {load: ['[tex]/physics']},
  tex: {packages: {'[+]': ['physics']}}
};

so I tried putting variations of these lines in the document:

  • #+HTML_MATHJAX: loader: {load: ['[tex]/physics']} tex: {packages: {'[+]': ['physics']}}
  • #+HTML_MATHJAX: load: ['[tex]/physics'] packages: {'[+]': ['physics']}

But neither worked. What’s the right way to do this?

Example:

#+TITLE: Some physics
^^^ What can I put here to use the physics package?

$\ket{-}=\frac{\ket{0}-\ket{1}}{\sqrt{2}}$

Edit: I put one solution down below that uses pandoc.

6
  • Try simply export via pandoc to html5. No other settings. See supported symbols here: docs.mathjax.org/en/latest/input/tex/macros/index.html – Ian May 20 at 13:05
  • Oh, I didn’t consider pandoc! That’s also worth trying. But still, when I run pandoc on this example file (via the shell, not through org-mode) I get errors, I think because pandoc also doesn’t know I need the physics package. I’ll update the question to be more specific. – James Weigle May 20 at 13:32
  • I suggested html5 - not simply html. Take into account there is a package ox-pandoc which can be added to your configuration and export from emacs. I use doom-emacs configured with (org +pandoc) but I am not pushing you to that (but useful if you need a fast solution). – Ian May 20 at 14:25
  • Okay, thanks, I’ve installed ox-pandoc. What should I do to make emacs use it? – James Weigle May 20 at 15:06
  • Please do not evolve a question by implementing comment suggestions and then saying, in effect, "I tried that and ran into this other problem: XYZ." The question should now be deleted/closed or edited to remove the additional questions. – Drew May 20 at 15:10
0

Okay, this works for my specific case (thanks to Ian’s comment):

  1. Install the package ox-pandoc.
  2. Customize the option org-pandoc-options-for-html5 to include mathjax set to t.
  3. Run the command org-pandoc-export-to-html5.
0

I've probably looked through every single piece of documentation related to Org Mode's LaTeX to HTML export and MathJax, and this is what I've got:

Launch Emacs, then open up your MathJax configuration using M-x org-customize. Go to Org Export -> Org Export HTML -> Org HTML MathJax template. There, you will find a window where you can edit the MathJax config.

Change it up so it looks like this:

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    displayAlign: "%ALIGN",
    displayIndent: "%INDENT",

    extensions: ["[Contrib]/physics/physics.js"],

    "HTML-CSS": { scale: %SCALE,
                    linebreaks: { automatic: "%LINEBREAKS" },
                    webFont: "%FONT"
                   },
    SVG: {scale: %SCALE,
          linebreaks: { automatic: "%LINEBREAKS" },
          font: "%FONT"},
    NativeMML: {scale: %SCALE},
    TeX: { equationNumbers: {autoNumber: "%AUTONUMBER"},
           MultLineWidth: "%MULTLINEWIDTH",
           TagSide: "%TAGSIDE",
           TagIndent: "%TAGINDENT"}
         }
});
</script>
<script type="text/javascript"
        src="%PATH"></script> 

The important line to add is:

extensions: ["[Contrib]/physics/physics.js"],

When you're in this editing mode the <return> key might not add a whitespace character. Remember that you can always add one using the C-o shortcut. After you're done select [ Apply and save ]. Now the physics package should be working properly.

New contributor
SaJmoN is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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