chirun-ncl / chirun

A Python package providing the command line interface for building flexible and accessible content with Chirun.
https://chirun.org.uk/
Other
29 stars 4 forks source link

Alt text #5

Open prowlett opened 4 years ago

prowlett commented 4 years ago

What is the approach to putting alt text on images in coursebuilder? I've seen various suggestions for how to add alt text in LaTeX online, but I'm asking what you use to do this in a way that works in coursebuilder for the web and PDF versions. Thanks.

christianp commented 4 years ago

plasTeX seems to have no concept of alt text for images. You can't add keyword options to LaTeX macros willy-nilly, so we'd have to define a new macro which renders to \includegraphics in latex, but has an alt keyword option that plasTeX can use.

A \caption inside a figure environment is rendered as a figcaption element, which becomes the figure's accessible text. So, the following:

\begin{figure}
  \includegraphics{image.png}
  \caption{An image}
\end{figure}

will be read out as "Figure 1 An image". It doesn't look like figure* or caption* omits the figure counter.

prowlett commented 4 years ago

The code

\begin{figure}
  \includegraphics{image.png}
  \caption{An image}
\end{figure}

produces something like

<figure id="axxxxxxxxxx">
<p>
<img src=".../images/img-0001.jpg"/>
</p>
<figcaption>
<span class="caption_title"><b>Figure</b></span>
<span class="caption_ref"><b>1</b></span>
<span class="caption_text">An image</span>
</figcaption>
</figure>

I am not an expert, but I suspect a screenreader might read "image without alt text. Figure 1 An image", which is not ideal.

Also there is an issue here that a figure caption is not the same thing as alt text - a caption contextualises what you are seeing, an alt tag should replace seeing it.

It has nice features around course organisation, but a major draw for using coursebuilder is the idea that it eats LaTeX and produces accessible notes. Images without alt text are a major gap in this mission that I would urge you to prioritise.

georgestagg commented 4 years ago

Alt text has been implemented as part of c57ab7bdd2106cffc087b57ec2ba604269896095.

Here is an example using the new \alt{} macro to add alt text to an image:

\begin{figure}
\includegraphics[width=10cm]{images/hist.pdf}
\caption{A histogram originally provided in .pdf format}
\alt{A plot titled "A histogram". The x axis is labelled "x-axis".
    The y axis is labelled "Frequency". The histogram shows a peak at
    a value of approximately 70.}
\end{figure}
prowlett commented 4 years ago

Works brilliantly! I can use \includegraphics (including with PDF) or draw something directly in tikz and it appears in HTML with alt text. Thanks @extigy and @christianp so much, that's very helpful!

Lycanic commented 4 months ago

A note: The current implentation of this is with \alttext{}, not \alt{}

pkra commented 4 months ago

FYI (years later)the official LaTeX syntax is \includegraphics[alt={the alt text}]{theImage}

christianp commented 4 months ago

Ah! Let's support that, then.

christianp commented 4 months ago

@Lycanic: since LaTeX has official syntax for this now, we should add support for it to plasTeX and deprecate the \alttext command.

pkra commented 4 months ago

For completeness, I think this is the relevant PR https://github.com/latex3/latex2e/pull/669

pkra commented 4 months ago

FWIW I still think your macro is a good idea (and more ideas are needed - see for example https://github.com/AmerMathSoc/texml/issues/55). The new LaTeX syntax is rather limited given that WCAG 1.1.1 requires text alternatives for any non-text content (and at least on the web those text alternatives can be provided in many different ways).

prowlett commented 4 months ago

This is a good point. Also a lot of my \alttext{} are on TikZ graphics that become <img> tags but were never \includegraphics{} commands. I was quite excited about this new format until I remembered that!