# Unable to define LaTeX macros in Mathjax3 using Documenter.jl

**URL:** <https://discourse.julialang.org/t/unable-to-define-latex-macros-in-mathjax3-using-documenter-jl/118813>\
**Category:** New to Julia\
**Tags:** question, documenter\
**Created:** [August 30, 2024, 2:23pm UTC](https://discourse.julialang.org/t/unable-to-define-latex-macros-in-mathjax3-using-documenter-jl/118813 "2024-08-30T14:23:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![msw](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@msw](https://discourse.julialang.org/u/msw)\
**Post date:** [August 30, 2024, 2:23pm UTC](https://discourse.julialang.org/t/unable-to-define-latex-macros-in-mathjax3-using-documenter-jl/118813/1 "2024-08-30T14:23:25Z")

</div>

I am trying to set up Documenter.jl with MathJax and I want to define some macros. I am doing as in the [manual](https://documenter.juliadocs.org/stable/man/latex/#Set-math-engine-and-define-macros-for-LaTeX). 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.

```julia
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?

---

<div class="post-metadata">

**Author:** ![kapple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapple/32/218915_2.png) [@kapple](https://discourse.julialang.org/u/kapple)\
**Post date:** [August 30, 2024, 10:45pm UTC](https://discourse.julialang.org/t/unable-to-define-latex-macros-in-mathjax3-using-documenter-jl/118813/2 "2024-08-30T22:45:24Z")

</div>

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}"`?

---

<div class="post-metadata">

**Author:** ![msw](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@msw](https://discourse.julialang.org/u/msw)\
**Post date:** [August 31, 2024, 8:05am UTC](https://discourse.julialang.org/t/unable-to-define-latex-macros-in-mathjax3-using-documenter-jl/118813/3 "2024-08-31T08:05:19Z")

</div>

> [@kapple](#):
>
> 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

```javascript
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?

---

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [September 1, 2024, 5:42am UTC](https://discourse.julialang.org/t/unable-to-define-latex-macros-in-mathjax3-using-documenter-jl/118813/4 "2024-09-01T05:42:23Z")

</div>

See docs of DFTK.jl, the relevant code is

```julia
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.
