Skip to content

extra_dependencies and includes:in_header not working for PDF output. #930

Closed

Description

@j-magnolia

Steps to reproduce:

  1. Create a basic bookdown project using RStudio new project and choosing "Book project using bookdown"
  2. Test that bookdown::render_book("index.Rmd", bookdown::pdf_book()) builds correctly.
  3. Edit _output.yml to add extra_dependencies: "subfig" to the pdf_book output:
bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
  extra_dependencies: "subfig"
  1. Edit 04-application.Rmd to add the example code from https://bookdown.org/yihui/rmarkdown-cookbook/latex-subfigure.html:
## Example one

```{r subfig-test, fig.cap='Figure 1', fig.subcap=c('(a)', '(b)', '(c)'), fig.ncol=2, fig.align="center", out.width="50%"}
plot(1:10)
plot(cars, pch = 19)
boxplot(Sepal.Width ~ Species, data = iris)
```

## Example two
  1. Build using bookdown::render_book("index.Rmd", bookdown::pdf_book()).

Expected result:

I expect a PDF document like the one in the example at https://bookdown.org/yihui/rmarkdown-cookbook/latex-subfigure.html

Actual result:

XeLaTeX reports an error:

! Undefined control sequence
l.249 {\centering \subfloat
                           [(a)\label{fig:subfig-test-1}]{\includegraphics[w...

Error: LaTeX failed to compile Foo.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Foo.log for more info.

After this error I tried again, adding the line

\usepackage{subfig}

to preamble.tex, but I still got the same error.

Inspecting the generated Foo.tex file, there is neither an include{preamble.tex} nor a \usepackage{subfig}.

This error is similar to #888

> xfun::session_info("bookdown")
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363), RStudio 1.3.1056

Locale:
  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
  LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
  LC_TIME=English_United States.1252    

Package version:
  base64enc_0.1.3      bookdown_0.20.3      digest_0.6.25       
  evaluate_0.14        glue_1.4.1           graphics_4.0.2      
  grDevices_4.0.2      highr_0.8            htmltools_0.5.0     
  jsonlite_1.7.0       knitr_1.29           magrittr_1.5        
  markdown_1.1         methods_4.0.2        mime_0.9            
  rlang_0.4.7          rmarkdown_2.3.2.9003 stats_4.0.2         
  stringi_1.4.6        stringr_1.4.0        tinytex_0.25        
  tools_4.0.2          utils_4.0.2          xfun_0.16           
  yaml_2.2.1          

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('bookdown'). 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/bookdown').
    • 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.

Activity

  1. j-magnolia commented on Aug 21, 2020

    @j-magnolia
    ContributorAuthor

    The problem here is passing a constructed bookdown::pdf_book() object to render_book. If I pass a string instead:

    bookdown::render_book("index.Rmd", "bookdown::pdf_bpok")
    

    the book renders correctly.

    I am closing this issue.

  2. cderv commented on Aug 22, 2020

    @cderv
    Collaborator

    Seems like an issue 🤔 it should work the them with both type of input.

  3. yihui commented on Aug 22, 2020

    @yihui
    Collaborator

    I know why the previous way fails, but don't have time to explain in detail. I strongly recommend that you pass a character string instead of a function to the output format. In short, if you pass a function, you must provide all options in the function call. If you pass a string, it uses options provided in _output.yml.

    https://bookdown.org/yihui/bookdown/usage.html

  4. cderv commented on Aug 22, 2020

    @cderv
    Collaborator

    Oh ok ! Noted. Don’t need more explanation 😅
    Short and clear. I understand now.

  5. j-magnolia commented on Aug 22, 2020

    @j-magnolia
    ContributorAuthor

    It might be useful to add @yihui's comment above to the documentation for bookdown::render_book and rmarkdown::render:

    If you pass an output format object to output_format, you must set all the options when you construct the object.
    If you pass a string, the output format will use the options provided in _output.yml.

  6. cderv commented on Aug 22, 2020

    @cderv
    Collaborator

    I completely agree as I was also thinking about that. This would be a great addition. You can submit a PR or I’ll do that Monday.

  7. j-magnolia commented on Aug 23, 2020

    @j-magnolia
    ContributorAuthor

    PR #931 submitted.

  8. j-magnolia commented on Aug 27, 2020

    @j-magnolia
    ContributorAuthor

    I have closed PR #931 and submitted two new PRs: #958 and rstudio/rmarkdown#1907 to address the documentation primarily in rmarkdown, with a note in the bookdown::render_book() docs to look at the rmarkdown::render() docs for details on how the output_format argument is handled.

  9. github-actions commented on Mar 31, 2021

    @github-actions

    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.

  10. locked as resolved and limited conversation to collaborators on Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions