logo

LaTeX Tagging Project

Accessible STEM documents


Reading Verbatim Code blocks

Verbatim has similar requirements to mathematics, in that symbols should ideally be read and not ignored or just read as pause, as is used for natural language text.

Default Reading

Reading with symbol pronunciation set to “All”

Screen readers have customisable settings for punctuation symbols, With NVDA, <nvda>p cycles between none, some (the default), many and all.

With all the reading is

It would be good if screen readers had a setting to automatically switch to this mode in <pre> (html) or /Code (pdf) contexts, but they do not currently.

Alt attribute

PDF has two main attributes to control the text used by AT, /Alt and /ActualText. The latter would affect other uses, such as cut and paste, preventing the common requirement to copy code out of the document. The mechansim used in the Example document on this site is for LaTeX to annotate each symbol with an Alt attribute, and to add an empty /Span with an /Alt to announce each new line.

Default Reading by character

Screen readers allow navigation by various units including movement by character, which is commonly used for code sections and other technical material.

The navigation of just the first line of the verbatim example is shown here.

In comparison to the previous section navigation by character with the code using `/Alt.

Reading the verbatim-alt code by character

Using MathML for each symbol

It is possible to use MathML, for example tag { as <math><mo>{</mo></math> This would not require any explicit tagging in the document, it could be added in the same way as the /Alt tagging described above. In the TeX source, simply by change the included additional module from verbatim-alt to verbatim-af.

Using a MathML table

An alternative way of using MathML would be to use an mtable with a :lines intent so that it isn’t announced as a matrix, but simply “3 lines; line 1 …, line 2 …”

Each line of the display is then encoded as, for example:

<mtr><mtd intent=":literal"><mtext> main</mtext><mo>(</mo><mtext> </mtext><mo>)</mo><mtext> </mtext><mo>{</mo></mtd></mtr>

Inline Code (LaTeX \verb, HTML <code>)

The above examples all show an example of a displayed code block (LaTeX verbatim environment). It is usually clear to a reader from the context that such a region is being added, and for example as the symbol pronunciation setting could be toggled manually to get the reading shown above just for the code block.

In addition, the original code file could be offered as an Embedded Associated file and made available by the PDF readers’s “Attached Files” menu., allowing the user to extract the code and process it in a code editor or other environemnt more directly suited to handling code in an accessible way.

Some experienced programmers may reasonably argue that for such code blocks it is not too important if the document-based reading misses details, as it is only used to skim over the code and all real use would be achieved by moving the code to a code editor. However, not all readers of documents that have such block use code editors, or are familiar enough with the programming language that not announcing syntax characters would be acceptable.

In addition, documents often have many small inline code fragments such as \LaTeX or <h2> or this_variable_name or class.method. In most cases it would not be appropriate to offer such fragments as files that may be extracted, and the user may have far less contextual information to tell them to switch reading style. In the absence of a mechanism to have the screen reader automatically increase the verbosity of symbol pronunciation in such code blocks, one of the methods discussed above to individually tag each symbol would seem preferable.