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

Add alt text to images added to Ppt via rmarkdown #2106

Closed
3 tasks done
jsgosnell opened this issue Apr 12, 2021 · 9 comments
Closed
3 tasks done

Add alt text to images added to Ppt via rmarkdown #2106

jsgosnell opened this issue Apr 12, 2021 · 9 comments
Labels
feature a feature request or enhancement theme: pandoc concerns upstream pandoc theme: powerpoint

Comments

@jsgosnell
Copy link

When using rmarkdown to add images to PowerPoint files, the alt text designation in the image tag becomes the title/caption. If using a web-based image, the url becomes the alt text. This isn't optimal for screen readers (the main reason I'm trying to add alt text to the images) (see answer provided to question on stackoverflow by Josh: https://stackoverflow.com/questions/66959628/how-do-you-add-alt-text-for-accessibility-to-images-in-powerpoint-files-create). Is it possible to update the code so the alt text truly becomes alt text and the caption is handled elsewhere (like a fig.cap argument)?

Example of issue:

---
title: "Making presentations in R"
author: "jsg"
date: "3/29/2021"
output: 
  powerpoint_presentation
---

## Issue example:  Puffin image

![This should be alt text and not caption](https://upload.wikimedia.org/wikipedia/commons/9/94/Puffin_Mrkoww.jpg)


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('rmarkdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/rmarkdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@apreshill
Copy link
Contributor

I'm seeing in both cases (local image and url) that the alt text populates the image path:
Screen Shot 2021-06-03 at 4 50 40 PM

Screen Shot 2021-06-03 at 4 50 27 PM

@apreshill
Copy link
Contributor

apreshill commented Jun 3, 2021

Source:

---

## Alt text does not work with urls

```
![look a puffin](https://upload.wikimedia.org/wikipedia/commons/9/94/Puffin_Mrkoww.jpg "Title: A proper puffin"){fig.alt="alt text: it is a very cute puffin."}
```

![look a puffin](https://upload.wikimedia.org/wikipedia/commons/9/94/Puffin_Mrkoww.jpg "Title: A proper puffin"){fig.alt="alt text: it is a very cute puffin."}

---

## Alt text does not work with local images either

```
![look a puffin](images/Puffin_Mrkoww.jpg "Title: A proper puffin"){fig.alt="alt text: it is a very cute puffin."}
```

![look a puffin](images/Puffin_Mrkoww.jpg "Title: A proper puffin"){fig.alt="alt text: it is a very cute puffin."}

@cderv
Copy link
Collaborator

cderv commented Jun 4, 2021

Just for context for me later, there are several things in this issue.

This markdown syntax

![This should be alt text and not caption](https://upload.wikimedia.org/wikipedia/commons/9/94/Puffin_Mrkoww.jpg)

will be processed by Pandoc and not knitr or rmarkdown directly. So better support for alt text in the Markdown syntax is something to do on the Pandoc side.

Doc about the syntax is here: https://pandoc.org/MANUAL.html#images

A link immediately preceded by a ! will be treated as an image. The link text will be used as the image’s alt text:

![la lune](lalune.jpg "Voyage to the moon")

But

Extension: implicit_figures
An image with nonempty alt text, occurring by itself in a paragraph, will be rendered as a figure with a caption. The image’s alt text will be used as the caption.

![This is the caption](/url/of/image.png)

So implit_figures extentions could have an impact, and this is not clear which formats supports what.

I have looked into this while working on adding fig.alt in knitr for figures. So this is related also to support for non HTML output format: yihui/knitr#1967
Main issues to support fig.alt chunk option for DOCX / PPTX is because this is buggy in Pandoc.

With DOCX, the syntax would work (in some way) - see yihui/knitr#1965 (comment)

![A plot](test_files/figure-docx/unnamed-chunk-1-1.png "Description")
Will lead to having

  • "A plot" as a image caption/legend
  • Both "A plot" and "Description" as alternative text description in WORD I got
Description

A plot

Oddly we don't get that with PPTX and I think you've found a new bug in Pandoc @apreshill ! It should at least be the same as with DOCX. I'll report that to Pandoc repo maybe.

Also I am curious about using {fig.alt="alt text: it is a very cute puffin."} as an attributes on Pandoc figure. Did you find this syntax somewhere ? I was not aware about this - I guess you tried it with Powerpoint because of link_attributes pandoc's extension ?

@cderv cderv added theme: pandoc concerns upstream pandoc feature a feature request or enhancement labels Jun 4, 2021
@apreshill
Copy link
Contributor

Thank you for filing that issue @cderv!

@apreshill
Copy link
Contributor

apreshill commented Jun 4, 2021

I tried the syntax I did because JJ told me to try: ![figure caption goes here](img.png){fig.alt="alt text here"} in another issue.

"You can just put fig.alt on any pandoc image (or use as a chunk attribute). Alternatively you can just use the native pandoc syntax for alt (quoted text after the image path). include_graphics should definitely not be required"

@cderv
Copy link
Collaborator

cderv commented Aug 18, 2021

Just to share that this will be taken into account in Pandoc. It has already been merged (see the issue in pandoc repo) and it will be available in a future Pandoc version.

@apreshill
Copy link
Contributor

Here is the PR: jgm/pandoc#7507

@cderv
Copy link
Collaborator

cderv commented Dec 24, 2021

Since Pandoc 2.14.2, It is now possible to pass a description text to inlucde in Powerpoint using the Title part of the syntax
https://pandoc.org/MANUAL.html#images

![used as caption](link "Description")

So with original example this should be

---
title: "Making presentations in R"
author: "jsg"
date: "3/29/2021"
output: 
  powerpoint_presentation
---

## Issue example:  Puffin image

![This is the caption](https://upload.wikimedia.org/wikipedia/commons/9/94/Puffin_Mrkoww.jpg "And here is more information in description")

image

This require a recent Pandoc which is included in RStudio current Daily version, and will be in next release.

Thanks for opening this issue!

@cderv cderv closed this as completed Dec 24, 2021
@github-actions
Copy link

github-actions bot commented Jul 5, 2022

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement theme: pandoc concerns upstream pandoc theme: powerpoint
Projects
None yet
Development

No branches or pull requests

3 participants