Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the font used for word doc exported using pandoc?

Rendering a microsoft word document using pandoc. The font seems to default to Calibri for headings and Cambri for body text. Goal is to have the file use Arial or Times roman fonts.

I don't want to touch/edit/have anything to do with the file in word.

How can I set the font that will be used in Word™ from either the multi-markdown source or in the call to pandoc?

Pandoc command:

pandoc -s my_markdown.txt -o whycambriafont.docx

This question: pandoc-generated docx misses italic variables in equations shows a way to edit the font styles by creating a zip and then editing the style files, but is a kludge.

like image 404
Minnow Avatar asked Jan 04 '16 21:01

Minnow


1 Answers

You can supply a reference.docx file with the --reference-doc option to pandoc which acts sort of like a template.

  1. Generate a file with echo 'hello word' | pandoc -o reference.docx or similar.
  2. Change the font in the style. Either by opening the file in Word, changing the style and saving it, or alternatively opening it for example with vim:
    • Rename the reference.docx to reference.zip
    • vim reference.zip and select reference/theme/theme1.xml
    • find and change Calibri to Arial
    • save and rename zip back to docx
  3. Profit: use with pandoc --reference-doc reference.docx

See also Defining-custom-DOCX-styles-in-LibreOffice-(and-Word).

like image 162
mb21 Avatar answered Nov 03 '22 14:11

mb21