Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a custom.docx breaks "Figure with Caption" Styling. #3656

Closed
iandol opened this issue May 10, 2017 · 5 comments · Fixed by #3658
Closed

Using a custom.docx breaks "Figure with Caption" Styling. #3656

iandol opened this issue May 10, 2017 · 5 comments · Fixed by #3658

Comments

@iandol
Copy link
Contributor

iandol commented May 10, 2017

This is pretty simple. First create two custom docx reference templates:

pandoc --print-default-data-file reference.docx > customA.docx
pandoc --print-default-data-file reference.docx > customB.docx

Now edit customB.docx in Word — all you need to do is open it, add a space, delete the space and save. Now if you use this markdown and those templates:

# Simple test #

![Test image](test.png)  

More text.  
pandoc --reference-docx=customA.docx -o resultA.docx input.md
pandoc --reference-docx=customB.docx -o resultB.docx input.md

You find in for resultB.docx in Word that the figure loses its "Figure with Caption" styling (and thus keep with next), and is now "Normal".

The reason is a case issue caused by Word editing the styles on save, here is styles.xml for A vs. B:

screen shot 2017-05-10 at 12 50 54

(LEFT==resultA.docx | RIGHT=resultB.docx) For some reason, Word overwrites the w:styleId = FigureWithCaption with the w:val extrapolation so the w:styleId becomes FigurewithCaption. But the document.xml still uses the uppercase version and thus fails to apply. The easiest fix I assume is to rename the original template so both w:val and w:styleId use an uppercase W. I couldn't see other styles that use mixed case in the pandoc template, but assume this applies to any such style.

@iandol
Copy link
Contributor Author

iandol commented May 10, 2017

Actually, it is not so simple to fix. Basically if you set w:styleId and w:val to FigureWithCaption, each time you edit it Word changes it to FigurewithCaption. So even if you change w:val in the original reference.docx if you edit it it will break. So the only answer I think is to change the DOCX writer to use FigurewithCaption for the actual document XML and edit the styleId of the template to match...

@jgm
Copy link
Owner

jgm commented May 10, 2017

Okay, we can change FigureWithCaption to FigurewithCaption.
This may break some existing reference.docx's, but I don't see a better option.
While we're breaking things, maybe better to use CaptionedFigure.
This presumably wouldn't create the same problem (which I imagine is caused by some algorithm that recognizes "small words" like "with").

@jgm jgm added this to the pandoc 2.0 milestone May 10, 2017
@jgm
Copy link
Owner

jgm commented May 10, 2017

PS. Thanks for the excellent bug report!

@iandol
Copy link
Contributor Author

iandol commented May 11, 2017

Well thanks multiplied for such an amazing tool! I agree that CaptionedFigure looks better and won't trigger any potential title case weirdness.

Writer Code to change: https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/Writers/Docx.hs#L878

I'm happy to edit the reference.docx to change the stylename. I can edit the docx manually (rename to zip, edit files, rezip and rename). Or I can edit it via Word (V15.33 for macOS); but that will update to a later version of Word than the reference.docx was generated with — some of the XML meta headers also change and I don't want to trigger any potential gotchas...

Can't wait for Pandoc 2.0, it's going to be an excellent release!

@iandol
Copy link
Contributor Author

iandol commented May 11, 2017

Here is reference.docx edited manually to use w:styleId=CaptionedFigure and w:val=Captioned Figure, no other changes made.

reference.docx

@jgm jgm closed this as completed in #3658 May 18, 2017
jgm pushed a commit that referenced this issue May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants