How to edit template partials for docx format? #4511
Replies: 4 comments 6 replies
-
(This is a broken link, at least for me; I wonder if you have a typo) What you're trying to achieve is probably easier to do with a custom Lua filter that processes the document and adds those words to the right headings. Have you considered that route first? |
Beta Was this translation helpful? Give feedback.
-
thanks, got it! |
Beta Was this translation helpful? Give feedback.
-
@achetverikov to add to Carlos answer regarding
Pandoc does not have text template for Docx. To cite the documentation
This is why you can't find the same partial template feature in Quarto as for HTML or TeX. For PPTX and DOCX, it is using a reference document. Quarto is leveraging this reference doc feature for word templating : https://quarto.org/docs/output-formats/ms-word-templates.html For the adding content automatically or based on some metadata, Lua filter will be the way. Just sharing that in case you did not know about reference docs. |
Beta Was this translation helpful? Give feedback.
-
Quarto uses Pandoc to convert to Docx (https://pandoc.org/MANUAL.html) and the templating mechanism is from Pandoc (https://pandoc.org/MANUAL.html#option--reference-doc) - this is different than Pandoc's template logic (https://pandoc.org/MANUAL.html#templates). Doc even says: "docx and pptx have no template (however, you can use --reference-doc to customize the output)."
Yes I believe it does. Pandoc does write the Docx using the template directly in Haskell in its writer (https://github.com/jgm/pandoc/blob/main/src/Text/Pandoc/Writers/Docx.hs) - it is not using the same templating logic as for other format (https://pandoc.org/MANUAL.html#templates). If you look at the writer you can see it is writing directly OpenXml syntax for docx and modifying / creating xml format.
What you can do in a Lua filter is catched some AST node and decide to write some raw openxml string directly instead of letting Pandoc writer convert this node. For example would do this for some post processing like Callout feature from Quarto (in https://github.com/quarto-dev/quarto-cli/blob/main/src/resources/filters/quarto-post/docx.lua) So for now, Quarto capabilities for Docx output is quite tied by Pandoc support. Some other tools in other language are for example post processing Pandoc output by modifying the docx produced (like officedown for R users), or tools like officer for R users allows to read a docx and tweak it before writing it back. Same type of tools exist in Python world like python-docx. Hope it helps understand the current situation. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was hoping to customize the docx template a bit (add words "Abstract" and "References" before the corresponding sections, make some other small changes...). I see examples for html/pdf here https://quarto.org/docs/journals/templates.html#html-partials but not for docx and the docx folder here https://github.com/quarto-dev/quarto-cli/tree/main/src/resources/formats has images only. How to edit template partials for docx format? Are there any examples of customized article templates using docx available?
Beta Was this translation helpful? Give feedback.
All reactions