I followed the instructions in this answer: https://stackoverflow.com/a/52131435/510024 and I could manage to create and use a filter to create a new page whenever I want in a conversion from markdown
to docx
. With that I could manage to get a 'Cover/Front Page' in the docx
file. However when using --toc
option the filter doesn't work. The newpage
is not respected and the 'TOC' appears right after the document title
i.e in the same page.
There is a way to convert from markdown
to docx
having as result a docx
document with a 'Cover/Front Page' and the 'TOC' (i.e. the 'TOC' being displayed in a page after the 'Cover/Front Page')
Thanks!
There are (at least) two possible methods: one which requires changes to the input document, and another where one modifies the reference document.
The abstract is the last element before the table of contents. Ending the abstract with a page break will cause the toc to start on a new page:
---
title: MWE
abstract: ' `<w:p><w:r><w:br w:type="page"/></w:r></w:p>`{=openxml}'
---
Note that the abstract may not be empty, but adding a single no-break space, as demonstrated in above example, is enough.
Pandoc uses a reference document when creating docx files. It is possible to create a custom reference doc and to modify the TOCHeader style.
Creating a custom reference doc requires the following steps:
Create a new docx based on pandoc's default reference file:
pandoc --print-default-data-file reference.docx > custom-reference.docx
Open custom-reference.docx
and modify the styles in it to your liking.
Pass the result via the --reference-doc
option each time when invoking pandoc.
pandoc --reference-doc=custom-reference.docx …
Alternatively, rename the file to reference.docx
and place it in pandoc's data directory, so it is chosen as default.
See the documentation on how to modify a custom style for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With