Search code examples
pandoc

Pandoc - Convert from Markdown to PDF and Set File Name From Metadata Title


YAML Metada looks like this

---
Tag: tag1, tag2
title: "Title I want to use"
Status: active
Name: "John Smith"
---

I currently use this command

for f in *.md; do pandoc "$f" -o "${f%.md}.pdf"; done

How do I set the command so that the file name will be taken from the title metadata?


Solution

  • You'll need a helper file title.plain with content

    $title$
    

    With that, the following command should do:

    for f in *.md; do
      pandoc "$f" -o "$(pandoc --template=title.plain -t plain "$f")".pdf
    done