Skip to content

[add] accessibility for num#86

Draft
Mc-Zen wants to merge 24 commits into
mainfrom
accessibility
Draft

[add] accessibility for num#86
Mc-Zen wants to merge 24 commits into
mainfrom
accessibility

Conversation

@Mc-Zen

@Mc-Zen Mc-Zen commented May 11, 2026

Copy link
Copy Markdown
Owner

This PR adds support for adding manual as well as automatic alt texts to standalone numbers, units and quantities for export to accessible formats like PDF UA-1.

This is done by adding a parameter alt that can be one of the following

  • a string for specifying a manual alt text
  • auto for automatic locale-aware description generation (PRs for adding more translations welcome!)
  • a dictionary with the keys times, plus, minus, and power. For English, the corresponding values would be "times", "plus", "minus", and "to the power of".
  • a function that receives a dictionary with the keys int, frac, decimal-separator, base, expoenent, abd uncertainty.

Currently available languages:

  • English
  • German
  • French
  • Spanish
  • Italian

Language addition PRs welcome!

Limitations:

  • In text mode, math: false, no alt text is added. This might change in the future.
  • For units, the grammar is somewhat limited to a reasonable level, eg currently no difference is made for singular/plural.
  • When a num, unit or quantity is inserted into an equation (like $a=#num[2.2e4]$) the alt text of the number will be dismissed since the equation is merged with the outer equation. Maybe Typst will add some modularity in the future.

Todo

  • Finish formatting uncertainties before creating the description (in order to avoid things like ".5" in the alt text).

Closes #82

@Mc-Zen

Mc-Zen commented Jun 28, 2026

Copy link
Copy Markdown
Owner Author

Hi @SeSodesa ,

I've added support for a distinction between singular/plural! Units in the dictionary are by default singular and the new pluralize dictionary defines a function for each language for how to form the plural. When many units are formed in the same simple way, this can profit from a generic rule. Otherwise, implementing just a dictionary for the plural version is also okay.

The plural is only applied to the last "atomic" unit in the numerator and only when the needs-plural check returns true. For most languages, this function only checks whether the value is 1 or not. French is a bit more particular, the absolute the value needs to be at least 2 for plural.

It would be great if you could update the Finnish translation to make use of these new capabilities!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing support for PDF/UA-1 export

2 participants