Change the size or style of a Monocace Pandoc font in DOCX output

When using markdown code codes, the resulting monospace font size is too large in DOCX documents.

I can adjust the font size of paragraphs by specifying my own template.docx file, but for some reason, the generated code blocks do not use the paragraph style, unlike most other generated output.

Is there any way:

  • Code blocks use a specific style so that I can override the style in the template. docx

  • Cancel the monospace font used in the DOCX representation of code blocks?

Updated to clarify: I am using an external reference.docx based on a previously created docx, as described in the comments. By changing the styles for heading1, etc., I have reasonable control over the output. The problem is that the created monospaced text does not use the named style, it is just β€œnormal” with some changes. Therefore, I have no way to change it in the template, if I do not change the size of all the "normal" text.

+8
docx pandoc
source share
2 answers

Using Pandoc 1.17.2 and Word 2013, I finally found a solution, it seems that later versions of Pandoc use a related style that is hidden by default in Word.

Step 1. Create a custom template file using

pandoc -o template_1.17.2.docx test.md 

Where test.md contains the source code and all other styles that you can change. For example:

 ~~~~ this is preformatted source using style "Source Code" ~~~~ ~~~ xml <this> is preformatted source using "KeyworkTok" and "NormalTok"</this> ~~~ 

Open the Word_1.17.2.docx template in Word. Source code is now formatted using the hidden linked style "Source Code". This style is NOT displayed in the default style preview area, you can add it by customizing the style preview panel by clicking the small square arrow in the lower right corner of the style preview panel.

Change this style as you like and save the template. Then generate a document based on this template:

 pandoc --reference-docx=template_1.17.2.docx -o mydoc.docx mydoc.md 

You should now see the source correctly formatted in mydoc.

@LinusR suggests that different source styles use different Layout styles. I added XML as an example. Formatted XML will use KeywordTok and NormalTok.

+3
source share

Pandoc uses the reference.docx file when creating DOCX documents (MS Word). This should be indicated on the Pandoc command line. Pandoc then extracts all the standard styles and formatting options (if they do not use custom names) from this DOCX link and applies them to the generated DOCX:

  pandoc -t docx -o out.docx in-markdown.txt --reference-docx=my.docx 

The best way to get a Pandoc-accessible DOCX link is to create the first simple DOCX using Pandoc, then transfer it to the Word installation, open it and change the styles that you like to use. Then save it, return it to Pandoc and use it as a link.


For ODT (LibreOffice / OpenOffice / OpenDocument), in addition to reference.odt (which you can use with the --reference-odt ), there is also a template . You can print the default template with pandoc -D odt and then change it and use it with pandoc -o out.odt --template=modifiedTemplate.odt


Last tip: use the latest version of Pandoc! (The current is 1.13.2.1. At the end of this month, 1.14 is expected.) His support for DOCX has improved significantly in recent releases.

+3
source share

All Articles