Max Williams
Max Williams

Reputation: 32933

Pandoc doesn't seem to use settings in docx template

I'm using Pandoc v1.12.2.1 to convert html to docx. It's working, generally, but I'm trying to get it to read in a docx template file so I can tell it to use Arial for the font and to make all headings black (instead of blue as they're coming out at the moment).

The template file is at

/path/to/my/project/public/pandoc/templates/reference.docx

and i'm calling Pandoc like this:

pandoc --data-dir /path/to/my/project/public/pandoc --template reference.docx -s "$input" -o "$output"

Where $input and $output are the html file I'm reading in and the destination of the resulting docx file respectively.

It produces a docx file, but it doesn't take my template into account - it looks identical to when I don't use a template file. I think it's reading the reference.docx file, because if I change the filename it complains about it not being there.

To produce the template I followed the instruction on [https://pandoc.org/MANUAL.html#option--reference-doc][1] which was to take a docx file produced by Pandoc, edit the style settings, and then save it.

I've put the template file [here][2] in case anyone can see anything wrong with it.

I'm trying to do this in Ubuntu 14.04, using LibreOffice, and I wonder if that has anything to do with it not working? Do I need to edit the template in Microsoft Word in Windows?

Grateful for any advice.

EDIT - I've also tried this:

pandoc "$input" -s --reference-docx /path/to/my/project/public/pandoc/templates/reference.docx  -o "$output"
``

and have the same result:  it doesn't seem to use the styles, but it will complain if I change the filename, suggesting that it is reading the doc.


  [1]: https://pandoc.org/MANUAL.html#option--reference-doc
  [2]: https://www.dropbox.com/s/e4dl9avue1i7vkr/reference.docx?dl=1

Upvotes: 3

Views: 1757

Answers (2)

Max Williams
Max Williams

Reputation: 32933

The short answer is "Do it in Windows". I emailed the template to my Windows laptop, loaded the docx into Word in Windows 10, updated the styles in that, and then emailed it back to myself and used it in Linux, and it instantly worked.

So, there must be some difference to how LibreOffice saves docx stylesheets, compared to how Windows does it.

Upvotes: 0

tarleb
tarleb

Reputation: 22609

Pandoc 1.x expects the reference document to be passed via the --reference-docx command line parameter. Conceptually the reference doc is different from a template, as the latter allows to use conditionals and variable substitution. A different command line flag is used to make the difference more recognizable.

Note, in case you upgrade to a newer pandoc version, that pandoc 2.0 and later use --reference-doc instead (no x).

Upvotes: 1

Related Questions