MathJax Macros with arguments
I'm trying to follow the docs to create my own macros, but am struggling with certain ones. For example, how would I create either of these macros in a way that works?
mathengine = Documenter.MathJax3(Dict(:TeX => Dict(
:equationNumbers => Dict(:autoNumber => "AMS"),
:Macros => Dict(
:t => ["\\text#1", 1],
:dx => ["\\frac{d#2}{d#1}", 2, "x"],
),
)))
(the latter is from mathjax docs).
It's not clear to me what you are asking. I assume you tried out the example from the manual you are quoting, and something didn't work. But what exactly didn't work? What's the concrete issue?
@haakon-e ping
Thanks for the critical questions. In hindsight I should have provided a more comprehensive reproducer. It seems like the \text macro works in MathJax3 now, but not \frac. Both work with MathJax2.
I created an empty package TestPackage with pkg> generate TestPackage
then added
docs/make.jl
docs/Project.toml # with Documenter, TestPackage as dependencies
docs/src/index.md
index.md has the following contents:
hello world
```math
\ket{\phi}, \bra{\phi}
```
```math
\dyx{y}
```
```math
\dx{x}{y}
```
make.jl has the following contents (illustrating two MathJax options)
using Documenter, TestPackage
macros = Dict(
:ket => ["|#1\\rangle", 1],
:bra => ["\\langle#1|", 1],
:dyx => ["\\frac{d#1}{dx}", 1],
:dx => ["\\frac{d#2}{d#1}", 2, "x"],
:t => ["\\text#1", 1],
)
v = 2
if v == 2
## With MathJax2
mathengine = Documenter.MathJax(Dict(:TeX => Dict(
:equationNumbers => Dict(:autoNumber => "AMS"),
:Macros => macros,
)))
elseif v == 3
## With MathJax3
mathengine = MathJax3(Dict(
:loader => Dict("load" => ["[tex]/physics"]),
:tex => Dict(
"inlineMath" => [["\$","\$"], ["\\(","\\)"]],
"tags" => "ams",
"packages" => ["base", "ams", "autoload", "physics"],
),
:Macros => macros,
))
end
makedocs(sitename="My docs", remotes=nothing,
format = Documenter.HTML(;mathengine)
)
With Documenter.MathJax, i.e. v=2, the docs compile as expected:
With Documenter.MathJax3, i.e. v=3, the equations do not compile
Hope this is more helpful!
Shouldn't the .macros section also go into the .tex section for MathJax v3? X-ref: https://docs.mathjax.org/en/v3.0/options/index.html#configuring-mathjax
So maybe something like this?
mathengine = MathJax3(Dict(
:loader => Dict("load" => ["[tex]/physics"]),
:tex => Dict(
"inlineMath" => [["\$","\$"], ["\\(","\\)"]],
"tags" => "ams",
"packages" => ["base", "ams", "autoload", "physics"],
"macros" => macros,
),
))
I tried both. It makes no difference:
mathengine = MathJax3(Dict(
:loader => Dict("load" => ["[tex]/physics"]),
:tex => Dict(
"inlineMath" => [["\$","\$"], ["\\(","\\)"]],
"tags" => "ams",
"packages" => ["base", "ams", "autoload", "physics"],
"macros" => macros,
),
:macros => macros,
))
My suggestion here would be to try to work backwards then. Take the generated HTML/JS site, look at the generated JS for this in assets/documenter.js, and try to figure out how to fix that. Once the JS works, then figure out if Documenter can generate the necessary JS already or we need to change something.