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

Trivial DOCX writer doesn't work for reference doc with header #10201

Open
svenboulanger opened this issue Sep 19, 2024 · 8 comments
Open

Trivial DOCX writer doesn't work for reference doc with header #10201

svenboulanger opened this issue Sep 19, 2024 · 8 comments
Labels

Comments

@svenboulanger
Copy link

svenboulanger commented Sep 19, 2024

Explain the problem.

If I use the following (trivial) DOCX writer all resulting files are missing their headers in version 3.4. If I use the same writer in 3.1.12 (which is the version I was using before I'm trying to update) then it works correctly.

The (trivial) DOCX writer, writer.docx.lua:

function ByteStringWriter(doc, opts)
    local docx = pandoc.write(doc, "docx", opts)
    return docx
end

Then if I use the command

pandoc --reference-doc="ref_doc_with_header.docx" -t "writer.docx.lua" test.md -o test.docx

ref_doc_with_header.docx

I have no header in v3.4 and I do have the header in v3.1.12.

Pandoc version?
Version 3.4, Windows 11

@jgm
Copy link
Owner

jgm commented Sep 19, 2024

Can you check other versions? It would be very helpful to know which version caused this change.

@svenboulanger
Copy link
Author

It breaks at version 3.2.1 (3.2 is still fine).

@jgm
Copy link
Owner

jgm commented Sep 20, 2024

In the changelog, this looks like the most relevant entry for that version:

  * Docx writer:

    + Allow OpenXML templates to be used with `docx` (#8338, #9069, #7256,
      #2928). The `--reference-doc` option allows customization of styles in
      docx output, but it does not allow one to adjust the content of the output
      (e.g., changing the order in which metadata, the table of contents,
      and the body of the document are displayed), or adding boilerplate
      text before or after the document body.  For these changes, one can
      now use `--template` with an OpenXML template.  (See the default
      `openxml` template for a sample.) `--include-before-body` and
      `--include-after-body` can also now be used with `docx` output.
      The included files must be OpenXML fragments suitable for
      inclusion in the document body.

I will have to investigate.

@jgm
Copy link
Owner

jgm commented Sep 20, 2024

OK, right before the end of the body in document.xml we have:

<w:sectPr w:rsidR="00FF1A1A">
<w:headerReference w:type="even" r:id="rId8"/>
<w:headerReference w:type="default" r:id="rId9"/>
<w:footerReference w:type="even" r:id="rId10"/>
<w:footerReference w:type="default" r:id="rId11"/>
<w:headerReference w:type="first" r:id="rId12"/>
<w:footerReference w:type="first" r:id="rId13"/>
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
<w:cols w:space="720"/>
</w:sectPr>
</w:body>

My guess is that we are clobbering this with the new openxml templates, and we need to make sure that the sectPr on body is preserved.

EDIT: Maybe not. There is a sectpr variable already, and there's code in the Docx writer that sets this variable based on the reference docx. https://github.com/jgm/pandoc/blob/main/src/Text/Pandoc/Writers/Docx.hs#L249-L253

@jgm
Copy link
Owner

jgm commented Sep 22, 2024

The header works with standard pandoc; the problem seems specific to this custom writer.

@jgm
Copy link
Owner

jgm commented Sep 22, 2024

@tarleb can you think of any Lua changes in 3.2.1 that might affect this?

@tarleb
Copy link
Collaborator

tarleb commented Sep 22, 2024

Nothing comes to mind.

Does adding

Template = pandoc.template.default 'docx'

to the custom writer make a difference?

@svenboulanger
Copy link
Author

svenboulanger commented Sep 25, 2024

Just adding the line at the top of the writer lua script does not change anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants