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

fig.cap and fig.alt appear redundant (fig.alt is preferred) #2029

Open
3 tasks done
alanocallaghan opened this issue Jul 20, 2021 · 5 comments
Open
3 tasks done

fig.cap and fig.alt appear redundant (fig.alt is preferred) #2029

alanocallaghan opened this issue Jul 20, 2021 · 5 comments
Assignees
Labels
feature Feature requests next Issues/PRs considered for the next release

Comments

@alanocallaghan
Copy link

I was very grateful to find the new alt-text feature. However it doesn't seem to work as described, and when both fig.cap and fig.alt are supplied, only fig.alt is present in the output. This is not ideal as alt-text may need be more detailed than the caption for some images.

I have made a tiny testing repo here to demonstrate: https://github.com/Alanocallaghan/testalt/
The issues page suggests zipfiles, so here's that repo as a zip too: testalt.zip

r$> xfun::session_info()                                                        
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Locale:
  LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
  LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
  LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
  LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

Package version:
  compiler_4.1.0  evaluate_0.14   glue_1.4.2      graphics_4.1.0 
  grDevices_4.1.0 highr_0.9       knitr_1.33.8    magrittr_2.0.1 
  markdown_1.1    methods_4.1.0   mime_0.11       parallel_4.1.0 
  png_0.1-7       stats_4.1.0     stringi_1.7.3   stringr_1.4.0  
  tools_4.1.0     utils_4.1.0     xfun_0.24       yaml_2.2.1     

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at .
  • 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.

      I am not asking a question

    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). 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('yihui/knitr').

      I have

    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.

      I have not posted it anywhere else

  • 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.

@cderv
Copy link
Collaborator

cderv commented Jul 21, 2021

Thanks for the report.
I worked on this feature, so I'll have a look at your reproducible example.
And then I'll have a look at your PR.

@cderv cderv self-assigned this Jul 21, 2021
@cderv
Copy link
Collaborator

cderv commented Jul 21, 2021

Can you clarify what results you are expecting ?

The fig.alt feature was made primarly for HTML output, and is not correctly supported in other type of output.
When I render the document to rmarkdown::html_document() using rmarkdown::render("test.Rmd", rmarkdown::html_document(keep_md=TRUE)", this is the content of the md file I get before convertion to HTML

---
title: Testing alt-text
output: 
  html_document:
    keep_md: true
---


```r
knitr::include_graphics("mcgriff.png")
```

<img src="mcgriff.png" width="340" />


```r
knitr::include_graphics("mcgriff.png")
```

<div class="figure">
<img src="mcgriff.png" alt="Caption only." width="340" />
<p class="caption">Caption only.</p>
</div>


```r
knitr::include_graphics("mcgriff.png")
```

<div class="figure">
<img src="mcgriff.png" alt="This has alt text too." width="340" />
<p class="caption">Caption and alt text.</p>
</div>


```r
knitr::include_graphics("mcgriff.png")
```

<img src="mcgriff.png" title="This only has alt text." alt="This only has alt text." width="340" />

It seems in this case, this is the expected result. isn't it ?

It would be interesting to have the detailed of what you expect. Either in the issue discussion here, or as detailed explanation in your PR.

Changing this feature is touchy and we need to make sure we improve one output without breaking another one. That is why I am interested in the detail of your use case (you are not using rmarkdown and only knitr ?

Thanks!

@alanocallaghan
Copy link
Author

alanocallaghan commented Jul 21, 2021

Yes, I am only using knitr to knit to a markdown document. You can see here that knitr::knit overwrites the fig.cap as the title attribute of the img tag when fig.alt is set.

Specifically, the output is:

---
title: Testing alt-text
---


```r
knitr::include_graphics("mcgriff.png")
```

![plot of chunk nothing](mcgriff.png)


```r
knitr::include_graphics("mcgriff.png")
```

![Caption only.](mcgriff.png)


```r
knitr::include_graphics("mcgriff.png")
```

<img src="mcgriff.png" title="This has alt text too." alt="This has alt text too."  />


```r
knitr::include_graphics("mcgriff.png")
```

<img src="mcgriff.png" title="This only has alt text." alt="This only has alt text."  />

while I would hope it would be

---
title: Testing alt-text
---


```r
knitr::include_graphics("mcgriff.png")
```

![plot of chunk nothing](mcgriff.png)


```r
knitr::include_graphics("mcgriff.png")
```

![Caption only.](mcgriff.png)


```r
knitr::include_graphics("mcgriff.png")
```

<img src="mcgriff.png" title="Caption and alt text." alt="This has alt text too."  />


```r
knitr::include_graphics("mcgriff.png")
```

<img src="mcgriff.png" title="This only has alt text." alt="This only has alt text."  />

@alanocallaghan
Copy link
Author

The reason I'm knitting to a markdown doc rather than html directly is because it's part of a jekyll site setup, fwiw. Part of a carpentries lesson.

@cderv
Copy link
Collaborator

cderv commented Jul 21, 2021

The reason I'm knitting to a markdown doc rather than html directly is because it's part of a jekyll site setup, fwiw. Part of a carpentries lesson.

That is really interesting. We don't have a jekyll_document indeed. So we need to make fig.alt supported for markdown output resulting of knitr::knit with Rmd input.

That makes sense to me now. Thanks for the precision!

@cderv cderv added feature Feature requests next Issues/PRs considered for the next release labels Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature requests next Issues/PRs considered for the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants