Changing the Pandoc monospace font size or style in DOCX output

前端 未结 2 1379
南笙
南笙 2021-01-04 05:59

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

I can adjust the font size of paragraphs by specifying a custom

相关标签:
2条回答
  • 2021-01-04 06:30

    Pandoc, when creating DOCX (MS Word) documents uses a reference.docx file. This has to be given on the Pandoc command line. Pandoc will then extract all default styles and formatting settings (unless they use custom names) from this reference DOCX and apply them on the generated DOCX:

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

    The best way to arrive at a Pandoc-usable reference DOCX is to generate a first simple DOCX with the help of Pandoc, then take it to a Word installation, open it and change the styles to be used by you to your liking. Then save it, take it back to Pandoc and use it as a reference.


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


    Last advice: use the latest Pandoc version! (Current is 1.13.2.1. For end of this month a 1.14 is expected.) Its DOCX support improved considerably in recent releases.

    0 讨论(0)
  • 2021-01-04 06:34

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

    Step 1: Generate a custom template file using

    pandoc -o template_1.17.2.docx test.md
    

    Where test.md includes source code and all other styles you may want to modify. For example:

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

    Open template_1.17.2.docx in Word. The preformatted source is now formatted using the hidden linked style "Source Code". This style is NOT displayed in the styles preview pane by default, you can add it by configuring the styles preview pane by clicking the tiny square-with-arrow in the bottom right of the styles preview panel.

    Modify this style as you wish and save the template. Then generate your document based on this template:

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

    You should now see the source properly formatted in mydoc.

    @LinusR suggests that different source styles uses different Layout styles. I have added XML as an example. The formatted XML will use "KeywordTok" and "NormalTok".

    0 讨论(0)
提交回复
热议问题