0

This is a follow-up to knitr/Rmarkdown/pandoc : How to set bibliography paths globally in .Rmd files where a solution that works with knitr/rmarkdown/pandoc does NOT work with Quarto.

I have multiple .bib files in a system-wide localtexmf folder. I want to specify that some of these are searched for references in a quarto document. (I don't want to have to copy each of these to the project folder or specify full absolute or relative paths to these files.)

With knitr/rmarkdown/pandoc I can use:

bibliography:
- references.bib
- "`r system('kpsewhich graphics.bib', intern=TRUE)`"
- "`r system('kpsewhich statistics.bib', intern=TRUE)`"
- "`r system('kpsewhich timeref.bib', intern=TRUE)`"

However, using Quarto, this gives an error:

Preparing to preview
[1/2] intro.qmd
File r system('kpsewhich graphics.bib', intern=TRUE) not found in resource path

The system(kpsewhich()) command does find the files in the console:

> system('kpsewhich graphics.bib')
C:/Users/friendly/Dropbox/localtexmf/bibtex/bib/graphics.bib
[1] 0

How can I make this work using Quarto? Is there something different with the YAML syntax for Quarto? Is there some other way?

Edit: This may be a more general problem of using r function() in YAML with Quarto. This attempt to set the date: doesn't give an error, but yields Invalid date in the rendered book.

  date: "`r format(Sys.time(), '%B %d, %Y')`"

[This is now solved, using !expr format(Sys.time(), '%B %d, %Y') as suggested by @shafee.

Testing PDF:

Rendering to PDF gives more clues about why even the !expr solution doesn't work with Quarto. In the console, I get:

  bibliography:
    - references.bib
    - tag: '!expr'
      value: system('kpsewhich graphics.bib'
    - intern=TRUE)
    - tag: '!expr'
      value: system('kpsewhich statistics.bib'
    - tag: '!expr'
      value: system('kpsewhich timeref.bib'
  date:
    tag: '!expr'
    value: 'format(Sys.time(), ''%B %d, %Y'')'
  
File intern=TRUE) not found in resource path

so Quarto seems to have trouble parsing the system() call with the intern=TRUE option. This seems like a bug.

user101089
  • 3,756
  • 1
  • 26
  • 53

1 Answers1

1

Can you try like this under bibliography yaml key,

- !expr system('kpsewhich graphics.bib', intern=TRUE)

I haven't tested this but my hunch is, since quarto uses different syntax (see here) for evaluating R-code in yaml, maybe that's why it's thinking the given command in "`r ...`" as a file, instead of R-code.

shafee
  • 15,566
  • 3
  • 19
  • 47
  • Good suggestion! This seems to work, in that it does not generate an error. However, it does not find the references from my `.bib` files; I get a warning: **[WARNING] Citeproc: citation Timm:75 not found**. I'll have to investigate further ... – user101089 Aug 09 '22 at 16:11
  • Sorry I couldn't make any more hunchs about the warning you are having. :-) – shafee Aug 09 '22 at 16:31