rstudio / bookdown

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

How to facultatively in/exclude latex customizations? #361

Closed r-cheologist closed 7 years ago

r-cheologist commented 7 years ago

Hello,

Currently my yaml header looks as follows:

---
title: "Johannes Graumann --- `r ifelse(params[['short']], 'Résumé', 'Curriculum Vitae')`"
date: "`r format(Sys.time(), '%d %B, %Y')`"
subtitle: |
  | \scriptsize Version (Git Hash): `r 
      stopifnot(sum(sapply(git2r::status(untracked = FALSE),length)) == 0)
      git2r::branch_target(git2r::head(git2r::repository(getwd())))`
output:
  bookdown::pdf_document2:
    includes:
      in_header: [
        "tex_customization/list_customizations.latex",
        "tex_customization/toc_customizations.latex",
        "tex_customization/pagenumber_customizations.latex"]
    template: NULL
    toc: false
colorlinks: true
fontsize: "`r ifelse(params[['short']], '10pt', '11pt')`"
documentclass: scrartcl
classoption: "`r if(params[['short']]){'smallheadings'}`"
geometry: margin=`r ifelse(params[['short']], '0.5in', '1in')`, a4paper
params:
    short: false
---

I would like to amend this such that if params[['short']] == TRUE, the tex_customization/pagenumber_customization.latex fragment is NOT loaded. Any hints on how that could be achieved?

Sincerely, Joh

yihui commented 7 years ago

Normally you can use the syntax !expr to write arbitrary R expressions in YAML under the output option, e.g.

output:
  bookdown::pdf_document2:
    includes:
      in_header: !expr c('tex_customization/list_customizations.latex', 'tex_customization/toc_customizations.latex', if (!params[['short']]) 'tex_customization/pagenumber_customizations.latex')

but since you used params, I'm not sure if it still works.

Here is a similar question on StackOverflow: http://stackoverflow.com/q/40801633/559676 and I'd recommend you to ask question on StackOverflow in the future.

github-actions[bot] commented 4 years ago

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.