Is it possible to set default options for pandoc?
Asked Answered
T

1

16

Is it at all possible to set default options for pandoc? For example, I always want to use xelatex to generate PDFs, and as far as I can tell, my options for doing so are to pass --latex-engine=xelatex to every invocation of pandoc, or to write a wrapper script that just calls pandoc with that option.

Both of these seem suboptimal to me, and nearly every other command-line program has ways to get around this. Sometimes it's done with an environment variable in the shell (something like setting PANDOC_OPTS="--latex-engine=xelatex"), and other times it's a configuration file (ala ~/.gitconfig or the like). I know pandoc has a data directory at ~/.pandoc, but from my reading of the documentation there is no way to do this.

Troy answered 18/10, 2016 at 15:16 Comment(1)
you can also set an alias in your ~/.bash_profile or similar file...Knish
J
15

Since pandoc 2.8, one can provide default options via the --defaults command line parameter:

-d FILE, --defaults=FILE

Specify a set of default option settings. FILE is a YAML file whose fields correspond to command-line option settings. All options for document conversion, including input and output files, can be set using a defaults file. The file will be searched for first in the working directory, and then in the defaults subdirectory of the user data directory (see --data-dir). The .yaml extension may be omitted. See the section Default files for more information on the file format. Settings from the defaults file may be overridden or extended by subsequent options on the command line.

Jorgan answered 25/11, 2019 at 8:1 Comment(4)
Oh wow, I'd forgotten I even wanted this. Thanks for digging this question up!Troy
Can you actually set a... default defaults file?Salenasalene
@Salenasalene no, but you can place a file, say detly.yaml in the $USERDATA/defaults directory, where $USERDATA is the folder reported by pandoc -v – you might have to create the folder first. With that in place you can run pandoc -d detly.Jorgan
@Jorgan yeah, I saw that in the docs. it doesn't help with tools that call pandoc themselves though. I was hoping to set up a default template and set of options.Salenasalene

© 2022 - 2024 — McMap. All rights reserved.