Select output writer for Pandoc in the YAML metablock

Viewed 26

In order to specify an output format for pandoc, I must set the -t flag on the command line. I would like to specify which output format I want from inside of my Markdown text file. Is this possible?

For instance, if I wanted pandoc to convert my Markdown text file to a Microsoft Word document, I imagine it might look like this:

mydocument.md:

---
title: Not Just Good, More Good
author: DanielTA
date: 9 September 2022
geometry: margin=1in
mainfont: Comic Neue
fontsize: 12pt
output: docx
---

Document body text...

Then run pandoc mydocument.md which would output mydocument.docx into the same directory.

I tried this and it does not seem to work. I know that many command line variables can be defined in the YAML metablock header, but I am not sure if format/output options are possible to define there.

1 Answers

It's not possible to define this kind of information in the metadata. However, pandoc has a feature called "defaults files". Input and output formats, options, and filenames can all be put there. The file is then passed to pandoc via --defaults or -D.

pandoc -D docx.yaml mydocument.md

Alternatively, take a look at Quarto. It is a beautiful system based on pandoc and allows to incorporate this kind of info directly in the YAML frontmatter.

Related