Open chrisdaaz opened 3 years ago
Great! I'll address this first to see if I can get some of the custom commands added!
Fixed macros for Diff, Partial, and FullDiff with commit cf683a5.
Need to figure out how to add packages.
Looks great!
Thanks! As far as I can tell, MathJax doesn't support loading LaTeX packages. MathJax is scoped to "only the math-mode macros of TeX and LaTeX, not the text-mode macros." We'll have to use R Markdown to format text.
That said, we're using a predefined configuration of MathJax that includes a number of extensions, such as:
the TeX, MathML, and AsciiMath preprocessors and input processors, the AMSmath, AMSsymbols, noErrors, and noUndefined TeX extensions, the CommonHTML output processor definitions, and the MathMenu and MathZoom extensions
There are a couple of third-party extensions that mimic LaTeX package behaviors in this repository. It looks pretty limited, though. Maybe there's more relevant additions in MathJax 3.x
It seems like there is some support for math-mode macros through packages such as "extensions" such as \color and \cancel (see here), but I don't understand how to adapt our mathjax.html to enable these extensions.
If we can put together an example with \color, I can try some other useful packages such as \units or \siunits (which are math-mode macros), which really save a lot of effort with the technical writing.
I think this is how we would edit mathjax.html to load extensions:
<!-- MathJax documentation: https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-macros -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
extensions: ["color.js", "mhchem.js"]
Macros: {
Diff: ["{\\mathop{} \\mathrm{d^{#1}}{#2}}", 2],
Partial: ["{\\mathop{} \\frac{\\partial^{#1}{#2}}{\\partial{#3}^{#1}}}", 3],
FullDiff: ["{\\mathop{} \\frac{\\mathrm{d}^{#1}{#2}}{\\mathrm{d}{#3}^{#1}}}", 3]
}
}
});
</script>
The above should load color and mhchem extensions. I couldn't find \units
or \siunits
in MathJax proper, but there's this third-party extension we can try: https://github.com/burnpanck/MathJax-siunitx
I've pushed a testing branch that includes these configurations, including a self-hosted copy of siunitx.js
. I don't know the LaTeX syntax or usage of these packages, so I haven't tried them out.
Thanks, I'll take a peek and test some of the TeX commands.
I may have got this working, sort of:
I used a sample the author of siunitx.js
provides here.
I'm using a self-hosted copy of the js
with this hack in the index.Rmd
file:
file.copy('siunitx.js', '_book/siunitx.js')
That line will copy static files to the output directory, which we use to serve the site.
That looks perfect - math mode always switches to Computer Modern font by default, which is why the text jumps back an forth with the in-line siunitx syntax. I'll play around with it a bit and look at how you loaded the extensions.
I've added an HTML insert for configuring MathJax in
mathjax.html
. This is where you might want to add some TeX macros or other MathJax configurations. I added a few fromjde_course.sty
but there may be others I missed.Links to relevant docs: