Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Support out.width and out.height chunk options (and possibly fig.retina) as word_document does #63

Open
petrbouchal opened this issue Mar 9, 2020 · 1 comment

Comments

@petrbouchal
Copy link

petrbouchal commented Mar 9, 2020

When a figure size is set using the out.width/out.hight chunk option, or indirectly using fig.retina, the resulting figure is rendered in the intermediate markdown file with an <img> tag, which Pandoc ignores when converting to word. This differs from the behaviour of word_document and would be very useful in redoc.

fig_sizing_reprex_redoc.docx
fig_sizing_reprex_word.docx

Unfortunately I am not well versed enough in the rmarkdown internals to suggest a fix, but a hint might be in this knitr PR which made these chunk options effective in docx formats: yihui/knitr#1746


Session Info
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.3

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3        rstudioapi_0.11   knitr_1.28        xml2_1.2.2        magrittr_1.5     
 [6] uuid_0.1-4        R6_2.4.1          rlang_0.4.5       fansi_0.4.1       highr_0.8        
[11] httr_1.4.1        stringr_1.4.0     tools_3.6.2       packrat_0.5.0     xfun_0.12        
[16] sessioninfo_1.1.1 cli_2.0.2         withr_2.1.2       htmltools_0.4.0   yaml_2.2.1       
[21] assertthat_0.2.1  digest_0.6.25     crayon_1.3.4      zip_2.0.4         whoami_1.3.0     
[26] officer_0.3.7     glue_1.3.1.9000   evaluate_0.14     mime_0.9          rmarkdown_2.1    
[31] stringi_1.4.6     compiler_3.6.2    diffobj_0.2.3     redoc_0.1.0.9000  jsonlite_1.6.1   

Pandoc version (get with rmarkdown::pandoc_version): 2.7.3

RStudio version (if applicable): 1.3.885

rmarkdown version: 2.1

knitr version: 1.28

@petrbouchal
Copy link
Author

petrbouchal commented Mar 9, 2020

It seems the cause of this is the pandoc option to = "docx+empty_paragraphs" in redoc.R, which is not in the list of to values that trigger the use of a knitr hook.

A quick fix is to force this behaviour by adding

knitr::knit_hooks$set(plot = knitr:::hook_plot_md_pandoc)

in setup. I wonder if this can be somehow integrated in redoc(); I did it in a derived output format like so (approach courtesy of https://github.com/atlas-aai/ratlas/).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant