Closed pierrethibault closed 6 years ago
What kind of support do you have in mind? Can't you just include siunitx (through \usepackage{siunitx}) in latex output and apply the package for latex and html output?
Then I am missing something. How can I ensure that, e.g., !bt \SI{1}{Pa} = \SI{1}{N/m^2} !et is rendered correctly with "doconce format html" ?
Alright what I have figured out is that the section <script type="text/x-mathjax-config">
has to be modified to add the line:
MathJax.Ajax.config.path["Contrib"] = "https://cdn.mathjax.org/mathjax/contrib";
and with
"[Contrib]/siunitx/unpacked/siunitx.js"
in the extensions list. All I'd need is a recommendation on how to do this. Some kind of post-processing of the html file? Thanks.
Alright. Not very elegant but adding this at the beginning of the document works:
# #if FORMAT in ("html")
<script type="text/x-mathjax-config">
MathJax.Ajax.config.path["Contrib"] = "https://cdn.mathjax.org/mathjax/contrib";
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "AMS" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js", "[Contrib]/siunitx/unpacked/siunitx.js"]
}
});
</script>
# #endif
And for latex, I used instead --latex_preamble
to insert the \usepackage{siunitx}
.
OK, we could offer --units to get the latex and html versions. Any idea how it works with sphinx and ipynb?
Apparently in both cases one has to insert this script somewhere:
<script type="text/x-mathjax-config">
MathJax.Ajax.config.path["Contrib"] = "https://cdn.mathjax.org/mathjax/contrib";
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "AMS" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js", "[Contrib]/siunitx/unpacked/siunitx.js"]
}
});
</script>
I don't know the best way to do it for sphinx. Maybe directly in a css file? (As in https://github.com/numerical-mooc/numerical-mooc/blob/master/styles/numericalmoocstyle.css).
For ipynb, one way to do it is to execute a cell with
from IPython.core.display import HTML
HTML(r"""
<script>
MathJax.Ajax.config.path["Contrib"] = "https://cdn.mathjax.org/mathjax/contrib";
MathJax.Hub.Config({
TeX: {
extensions: ["[Contrib]/siunitx/unpacked/siunitx.js"]
}
});
</script>
""")
Ipython has an offline mathjax library, whereas this requires an internet connection. Also third-party extensions work only for mathjax versions >= 2.5.
It seems to me that Sphinx hides MathJax options from the user so we are not able to adjust the settings. I do not think incorporating MathJax into css files is the way to go - it would require hacking all the css files for all Sphinx styles. Direct hacking of the .html files seems to be a better option.
So far, I have added a command-line argument --siunits that incorporates the siunitx package in latex and html/mathjax. Not sure if your special hack is better since it becomes a hack anyway...
It would be nice to have support for SI units. The LaTeX package siunitx has a mathjax version (https://github.com/mathjax/MathJax-third-party-extensions/tree/master/siunitx) so it looks like a good candidate.