rstudio / bookdown

Authoring Books and Technical Documents with R Markdown
https://pkgs.rstudio.com/bookdown/
GNU General Public License v3.0
3.75k stars 1.26k forks source link

Pandoc variables specific to a format could be passed in the format function instead of top level in the YAML. #918

Open umarcor opened 4 years ago

umarcor commented 4 years ago

When trying to use options such as documentclass, lof, biblio-title, margin-left or margin-right in the preamble of the index/root Rmd file, I found that only adding them at the top-level would work:

site: bookdown::bookdown_site
bibliography: ["Rmd/refs.bib"]
csl: Rmd/ieee.csl
link-citations: yes
documentclass: report
lof: yes
biblio-title: References
margin-left: 35mm
margin-right: 35mm
output:
  bookdown::gitbook:
    config:
      info: no
    bookdown::pdf_book:
      toc_depth: 4
      includes:
        in_header: Rmd/preamble.tex
      latex_engine: xelatex
      citation_package: biblatex
      keep_tex: yes
    bookdown::epub_book: default

Instead, I would have expected those keys to be supported in output > bookdown::pdf_book::

site: bookdown::bookdown_site
bibliography: ["Rmd/refs.bib"]
csl: Rmd/ieee.csl
link-citations: yes
output:
  bookdown::gitbook:
    config:
      info: no
    bookdown::pdf_book:
      toc_depth: 4
      includes:
        in_header: Rmd/preamble.tex
      latex_engine: xelatex
      citation_package: biblatex
      keep_tex: yes
      documentclass: report
      lof: yes
      biblio-title: References
      margin-left: 35mm
      margin-right: 35mm
    bookdown::epub_book: default

However, if I use the latter format, those options seem to be silently ignored.

Find full example repo: LarsAsplund/github-facts.

cderv commented 3 years ago

Those keys are Pandoc variables define in YAML metablock (https://pandoc.org/MANUAL.html#extension-yaml_metadata_block) - they are not used by rmarkdown output format directly in R and only processed by Pandoc.

This is the way you need to specified those variables.

We maybe offer new ways to provide some keys but this would be a rmarkdown change and it would still use Pandoc feature (default file or metadata file perhaps)

However, I understand the idea of specific format option not at top level. This would more work to support as rmarkdown would need to know which are Pandoc variables, and pass them to Pandoc directly, whereas now Pandoc is reading the variable from the YAML header directly.

Thanks for the suggestion and having open the discussion. We'll not consider it in the near feature but this may attract some 👍 in the future, and it will be interesting to consider if we rething how to pass variable to Pandoc template.