Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support alt text for images in LaTeX output #2378

Merged
merged 4 commits into from
Oct 30, 2024
Merged

Conversation

capnrefsmmat
Copy link
Contributor

Since 2021, graphicx supports an alt option containing alt text. Pass fig.alt through unless knitr.include_graphics.alt is FALSE (which can be set if e.g. you're using an older TeX Live whose graphicx does not support this.)

Ongoing LaTeX work to support accessible (tagged) PDFs will eventually use this option to embed alt text in PDFs. See https://www.latex-project.org/publications/indexbytopic/pdf/

See also #1967.

I haven't contributed to knitr before, so not sure of a few things:

  1. I didn't see tests that checked \includegraphics output. Are there any tests I should change/add?
  2. I added the option because graphicx versions before 2021 will throw an error when they get alt text, so some users may want to turn this off. But I defaulted the option to TRUE, so the alt text is included in LaTeX output by default. Should it default to FALSE instead? The new behavior will be surprising to people with old TeX installs, but on the other hand fig.alt is doing nothing for them right now. At the least I could add a FAQ entry for the error they'd get.

Since 2021, graphicx supports an alt option containing alt text. Pass
fig.alt through unless knitr.include_graphics.alt is FALSE (which can be
set if e.g. you're using an older TeX Live whose graphicx does not
support this.)

Ongoing LaTeX work to support accessible (tagged) PDFs will eventually
use this option to embed alt text in PDFs.
@CLAassistant
Copy link

CLAassistant commented Oct 27, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You can either add tests to tests/testit/ (you can create a new script there) or add an example .Rnw document in the repo https://github.com/yihui/knitr-examples.
  2. I tend to keep it simple for now by not introducing a global option. If users have to use an old version of LaTeX, they still have the option of not using fig.alt.

Thanks!

@capnrefsmmat
Copy link
Contributor Author

Okay, I've removed the global option and added a test script.

Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@yihui yihui merged commit 8431f8a into yihui:master Oct 30, 2024
1 check passed
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.

3 participants