University of Birmingham, UK cs.bham.ac.uk/~vxs
MathJax Consortium mathjax.org
Progressive Accessiblity Solutions progacc.com
There are other rendering solutions out there: KaTeX, MathQuill, MathLive
When running pandoc
or make4ht
with the appropriate options MathJax is
generally included. If not, it is easy to add a script tag to the header of the
HTML file:
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
This loads a basic configuration, which finds LaTeX and MathML code in the page and translates it into HTML with CSS styling.
MathJax still might need some costomization.
pandoc
or with make4ht
pandoc rademacher.tex -o rademacher.html --standalone --mathjax
make4ht rademacher.tex "mathjax"
This now should give nicely rendered math. The results are also available here:
Configuration element can be added in script
tag before MathJax is loaded.
<script>
MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
}
</scrip>
This allows the use of $
signs for inline mathematics.
See MathJax Documentation at http://docs.mathjax.org/ for details
MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
macros: {
RR: "{\\bf R}",
bold: ["{\\bf #1}", 1]
}
}
}
\documentclass{article}
\begin{document}
\section{Slash command}
\[A\slash B\]
\end{document}
Note that \slash
is a new macro.
pandoc
pandoc slash.tex -o slash.html --standalone --mathjax
or with make4ht
make4ht slash.tex "mathjax"
\slash
macro will lead to incorrect output in the browser.\newcommand
as you would in the preamble of you LaTeX
file.div
with the \newcommand
code before the first call of the macro: <div style="display:none">\(\newcommand{\slash}{\backslash}\)</div>
Note, that I gave the div
a style that makes sure it is not
displayed. Generally it is not necessary, but might make sense to avoid visual
output in case there is an error in your macro definition.
slash.html
file, before the script
tag loading MathJax. <script>
MathJax = {
tex: {
macros: {
slash: "\\backslash"
}
}
}
</script>
Make sure it is before the script
tag that loads MathJax!
pandoc
make4ht
newcommand
is only available in the newcommand
packagenewcommand
, we can add new environment via
newenvironment
\[
\newenvironment{braced}{\left\{}{\right\}}
\begin{braced}
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}
\end{braced}
\]
$$ \newenvironment{braced}{\left{}{\right}} \begin{braced} x = \frac{-b \pm \sqrt{b^2-4ac}}{2a} \end{braced} $$
newenvironment
is in Math mode, otherwise MathJax cannot see itMathJax = {
tex: {
environments: {
braced: ["\\left\\{", "\\right\\}"]
}
}
};
<script>
window.MathJax = {
tex: {
tags: "ams",
inlineMath: [ ["\\\(","\\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: true,
packages: ['base', 'color', 'ams'] },
loader: { load: ['[tex]/color', '[tex]/ams']
}
};
</script>
We need to add newcommand
to the packages list and ensure it is loaded:
packages: ['base', 'color', 'ams', 'newcommand'] },
loader: { load: ['[tex]/color', '[tex]/ams', '[tex]/newcommand']
Math rendered with MathJax is pretty much accessible out of the box
Speech output can be switched on via:
Add the following configuration in your example file or add the option part to the existing configuration.
MathJax = {
options: {
menuOptions: {
settings: {
explorer: true
}
}
}
}
Note, that user selected options always overwrite developer selected options Note also, that in future version accessibility will be provided by default.
Other Formats:
There are multiple ways to customise accessibility
renderActions
We will look at configurations.
Add the following to the options block in your example file:
MathJax = {
options: {
renderActions: {
addMenu: [0, '', '']
},
menuOptions: {
settings: {
explorer: true
}
},
a11y: {
backgroundColor: 'Green',
braille: true,
viewBraille: true
}
}
};
Reload the page. What can you observe?
ax^2+bx+c=0
<math>
<mi>a</mi>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<mi>b</mi>
<mi>x</mi>
<mo>+</mo>
<mi>c</mi>
<mo>=</mo>
<mn>0</mn>
</math>
<math><mi>a</mi><msup><mi>x</mi><mn>2</mn></msup>
<mo>+</mo><mi>b</mi><mi>x</mi><mo>+</mo><mi>c</mi>
<mo>=</mo><mn>0</mn></math>
internally into semantically improved term structure