Document Accessibility

Document Accessibility
MathJax, Semantics and Accessibility

Volker Sorge

University of Birmingham, UK University of Birmingham Crest cs.bham.ac.uk/~vxs

MathJax Consortium MathJax Logo mathjax.org

Progressive Accessiblity Solutions Progressive Access Logo progacc.com

Overview

Understanding MathJax

There are other rendering solutions out there: KaTeX, MathQuill, MathLive

Including MathJax

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.

Revisiting the Example

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:

Configuring MathJax

Configuration element can be added in script tag before MathJax is loaded.

Basic configuration

<script>
MathJax = {
  tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']]
  }
}
</scrip>

This allows the use of $ signs for inline mathematics.

See MathJax Documentation at http://docs.mathjax.org/ for details

Configuration example with Macros

MathJax = {
  tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']],
    macros: {
      RR: "{\\bf R}",
      bold: ["{\\bf #1}", 1]
    }
  }
}

A Macro Example

Download the example file

\documentclass{article}

\begin{document}

\section{Slash command}

\[A\slash B\]

\end{document}

Note that \slash is a new macro.

Translate the File

    pandoc slash.tex -o slash.html --standalone --mathjax

or with make4ht

make4ht slash.tex "mathjax"
  1. Define the macro via a \newcommand as you would in the preamble of you LaTeX file.
  2. Give it to MathJax in its configuration.

Using newcommand

  1. Add an invisible 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.

Add macro to the configuration

  1. Add the following code into your 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!

Difference between pandoc and make4ht

pandoc

make4ht

Adding a New Environment

\[
    \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} $$

MathJax = {
    tex: {
        environments: {
          braced: ["\\left\\{", "\\right\\}"]
        }
      }
    };

make4ht configuration

<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'] 

Accessibility

Math rendered with MathJax is pretty much accessible out of the box

Example: Interactivity and Screenreading

Click or focus on the formula and press ENTER to start, Escape to quit.

Compute Speech

Switching on Speech output

Speech output can be switched on via:

Forcing Speech output on a page

Add the following configuration in your example file or add the option part to the existing configuration.

MathJax = {
    options: {
      menuOptions: {
        settings: {
          explorer: true
        }
      }
   }
}
Tab to a formula and press ENTER. What can you observe?

Note, that user selected options always overwrite developer selected options Note also, that in future version accessibility will be provided by default.

Alternative Formats for Math

Click or focus on the formula and press ENTER to start, Escape to quit.

Other Formats:

Customising Accessibility

There are multiple ways to customise accessibility

We will look at configurations.

A11y Configuration

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?

Semantics

Generate Semantics

    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>

Embedding Semantics

<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

Outlook