Would anyone be able to help me understand the behaviour of different output formats with respect to figures? Specifically, when attempting to control sizing via the fig.retina knitr parameter on a figure chunk, the word_document format outputs markdown into the intermediate .md document, e.g. ![](figures/chunkN-N.png){width=NNN}
, while document_md and pure knitr outputs a an HTML tag with the size parameter.
What baffles me is that the word_document format seems to override standard knitr behaviour; I would like to reuse this in custom docx-based formats where it is useful to control image size e.g. via the fig.retina parameter. This currently works in word_document but does not work in e.g. redoc, which outputs tags which are then ignored by Pandoc when converting to .docx - unlike the {width=NNN} notation.
Reprex:
Source (with chunk backticks moved around to preserve code formatting)
---
title: "figures"
output:
word_document: default
md_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
``
no sizing:
```{r}
plot(pressure)
``
fig.retina set:
```{r, fig.retina=3}
plot(pressure)
``
Resulting .md file for format md_document using rmarkdown::render():
no sizing:
![](fig_sizing_reprex_files/figure-markdown_strict/unnamed-chunk-1-1.png)
fig.retina set:
<img src="fig_sizing_reprex_files/figure-markdown_strict/unnamed-chunk-2-1.png" width="672" />
Resulting .md file from knitr::knit("file.Rmd")
no sizing:
![](fig_sizing_reprex_files/figure-markdown_strict/unnamed-chunk-1-1.png)
fig.retina set:
<img src="fig_sizing_reprex_files/figure-markdown_strict/unnamed-chunk-2-1.png" width="672" />
resulting intermediate .knit.md file for word_document format, using rmarkdown::render():
---
title: "figures"
output:
word_document:
keep_md: true
md_document: default
---
no sizing:
![](fig_sizing_reprex_files/figure-docx/unnamed-chunk-1-1.png)<!-- -->
fig.retina set:
![](fig_sizing_reprex_files/figure-docx/unnamed-chunk-2-1.png){width=480}
with the difference also reflected in the resulting word doc.
Any pointers as to which part of the rmarkdown format functions matters for this would be greatly appreciated.
knitr 1.28
rmarkdown 2.1
R 3.6.2
pandoc 2.7.2