14

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.

Michael M.
  • 613
  • 6
  • 14

1 Answers1

14

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.

tarleb
  • 19,863
  • 4
  • 51
  • 80
  • 4
    Oh wow, I'd forgotten I even wanted this. Thanks for digging this question up! – Michael M. Dec 12 '19 at 15:08
  • Can you actually set a... _default_ defaults file? – detly May 22 '23 at 02:42
  • @detly 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`. – tarleb May 22 '23 at 08:27
  • @tarleb 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. – detly May 22 '23 at 09:00