Daily Shaarli

All links of one day in a single page.

December 12, 2024

Amazing work by prof. McPherson: siunitx v3 for MathJax v3
thumbnail

This solves a major shortcoming when authoring documents in Quarto or R Markdown that generate both PDF and HTML output. MathJax lets the author use LaTeX commands in the source that translate into proper output in the HTML, but before this work there was no support for siunitx v3. This work can be said to take over where burnpanck/MathJax-siunitx left off.

To use it, I copied siunitx.js from its repo to my Quarto project and then made Quarto add it to the published site by setting the following in the project/document YAML:

project:
  resources:
    - "path/to/siunitx.js"
format:
  html:
    html-math-method:
      method: mathjax
      url: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"
    include-in-header:
      text: |
        <script>
        window.MathJax = {
          loader: {
            load: ['[custom]/siunitx.js', '[tex]/html'],
            paths: { custom: './path/to/' }
          },
          tex: {
            packages: { '[+]': ['siunitx', 'html'] },
            siunitx: {
              'per-mode': 'power'
            }
          }
        };
        </script>

And that should give you siunitx v3 commands in your Quarto manuscript :-)
Note that if you also want your notebooks to benefit from siunitx-pcc, you will need to symlink (or copy) the siunitx.js file into their top-level directory (which is ./notebooks) or otherwise siunitx macros will not render as paths: { custom: './path/to/' } is relative to their top-level directory and not (as you might think) the Quarto project root.
I have found that re-creating the directory structure mkdir -p notebooks/path/to; cd notebooks/path/to and then symlinking ln -s ../../../path/to/siunitx.js . works (don't forget to add another resources line: - "notebooks/path/to/siunitx.js").

In short, siunitx-pcc lets you use almost all siunitx macros.