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

Illegal unit of measure in pdf with fig.retina in bookdown::pdf_document2 #1761

Closed
3 tasks done
chendaniely opened this issue Sep 12, 2019 · 4 comments
Closed
3 tasks done
Milestone

Comments

@chendaniely
Copy link

chendaniely commented Sep 12, 2019

Using the fig.retina knitr option causes an "Illegal unit of measure" when trying to generate a pdf when the output is bookdown::pdf_document2.

It seems like in the intermediate .tex file, the \includegraphics just has a number for the width, but does not have a unit.
For example:

\includegraphics[width=720]{/home/dchen/Desktop/04-data-workflows/analysis/figures/demo-multi-1} \caption{The caption.}\label{fig:demo-multi}

but chaning it to

\includegraphics[width=720px]{/home/dchen/Desktop/04-data-workflows/analysis/figures/demo-multi-1} \caption{The caption.}\label{fig:demo-multi}

will let me run pdflatex to generate the pdf.

Minimal example:

This works:

---
output:
  bookdown::pdf_document2: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r pressure, echo=FALSE}
plot(pressure)
```

This does not work:

---
output:
  bookdown::pdf_document2: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.retina = 3)
```

```{r pressure, echo=FALSE}
plot(pressure)
```

Returns this error:

/usr/lib/rstudio/bin/pandoc/pandoc +RTS -K512m -RTS asdf.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output asdf.tex --table-of-contents --toc-depth 2 --template /home/dchen/R/x86_64-pc-linux-gnu-library/3.6/rmarkdown/rmd/latex/default-1.17.0.2.tex --number-sections --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --wrap preserve --variable 'geometry:margin=1in' --variable 'compact-title:yes' --variable tables=yes --standalone 
output file: asdf.knit.md

! Illegal unit of measure (pt inserted).
<to be read again> 
                   \relax 
l.91 ...h=468]{asdf_files/figure-latex/pressure-1}

Error: Failed to compile asdf.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See asdf.log for more info.
Execution halted

My session info:

> devtools::session_info()
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.1 (2019-07-05)
 os       Antergos Linux              
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/New_York            
 date     2019-09-12                  

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version  date       lib source                          
 arsenal     * 3.3.0    2019-09-07 [1] CRAN (R 3.6.1)                  
 assertthat    0.2.1    2019-03-21 [1] CRAN (R 3.6.0)                  
 backports     1.1.4    2019-04-10 [1] CRAN (R 3.6.0)                  
 bookdown      0.13     2019-08-21 [1] CRAN (R 3.6.1)                  
 broom         0.5.2    2019-04-07 [1] CRAN (R 3.6.0)                  
 callr         3.3.1    2019-07-18 [1] CRAN (R 3.6.1)                  
 cellranger    1.1.0    2016-07-27 [1] CRAN (R 3.6.0)                  
 cli           1.1.0    2019-03-19 [1] CRAN (R 3.6.0)                  
 colorspace    1.4-1    2019-03-18 [1] CRAN (R 3.6.0)                  
 cowplot     * 1.0.0    2019-07-11 [1] CRAN (R 3.6.1)                  
 crayon        1.3.4    2017-09-16 [1] CRAN (R 3.6.0)                  
 data.table    1.12.2   2019-04-07 [1] CRAN (R 3.6.0)                  
 desc          1.2.0    2018-05-01 [1] CRAN (R 3.6.0)                  
 devtools      2.2.0    2019-09-07 [1] CRAN (R 3.6.1)                  
 digest        0.6.20   2019-07-04 [1] CRAN (R 3.6.1)                  
 dplyr       * 0.8.3    2019-07-04 [1] CRAN (R 3.6.1)                  
 DT            0.8      2019-08-07 [1] CRAN (R 3.6.1)                  
 ellipsis      0.2.0.1  2019-07-02 [1] CRAN (R 3.6.1)                  
 evaluate      0.14     2019-05-28 [1] CRAN (R 3.6.0)                  
 forcats     * 0.4.0    2019-02-17 [1] CRAN (R 3.6.0)                  
 fs            1.3.1    2019-05-06 [1] CRAN (R 3.6.1)                  
 generics      0.0.2    2018-11-29 [1] CRAN (R 3.6.0)                  
 ggplot2     * 3.2.1    2019-08-10 [1] CRAN (R 3.6.1)                  
 ggpubr      * 0.2.3    2019-09-03 [1] CRAN (R 3.6.1)                  
 ggsignif      0.6.0    2019-08-08 [1] CRAN (R 3.6.1)                  
 glue          1.3.1    2019-03-12 [1] CRAN (R 3.6.1)                  
 gridExtra     2.3      2017-09-09 [1] CRAN (R 3.6.0)                  
 gtable        0.3.0    2019-03-25 [1] CRAN (R 3.6.0)                  
 haven         2.1.1    2019-07-04 [1] CRAN (R 3.6.1)                  
 here        * 0.1      2017-05-28 [1] CRAN (R 3.6.0)                  
 hms           0.5.1    2019-08-23 [1] CRAN (R 3.6.1)                  
 htmltools     0.3.6    2017-04-28 [1] CRAN (R 3.6.0)                  
 htmlwidgets   1.3      2018-09-30 [1] CRAN (R 3.6.0)                  
 httr          1.4.1    2019-08-05 [1] CRAN (R 3.6.1)                  
 jsonlite      1.6      2018-12-07 [1] CRAN (R 3.6.0)                  
 km.ci         0.5-2    2009-08-30 [1] CRAN (R 3.6.1)                  
 KMsurv        0.1-5    2012-12-03 [1] CRAN (R 3.6.1)                  
 knitr         1.24     2019-08-08 [1] CRAN (R 3.6.1)                  
 labeling      0.3      2014-08-23 [1] CRAN (R 3.6.0)                  
 lattice       0.20-38  2018-11-04 [2] CRAN (R 3.6.1)                  
 lazyeval      0.2.2    2019-03-15 [1] CRAN (R 3.6.0)                  
 lubridate     1.7.4    2018-04-11 [1] CRAN (R 3.6.0)                  
 magrittr    * 1.5      2014-11-22 [1] CRAN (R 3.6.0)                  
 Matrix        1.2-17   2019-03-22 [2] CRAN (R 3.6.1)                  
 memoise       1.1.0    2017-04-21 [1] CRAN (R 3.6.0)                  
 modelr        0.1.5    2019-08-08 [1] CRAN (R 3.6.1)                  
 munsell       0.5.0    2018-06-12 [1] CRAN (R 3.6.0)                  
 nlme          3.1-141  2019-08-01 [1] CRAN (R 3.6.1)                  
 packrat       0.5.0-16 2019-07-02 [1] Github (rstudio/packrat@d7ad4c2)
 pillar        1.4.2    2019-06-29 [1] CRAN (R 3.6.1)                  
 pkgbuild      1.0.5    2019-08-26 [1] CRAN (R 3.6.1)                  
 pkgconfig     2.0.2    2018-08-16 [1] CRAN (R 3.6.0)                  
 pkgload       1.0.2    2018-10-29 [1] CRAN (R 3.6.0)                  
 prettyunits   1.0.2    2015-07-13 [1] CRAN (R 3.6.0)                  
 processx      3.4.1    2019-07-18 [1] CRAN (R 3.6.1)                  
 ps            1.3.0    2018-12-21 [1] CRAN (R 3.6.0)                  
 purrr       * 0.3.2    2019-03-15 [1] CRAN (R 3.6.0)                  
 R6            2.4.0    2019-02-14 [1] CRAN (R 3.6.0)                  
 Rcpp          1.0.2    2019-07-25 [1] CRAN (R 3.6.1)                  
 readr       * 1.3.1    2018-12-21 [1] CRAN (R 3.6.0)                  
 readxl        1.3.1    2019-03-13 [1] CRAN (R 3.6.0)                  
 remotes       2.1.0    2019-06-24 [1] CRAN (R 3.6.1)                  
 rlang         0.4.0    2019-06-25 [1] CRAN (R 3.6.0)                  
 rmarkdown     1.15     2019-08-21 [1] CRAN (R 3.6.1)                  
 rprojroot     1.3-2    2018-01-03 [1] CRAN (R 3.6.0)                  
 rsconnect     0.8.15   2019-07-22 [1] CRAN (R 3.6.1)                  
 rstudioapi    0.10     2019-03-19 [1] CRAN (R 3.6.0)                  
 rvest         0.3.4    2019-05-15 [1] CRAN (R 3.6.0)                  
 scales        1.0.0    2018-08-09 [1] CRAN (R 3.6.0)                  
 scico       * 1.1.0    2018-11-20 [1] CRAN (R 3.6.1)                  
 sessioninfo   1.1.1    2018-11-05 [1] CRAN (R 3.6.0)                  
 stringi       1.4.3    2019-03-12 [1] CRAN (R 3.6.0)                  
 stringr     * 1.4.0    2019-02-10 [1] CRAN (R 3.6.0)                  
 survival    * 2.44-1.1 2019-04-01 [2] CRAN (R 3.6.1)                  
 survminer   * 0.4.6    2019-09-03 [1] CRAN (R 3.6.1)                  
 survMisc      0.5.5    2018-07-05 [1] CRAN (R 3.6.1)                  
 testthat      2.2.1    2019-07-25 [1] CRAN (R 3.6.1)                  
 tibble      * 2.1.3    2019-06-06 [1] CRAN (R 3.6.0)                  
 tidyr       * 0.8.3    2019-03-01 [1] CRAN (R 3.6.0)                  
 tidyselect    0.2.5    2018-10-11 [1] CRAN (R 3.6.0)                  
 tidyverse   * 1.2.1    2017-11-14 [1] CRAN (R 3.6.0)                  
 usethis       1.5.1    2019-07-04 [1] CRAN (R 3.6.1)                  
 vctrs         0.2.0    2019-07-05 [1] CRAN (R 3.6.1)                  
 withr         2.1.2    2018-03-15 [1] CRAN (R 3.6.0)                  
 xfun          0.9      2019-08-21 [1] CRAN (R 3.6.1)                  
 xml2          1.2.2    2019-08-09 [1] CRAN (R 3.6.1)                  
 xtable        1.8-4    2019-04-21 [1] CRAN (R 3.6.0)                  
 yaml          2.2.0    2018-07-25 [1] CRAN (R 3.6.0)                  
 zeallot       0.1.0    2018-01-28 [1] CRAN (R 3.6.0)                  
 zoo           1.8-6    2019-05-28 [1] CRAN (R 3.6.0)                  

[1] /home/dchen/R/x86_64-pc-linux-gnu-library/3.6
[2] /usr/lib/R/library
> xfun::session_info('knitr')
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Antergos Linux, RStudio 1.2.1578

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

Package version:
  evaluate_0.14   glue_1.3.1      graphics_3.6.1  grDevices_3.6.1 highr_0.8       knitr_1.24     
  magrittr_1.5    markdown_1.1    methods_3.6.1   mime_0.7        stats_3.6.1     stringi_1.4.3  
  stringr_1.4.0   tools_3.6.1     utils_3.6.1     xfun_0.9        yaml_2.2.0  

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/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('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').
    • 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.

@yihui
Copy link
Owner

yihui commented Sep 12, 2019

The option fig.retina makes no sense for non-HTML output formats, as documented at: https://yihui.name/knitr/options/#plots

@chendaniely
Copy link
Author

chendaniely commented Sep 12, 2019

Thanks, Yihui. Now that you mention it, it does make sense that fig.retina should only make sense for HTML documents, but it seems like it's still being used when outputting to pdf (e.g., the \includegraphics[width=720] gets created in the tex file when fig.width=10 is set in the rmd document)

The example @apreshill had was being able to output to multiple types within the same rmd document, so all the options were in one setup chunk.

@yihui yihui closed this as completed in de1f51a Sep 13, 2019
@yihui yihui added this to the v1.25 milestone Sep 13, 2019
@yihui
Copy link
Owner

yihui commented Sep 13, 2019

I just pushed a commit to avoid the error, but fig.retina still does not make sense for LaTeX output.

Note that fig.retina = 2 for HTML output by default. You probably don't need to adjust the default, unless your eyes are really really good :) (I can't tell the difference between fig.retina = 2 and 3)

@github-actions
Copy link

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 Nov 10, 2020
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

2 participants