Pandoc/Scrivomatic: header/footer content mingling (plus fusion of documents)


exporting my document via the Scrivomatic Workflow my documents has pagenumbers and a footer (I used an older version where did not have both). I recognize that it says “template” once and when I add a table of content (which I want) in the YAML-file, I have now the name of projekt as a footer. I would like to play with this, trying for example:

*to have chapter names and /or even subchapters name or odd pages the chapter number and even pages chapter name or something

*defining numbers type or starting number of the page numbers (for example having roman numbers or starting at page 3

I could think a) of the template *.docx, but mingling there did change a thing (but what with pdf?) or b) the pandocomatic.yaml or c) the meta-data in scrivener, but I cant find the right commands in the pandoc manual.

Leads me directly to another question:

  • How to bind two already existing docx or md with the one I compile at that moment.

My .DOCX template ([here]( … ustom.docx)) uses a standard Word field-code to insert the document title (edit the footer, then show the field codes and you will see it). For some annoying reason Word doesn’t update field codes when opening a document, so I normally edit footer, then right-click the field “template” text and update the field.

Now Pandoc can also export custom metadata to Word document properties, and Word can add custom properties as fields. Try this:

echo -e "---\nauthor: Joanna Doe\nsubject: fey\ncategory: dey\nKeywords: hey\nComments: bey\nTest1: jey\nTest2: zey\n---\n\n# Intro\n\nHello." | pandoc -o test.docx; open test.docx

In Word the meta-data makes it through to custom fields:

[attachment=1]Screenshot 2021-03-14 at 10.37.42.png[/attachment]

And this field can be used in the header/footer:

[attachment=0]Screenshot 2021-03-14 at 10.40.37.png[/attachment]

So you can set up whatever you want to go into headers and footers, editable as front-matter in Scrivener’s binder.

As your question of automatically merging DOCX files, no idea, perhaps there is a command-line tool for this and if so then pandocomatic can run it as a post-processor. A quick google search showed there is a python tool that can merge docx documents…

If it were me, I’d import them into a Scrivener project and reduce it to a known problem.


Dear Ian,

thanks. That works technically very well on the pandoc-site, but the Scrivener placeholders "<$pageGroupTitle>
" and “<$pageGroupParentTitle>” that I used (and which are recommend in the placeholder list of Scrivener) are not transformed but instead I see “<$sectiontitle>” and “<$sectionParentTitle>” in my compiled document. Any thoughts on that?

When you integrate --toc for a table of content, Word (for Mac, V 16.46) opens the document asking for updating fields and that way it, I needn’t click it.

Thanks, Katharine,

you’re so right. I have to attach pages which are styled totally different before and after the document. I wondered if I could do it smoothly, but I will do it manually then.

The Compile command in Scrivener is likely to work much more smoothly than any post-Scrivener merge. This is exactly why it exists, after all.


Is it only those placeholders that have problems? Some placeholders may depend on print formats for compile? Perhaps a minimal test case scrivener project would help.


all the other placeholders like chapter-numbers or figure numbers, word count, name and date are correctly transformed. Since I have a table of content added (defined in the yaml), I am asked to refresh it, when I open the docx. When I do, I get the strange fields entries as described before, when I don’t I just get “Error! Unknown document property name.”

Find a testsetup with the (your) modified custom.docx here: [attachment=0][/attachment].

(side question: When I want to call for toc or list of figures in the meta-data of the project and not in the yaml, how do i do that? … you gotta answer that on the way since you have to add toc:true into your yaml otherwise)

Nontroppo, would it overly complicate your life if I moved this and similar threads to the Markdown + LaTeX forum? We’re getting pretty deep into the post-Scrivener weeds.


I also agree these threads are better placed in the Markdown forum! 8)

Yes, the placeholders you specified can only be used by Scrivener’s own compiler header and footers:

[attachment=2]Screen Shot 2021-03-16 at 14.25.47.png[/attachment]

You need to use other Word fields to try to accomplish what you want, and it can only come from the document structure, not any metadata.

Just add it to the metadata, it will take precedence over the pandocomatic.yaml settings. So if you want to turn the TOC on irrespective of what it may be in the pandocomatic.yaml recipe, just put it in the metadata:

[attachment=1]Screen Shot 2021-03-16 at 14.41.07.png[/attachment]

By the way, you should remove the Scrivener compiler metadata you have also specified:

[attachment=0]Screen Shot 2021-03-16 at 14.39.46.png[/attachment]

This only complicates the resulting markdown and your Pandoc metadata frontmatter is what you should be editing. Also in your compile format post-processing settings you delete the intermediate markdown file, but it is hard to see what is happening during the transformation, and it is worth keeping the markdown unless you are sure your workflow is working perfectly…

Topic moved. – Katherine

Hello everyone, sorry I had that forum wrong. Thanks, nontroppo, again for help. Although I puzzle about it since the items I used are listed as header/footers in the manual (version 3.0.3).

[attachment=0]Screenshot 2021-03-18 at 17.37.51.png[/attachment]

plus, using the meta-data of the project not the yaml: the “table-of-contents: true” did not work. but “toc: true” did. Unfortunately “toc-title” did not work as meta-data, while it works fine in the yaml. Any idea why that is?

But Header and Footer fields are for Scrivener controlled formats, not markdown. In this case Scrivener can calculate which section, which page and calculate the contents accordingly. Markdown has no such concept of which section goes on which page, and therefore it is the final format paged media that must deal with headers and footers. The document metadata can only transmit “general” information, not information specific to a particular page. What exactly is it you want to accomplish?

Let us make sure we understand each other.

  1. Scrivener metadata, that is entered in the Compiler GUI directly. Scrivener converts it into a YAML metadata block.
  2. Front-matter metadata, that is entered as raw YAML in a document that is included as the first document (front matter) of a compile.
  3. pandocomatic.yaml – the settings pandocomatic uses control pandoc given a template name set in either 1) or 2)

I prefer to disable (1) and only use (2) for simplicity to specify (3). There are two types of control:

  1. Pandoc Settings
  2. Pandoc Metadata

Pandocomatic uses the pandoc field in pandocomatic.yaml for (1), and for (2) you can put it in the metadata field of pandocomatic.yaml, or add it directly in the Scrivener front-matter. Any metadata in the Scrivener front-matter takes priority.

toc and table-of-contents are pandoc settings, but toc can also be a variable, this is a special case. Again, I am not really clear what you are trying to achieve or what precise problem you are having, please create a minimal test project to demonstrate your problem…


thanks for this clarifying definitions which help to be able to speak. I thought you’ll have everything in the data I gave already, in which I changed the following:

  1. I cleared the Scrivener data (It was there not by choice but by template default)
  2. I switched some commands from the YAML (the pandoc meta-data part) to the frontmatter meta-data. There “table-of-contents: true” and “toc-title: blabla” did not have an effect. “toc:true” did, though. (all of are working when added to pandoc meta-data in the yaml).

question is: Because the name of table of content (toc title) varies by language used, I’d like to specify it in the frontmatter meta-data, what is the correct command? I cant find it.

More important though is the question of header and footers: I would like to have footers in my docx-output of your scrivomatic-workflow that show chapter name and number on the odd page and, if possible, on the even page the heading of the current section, which is to be found on that very page (so reader always knows where he or she is). Now I understand that I should not use the Scrivener placeholders ( thanks to you, again!).

There are options in Microsoft Word for such things to have a field in the custom.docx

Footer: Field > StyleRef > options : Heading 1.

But this alone seems to be not enough. Does there have to be a command in front-matter meta-data or in the yaml settings or meta-data section? If yes, which one. What to do in docx?

Just take the given data a couple of entries before.

toc-title is the metadata used for LaTeX and HTML templates, and perhaps works for DOCX even though it is a less flexible output format:

title: <$title>
author: <$author>
toc-title: "Test title"
  use-template: [docx, latex]
    table-of-contents: true

toc itself is a strange option, it is both a pandoc commandline setting and metadata (due to backwards compatibility I suspect), so that is why toc works in several places where other settings do not…

The problems with headers and footers is exclusively a Word issue, as long as the headings and sections get the correct names then Word should be able to use them for its fields. If Word can’t extract the heading level and name then you need to find how it works normally… I try to avoid Word as much as I can.