Unable to set CSL using pandoc_args in YAML

I would like to programmatically change some of the pandoc arguments for a custom output style. One of the arguments I'd like to be able to alter is for the CSL. I am able to alter this by using the appropriate entry in the YAML header, but not if set that option using pandoc_args. (The end goal is to have a function do this, but I'm working with YAML first to keep things simple.)

So, this works:

---
title: "Untitled"
output: word_document
bibliography: ref.bib
csl: ieee2.csl
---

As seen in [@R-animation]

# References

::: {#refs}
:::

But this does not:

---
title: "Untitled"
output: word_document
bibliography: ref.bib
pandoc_args: ["--csl=ieee2.csl"]
---

As seen in [@R-animation]

# References

::: {#refs}
:::

In case it matters:

  • The file "ieee2.csl" is a copy of a standard ieee.csl. Changed the name to ensure that it wasn't pulling from a system file somewhere.
  • The CSL file is at root, same place as the .Rmd files.
  • I've experimented with several flavors of quotation marks when using pandoc_args.
  • ref.bib is a standard LaTeX bibliography file.
  • Knitting by pressing CTRL+SHIFT+K in RStudio
  • I don't actually see the argument in the output which displays in the R Markdown tab in RStudio. The pandoc command at the end of that listing is:
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS mojo.knit.md --to docx --from markdown+autolink_bare_uris+tex_math_single_backslash --output mojo.docx --lua-filter 
 C:\Users\capta\Documents\R\libs\rmarkdown\rmarkdown\lua\pagebreak.lua" --highlight-style tango --citeproc"`

Did you also try the syntax used in
https://garrettgman.github.io/rmarkdown/word_document_format.html#pandoc-arguments
?

That approach works. I did not have the pandoc_args element as a child element of the output format. Correct syntax is:

---
title: "Untitled"
output: 
  word_document:
    pandoc_args: ["--csl=ieee2.csl"]
bibliography: ref.bib
---

As seen in [@R-animation]

# References

::: {#refs}
:::
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.