Pandoc Reference Doc

I’m having issues exporting from Scrivener using Pandoc post-processing to apply styles from a reference doc. I used the process described in the Pandoc user guide to create a custom copy of reference.docx and modified the styles in the document. When I export from Scrivener all of the styles are recognized (Header 1, Header 2, Block Quote, etc) and successfully converted except for “Title” which just exports as “Normal” text. Has anyone else run into this problem when using a custom reference doc?

Title works fine for me, you can see in my sample compile outputs on the scrivomatic GitHub. My reference docs is shared on GitHub too, download it and give it a try: dotpandoc/templates/custom.docx at master · iandol/dotpandoc · GitHub

If you still don’t see a styled title then the problem must be linked to your markdown. Test with a minimal pandoc doc. I usually type directly in the terminal using standard input. You enter a pandoc command with no file input, press enter then type or pase markdown then press ctrl+d and pandoc processes the input directly, it is a fast way to test thins out:

> pandoc -o out.docx --reference-doc ~/.local/share/pandoc/templates/custom.docx [ENTER]

---
title: Test
author: Jane Doe
---

# Intro

Test
[CTRL+D]
                                                                                                                 
> open out.docx

Gives me:

Check that your title is properly referenced in the metadata of your scrivener markdown output (don’t delete this markdown intermediate as it is vital to check the conversion), and not being put in the body of the output.

1 Like

When I tested things out in Terminal the title and author were both properly formatted per the reference doc. The Markdown file that exports from Scrivener looks like this (and both Title and Author are formatted as Normal text after processing) :

Title: Untitled  
Author: Author

# Heading 1

## Heading 2

> Block Quote

Right the markdown formatting is wrong, this is not a problem with your reference doc. Are you using the built-in metadata panel of Scrivener’s compiler or writing the metadata yourself?

I prefer to write a metadata document myself kept in my binder, but it is critical that the metadata is surrouneded using --- AND the metadata keys are not title case – title: not Title: — I normally don’t write --- in my metadata directly but use either a section layout to insert the --- or a Scrivener block style.

The markdown should look like this:

---
title: Untitled  
author: Author
---

# Heading 1

## Heading 2

> Block Quote
1 Like

Thanks for clarifying! I read through more of the documentation and messed around a bit and it seems like one of the limits of the Zotero/Scrivener Pandoc workflow is formatting headers (e.g. putting last name and page numbering in the header), so I’ll have to do some manual reformatting as it is.

I’m not sure quite what you mean, though I use Bookends and even if I use Zotero on some projects dislike the live citations that the zotero.lua script enforces, so I always use Pandoc’s citeproc engine directly and see no header problems in my documents…

Sorry, I my use of ‘header’ was not so specific… To use a CMOS term paper header as an example, my desired formatting coming out of Scrivener would look something like this:

The closest I was able to get to this using metadata with Pandoc was this:

If I don’t use metadata (just some Scrivener tokens) all of this is treated as normal text and I end up with something along these lines:

Which isn’t a huge deal at all. I just need to center the title and add a running header with page numbers. Way less reformatting than I was doing when I used the ODF/RTF scan workflow. I was just curious whether Pandoc was able to incorporate those elements when it converted a Markdown file into a docx file.

Almost anything is possible in pandoc, and that format would be trivial for LaTeX or Typst. For DOCX or ODT it is a bit more tricky, but I think about 90% can be achieved using a openxml template — For DOCX you can supply not only the reference.docx but also an openxml template, this is the default:

The $if(item)$ tags are pandoc template language, which reads the metadata and adds the markup if it exists.

So in your case you would edit that to put the author block first, then your professor and course before the title. The most difficult thing is the Lastname in the header, you need to use Word’s field feature e.g. you can add author name, title easily, but I don’t know about other fields… You could hack this, so that you would have author: Lastname in the Scrivener metadata then add author field to the word reference.docx header, but also provide a first name and use that in the document itself. Something like:

---
title: Pandoc Test
subtitle: Test
author: Lastname
firstname: Firstname
supervisor: Jane Doe
course: Octopology
date: ...
---

# Intro

…

The template would add each field in the correct order and the reference.docx would use an author field in the docx header.

1 Like

As I had Word open I did a quick test. Word has a Subject document info field that can be put in the Word header, and Pandoc will populate it if you use subject: xxx in the markdown metadata. So you could use author: as normal and still be able to use subject: to add the last name into the header…

1 Like

custom.zip (34.7 KB)

Here :right_arrow_curving_up: is the openxml template and reference doc; with a test document:

---
title: "A Test"
subtitle: " — Testing Pandoc Features"
subject: Roe
author: Jim Roe
supervisor: Professor Jane Doe
course: Discourses in Octopology
date: 2025-08-08
keywords: [pandoc, test, markdown]
lang: en-gb
---

# Introduction

This is a test document to demonstrate various Pandoc features.

…with this pandoc command…

pandoc --template=custom.openxml --reference-doc=custom-test.docx -o test.docx test.md

…gets you this in Word…

Word is clunky with fields in headers, so you do have to manually update fields to see the surname:

1 Like

Thanks for all your help! Just got a chance to try out the openxml template and it works well.