Convert CSL JSON (file or directory) via Pandoc
Source:R/csljson_convert_pandoc.R
csljson_convert_pandoc.RdConverts CSL JSON with Pandoc into one of: BibTeX, BibLaTeX, Docx, Markdown,
LaTeX, or PDF. Behavior depends on to:
bibtex/biblatex: creates bibliography files. For a directory of chunks, writeschunk_*.bibinto the directory given byoutput. For a single file, writes the specifiedoutput(appends.bibif missing).docx/markdown/latex/pdf: renders a formatted references document using citeproc. For a directory of chunks, writesreferences.<ext>insideoutput. For a single file, writes tooutput(appends extension if missing).
Usage
csljson_convert_pandoc(
csljson,
output,
to = c("biblatex", "bibtex", "docx", "markdown", "latex", "html", "pdf"),
from = "csljson",
overwrite = FALSE,
verbose = TRUE,
references_csl = NULL,
pdf_engine = "xelatex",
pdf_mainfont = NULL,
pdf_sansfont = NULL,
pdf_monofont = NULL,
pdf_cjk_mainfont = NULL,
pdf_cjk_options = NULL
)Arguments
- csljson
Path to a CSL JSON file (array) or a directory created by
corpus_to_csljson()containingchunk_*.jsonfiles.- output
Output path. For
bib*with a file input, this is the target.bibfile (extension added if missing). Forbib*with a directory input, this is the output directory. For formatted references (docx,markdown,latex,pdf), this is the output file (file input) or the output directory (dir input; file will bereferences.<ext>within).- to
One of
"biblatex","bibtex","docx","markdown","latex","html", or"pdf".- from
Source format; defaults to "csljson".
- overwrite
Logical; overwrite existing output file(s). Defaults to FALSE.
- verbose
Print progress messages.
- references_csl
Optional path to a CSL style file (e.g., apa.csl). If NULL, Pandoc's default style is used.
- pdf_engine
LaTeX engine used when
to = "pdf". Common values are"xelatex"(default, good Unicode support),"lualatex", or"pdflatex". Passed to Pandoc as--pdf-engine.- pdf_mainfont
Main text font name for PDF output (used with XeLaTeX/LuaLaTeX). Sets Pandoc variable
mainfont(e.g.,-V mainfont=Source Serif Pro).- pdf_sansfont
Sans‑serif font name for PDF output. Sets Pandoc variable
sansfont.- pdf_monofont
Monospace font name for PDF output. Sets Pandoc variable
monofont.- pdf_cjk_mainfont
Main CJK font name for PDF output. Sets Pandoc variable
CJKmainfontfor better East‑Asian typography.- pdf_cjk_options
Additional CJK options passed via Pandoc variable
CJKoptions(e.g., feature flags accepted byxeCJK).
Details
Requires Pandoc to be available. In RStudio, a bundled Pandoc is usually available; otherwise install Pandoc and ensure it is on PATH.
When rendering to = "pdf", this function maps the supplied PDF options to
Pandoc command line flags and variables as follows:
pdf_engine→--pdf-engine=<engine>pdf_mainfont,pdf_sansfont,pdf_monofont→-V mainfont=...,-V sansfont=...,-V monofont=...pdf_cjk_mainfont,pdf_cjk_options→-V CJKmainfont=...,-V CJKoptions=...
Use these to ensure Unicode coverage and consistent typography, especially for multilingual bibliographies.