course-access

R Markdown worksheets

This chapter walks through the pipeline for documents knitted from R Markdown: worksheets, problem sets, solutions, and examples. Fixes belong in the source wherever possible. The knitted PDF, if it is posted, is the exception: knitting regenerates it without tags, so it needs to be remediated after every knit.

An R Markdown document and each of its outputs reach a listener differently:

Format Figure descriptions Equations Structure
The .Rmd file Shown as text in each chunk’s header (fig.alt) LaTeX source Markdown headings, read as text
Knitted HTML Real alt text on every plot, from fig.alt MathJax, which screen readers can read Real headings, if the source’s levels are right
Knitted PDF None until remediated Untagged until remediated None until remediated: pdfTeX writes no tags

If you are posting output from a .Rmd, we recommend posting the HTML. It is accessible as knitted: alt text from fig.alt, real headings, math a screen reader can read, and it reflows when a reader zooms in. A PDF can be posted as well, for students who prefer to print or annotate one, but it takes extra work after every knit: stage 4 below, or the cheaper route of printing the HTML to a tagged PDF.

Figure descriptions are written in the .Rmd itself: each plot chunk’s fig.alt option holds the plot’s alt text, and knitting carries it into the HTML (1. Describe figures in the source). Nothing needs to be added to the HTML by hand.

Evidence: our practice; the HTML and PDF behavior found by inspecting files (knitted HTML and PDFs).

The stages below follow one order: describe and repair in the source, check the HTML, then remediate the PDF if posting. Everything in stages 1 to 3 can be done in RStudio. Stage 4 is needed only if you post the PDF, and needs Adobe Acrobat Pro. Stage 4 is described as done by hand; the script for it, rmd_pdf.py, is in tools (With an AI assistant or the scripts, in 4e). Rules from figures and equations apply throughout and are cited by ID.

Status: draft. Nothing in the knitted PDFs has yet been heard with a screen reader.


Before you start


1. Describe figures in the source

What and why. The chunk option fig.alt gives a plot alt text in the knitted HTML. Written once in the source, it survives every re-knit, and the same approved text is reused if a PDF is remediated. It also reaches students who knit the .Rmd themselves, but only if they knit to HTML: with output: pdf_document as the .Rmd’s default, their PDF has no alt text, so output: html_document is the better default for a file students knit.

Describe from the knitted HTML, not from the code. The code says what was asked for; the figure shows what came out, including values. Check any value quoted in a description against the printed output. (F10.)

Write fixed text. fig.alt can be computed from the data, but then every student reads extra code that has nothing to do with the lesson. We write descriptions as plain text, so students new to R see only the code the lesson is about.

```{r score-hours, fig.alt="Scatterplot of exam score against hours studied, for 120 students. Scores rise with hours, steeply up to about 10 hours and then more slowly; the points spread more widely at higher hours."}
plot(df$hours, df$score)
```

With an AI assistant. The assistant reads each plot from the knitted HTML, checks quoted values against the printed output, writes each description into its chunk’s fig.alt, and lists every description it wrote. The instructor reviews each one in the .Rmd: edits it, or leaves it to approve. The approved text is what the PDF reuses.

Evidence: our practice.


2. Repair the source

What and why. HTML output, and screen readers, depend on things that a PDF tolerates or hides. These are the problems we found in our own worksheets:

With an AI assistant. The assistant lists each fix; the instructor accepts or skips each one and makes the content decisions (what a hypothesis should say, what to cut).

Evidence: our practice; the run-in heading and list problems found by inspecting files (our own knitted PDFs). The lang setting is our analysis: we have not yet checked our own HTML for it.


3. Check the knitted HTML

After the instructor re-knits, open the HTML and check:

The worksheet is not finished until this check is done on the re-knitted file. An assistant that can open the HTML file can run every check but the math rendering from the page source, and lists what fails.

Equations in the HTML. MathJax, which shows the equations, adds hidden math markup that screen readers can use. With VoiceOver in Safari, display equations were read well and could be explored piece by piece, but inline math in a sentence was read as a separate item, breaking up the sentence, and every equation was a Tab stop. NVDA has not been tested (test results).

Evidence: our practice; equations found in testing (VoiceOver with Safari, October 2026).


4. Remediate the knitted PDF

What and why. pdfTeX, which knits R Markdown to PDF, writes no tags: no headings, no reading order, no alt text. A screen reader gets the page’s text as one undifferentiated stream, and every plot and display equation is silent. A first set of tags has to come from somewhere, and for us that is Acrobat Pro’s Autotag. Autotag guesses structure from the page’s layout, and on knitted worksheets it guesses wrong in consistent ways, so its tags are corrected in four passes.

Because every knit produces a new untagged PDF, keep the approved figure descriptions and equation readings in one place (a text file beside the .Rmd), ready to paste in again after the next knit.

Acrobat Pro’s menu and panel names change between versions, so the steps below name the tools (Autotag, the tags panel, the reading-order tool) rather than menu paths.

4a. Autotag once, on the fresh knit

Run Acrobat’s Autotag (the accessibility tools’ automatic tagging) on the knitted PDF, and keep a copy of the result. Never Autotag a file that has already been corrected: it discards the corrections (E6 gives the same rule for slides).

4b. Sort what Autotag called a figure

Autotag tags anything that doesn’t look like ordinary text as a figure. On one of our worksheets it found 27 figures: 6 plots, 10 display equations, and 11 lines of code or output. The table also lists the other tags it got wrong on our worksheets.

Autotag’s tag What it is Fix
Figure A plot Keep as a figure; add the approved fig.alt text as its alternate text
Figure A display equation Retag as a formula, with a written reading (E7 to E11)
Text A display equation Retag as a formula, with a written reading
Figure A line of code or console output Retag as a paragraph, so it is read as text
Aside, Table, or List A code chunk or its output (with ## read as table cells) Retag as paragraphs and spans, read as text, as in the HTML
Figure A paragraph that contains some math Retag as a paragraph
Figure Inline math on its own Retag as a formula, with a written reading
Heading The subtitle or date Retag as a paragraph
Heading A bold lead-in at the start of a paragraph Retag as part of the paragraph
Footnote A table’s notes, such as the significance-stars legend under a model table Retag as a paragraph
Link Code text that looks like a web address Remove the link; retag as text
Nothing, or a paragraph Page numbers Mark as artifacts

The plot descriptions are the ones already approved for fig.alt: the PDF’s plots come from the same code, so they need no new review beyond checking that the PDF shows the same figures in the same order. Equation readings are new work, because the HTML needs none. Without one, a display equation’s text comes out as a jumble of symbols; one chi-squared sum read as “χ 2= K X i=1 z 2i”.

Evidence: found by inspecting files (the tags of our knitted PDFs after Autotag).

4c. Fix headings and reading order

Evidence: found by inspecting files (the tags of our knitted PDFs).

4d. Fix inline symbols a screen reader would misread

Autotag leaves math inside sentences as text, and some of pdfTeX’s characters read wrongly:

In the .Rmd In the PDF’s text Likely heard as Should be
\neq A slash drawn over “=” “equals” “not equal to”
\mu The micro sign “micro” “mu”
e^{\beta_1} e, then a raised beta and 1, with nothing marking the superscript “e beta 1” “e to the power of beta sub 1”

Not every symbol is a problem: \ll came through as the much-less-than character, which is likely read correctly (“much less than”).

The not-equal problem matters most: an alternative hypothesis sounds like its null. We fix the first two in the PDF by giving each symbol its own replacement text (a span with ActualText), which leaves the page looking the same. This is impractical by hand in Acrobat and is done by tools/rmd_pdf.py. Superscripts need the same fix, which our script doesn’t do yet. Two source-level fixes may remove the need, though we have not tried them: LaTeX’s accsupp package can attach replacement text to \neq in the source, and the newer LaTeX tagging route (below) handles math differently.

Students who use screen readers can also work from the HTML, where MathJax stores these symbols correctly; past worksheets with the problem are a lower priority than new ones.

Evidence: the characters found by inspecting files (our knitted PDFs); “micro” from published documentation (NVDA’s symbol list). Not yet heard with a screen reader, before or after the fix.

4e. Check before posting

tools/pdf_audit.py lists a PDF’s tags, figures with their alt text, and headings in order, for the checks that don’t need Acrobat.

With an AI assistant or the scripts. tools/rmd_pdf.py carries out 4b to 4d from a file of the approved texts (config drafts it from the .Rmd: headings, real lists, the fig.alt texts) and runs the checks in 4e, except Acrobat’s own checker. Two things stay by hand, and the checks point to them: a code or output block Autotag split so that its reading order still jumps (name the block’s range in the file), and a whole page Autotag tagged as one paragraph. An assistant drafts the equation readings for the instructor to approve. The instructor knits, runs Autotag, and approves every text before it is written.

Evidence: our practice.


Alternatives we tried or considered

Printing the HTML to a tagged PDF. We printed a knitted HTML worksheet to PDF with Chromium, the open-source browser Chrome is built on, with tagging turned on. The result was tagged: figures carried their alt text, headings mirrored the HTML, the title and bookmarks were set, and code was readable as text. Two notes for anyone trying this: in Chrome, use its own Save as PDF, which uses the same engine; the macOS print dialog does not tag the file. Math was not tested. Evidence: found by inspecting files (a PDF saved from Chromium, October 2026).

maidr in every setup chunk. maidr::maidr_on() makes the ggplot2 plots in the knitted HTML explorable by keyboard, sound, and braille. In our test it also dropped those plots’ fig.alt text and captions from the HTML, removed them from the knitted PDF, left base R plots unchanged, and loaded its code from the web, unpinned, every time the page opened. We don’t use it in posted documents. Turning it on for HTML output only (if (knitr::is_html_output()) maidr::maidr_on()) may avoid the PDF problem; we have not tested that. Evidence: found in testing and found by inspecting files (R 4.6.0, maidr 0.4.0, rmarkdown 2.31, and knitr 1.51, October 2026): a maidr plot opened from the console was explored by keyboard and heard (test results); what maidr_on() does to knitted documents was found in the knitted files. For students using maidr themselves, see working in R with a screen reader.

Tagging at the source. Quarto can render to a tagged PDF (pdf-standard: ua-2, with a recent TeX Live or Typst), where fig-alt reportedly carries into the PDF; LaTeX’s own tagging (\DocumentMetadata{tagging=on}) does the same for documents written in LaTeX. Either could retire the Autotag step. We have not tried them.


Untested or open