Unable to define LaTeX macros in Mathjax3 using Documenter.jl

I am trying to set up Documenter.jl with MathJax and I want to define some macros. I am doing as in the manual. However, it does not seem to work properly, as I get Undefined control sequence \R.

Below is an example copied from the manual where I have added a single macro.

mathengine = Documenter.MathJax3(Dict(
    :loader => Dict("load" => ["[tex]/physics"]),
    :tex => Dict(
        "inlineMath" => [["\$","\$"], ["\\(","\\)"]],
        "tags" => "ams",
        "packages" => ["base", "ams", "autoload", "physics"],
        "macros" => Dict("R" => "\\mathbb{R}")
        )))

Have I done it wrong?

I’m on my phone right now away from my desk so I can’t try it. But have you tried raw"\R" => "\\mathbb{R}" instead? Or "\\R" => "\\mathbb{R}"?

Yes, and :R => "\mathbb{R}".

However, using the browser’s developer tools, I see that the above code generates

window.MathJax = {
  "tex": {
    ...,
    "macros": {
      "R": "\\mathbb{R}"
    },
    ...
}
;

which is exactly what I want, so I find it strange that this is not working.

I have also looked at the documentation of other packages, such as DifferentialEquations.jl, Symbolics.jl, etc. However these seems to be using either the default KaTeX mathengine or mathjax without any custom macros. Does anyone know of any other packages whose documentation I can reverse engineer?

See docs of DFTK.jl, the relevant code is

mathengine  = Documenter.MathJax3(Dict(
    :tex => Dict(
        :inlineMath => [["\$","\$"], ["\\(","\\)"]],
        :tags       => "ams",
        :packages   => ["base", "ams", "autoload", "configmacros"],
        :macros     => Dict(
            :abs    => [raw"\left\|#1\right\|",     1],
            :ket    => [raw"\left|#1\right\rangle", 1],
            :bra    => [raw"\left\langle#1\right|", 1],
            :braket => [raw"\left\langle#1\middle|#2\right\rangle", 2],
        ),
    ),
))

I just come across it trying to learn how to doc.

3 Likes