Search code examples
yamlmarkdowndocxpandoc

Writing thanks and keywords from YAML header in Markdown file to docx document through Pandoc conversion


After reading the online Pandoc manual and browsing pages such as knitr-pandoc-article-template-supporting-keywords and Keywords in Pandoc 2, I haven't figured out yet how to write the values of the thanks and keywords YAML fields from the header of a Markdown file to a docx document through Pandoc conversion. My working version of Pandoc is 2.18.

I have thought that a Lua filter might be the way to proceed, but my knowledge of both Lua and the Pandoc framework at the programmatic level is quite limited.

Any help in this regard would be greatly appreciated.

Although my actual setup is more complex, the following Markdown lines with a YAML header should do for an MWE:

---
title: The Title
author: The Author
thanks: |
  The author wishes to thank certain support.
abstract: |
  This is the abstract.
keywords: [one, two, three, four]
---
   
# A Heading

Text body. 

Solution

  • The answer to this depends a little on how you'd want the thanks to be viewed. E.g., if you'd like it to be presented as a footnote to the author, you'd use a Lua filter like this:

    function Meta (meta)
      meta.author = meta.author .. {pandoc.Note(meta.thanks)}
      return meta
    end
    

    The approach can be adapted to match different requirements.