jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.87k stars 3.39k forks source link

Footnote separator overwrite in custom docx template #7087

Open hcf-n opened 3 years ago

hcf-n commented 3 years ago

I have custom reference.docx. This works mostly fine. But when I modify the footnote separator in my custom template by saving it in Word, it seems to be overwritten by default pandoc values.

Im not shure how to investigate this further, but given some directions I'm willing to try to pin down the issue.

I'm on OS X Pandoc v. 2.11.4

hc

jgm commented 3 years ago

By footnote separator you mean what exactly?

And how do you attempt to adjust this in your reference docx? By changing a style, and if so which?

hcf-n commented 3 years ago

By «footnote separator» I mean the horizontal line that separates the main text from the footnotes on every word page that has footnotes. It is left aligned.

I’m perfectly happy with the way the footnote separator works in plain vanilla word based on normal.dot but the distance between the separator and the first footnote is to long in the docx produced by Pandoc.

I found this receipe on how to change the footnote separator in Word

  1. With the document open in Word, click on the View tab and click on Draft View.
  2. Click on the Review tab, then on Show Notes. A split window opens with the Footnote dropdown set to All Footnotes.
  3. Change that dropdown to Footnote Separator.
  4. The actual separator is a mystery character that acts neither like text nor like a drawing object. But you probably don't need to bother with it, because the space below the separator is probably caused by paragraph spacing.
  5. Click just to the right of the separator and adjust the paragraph spacing, perhaps taking out space after.

When I follow this I find that there is a 10 pt space after the footnote separator Screenshot

Adjusting this to 0 pt. gives the spacing I'm looking for.

I have looked into the xml files of the result docx file. But couldn't find any place where the 10 pt spacing after the footnote separater was set. It seems to me that the value is inherited from one of the normal paragraphs. It also seems to me that the spacing between paragrahs is differen in the docx from pandoc and the one from words normal.dot. This means that the value inherited by the footnote separator needs to be changed explicitly i.e something along the lines of

 <w:footnote w:type="separator" w:id="-1">
        <w:p w14:paraId="7F25054B" w14:textId="77777777" w:rsidR="0004223F" w:rsidRDefault="0004223F" w:rsidP="00394AF5">
            <w:pPr>
                <w:spacing w:after="0"/>
            </w:pPr>
            <w:r>
                <w:separator/>
            </w:r>
        </w:p>
    </w:footnote>
niszet commented 3 years ago

Hi hcf-n san,

I checked this behaviour in Pandoc 2.11.4 and Windows 10. And also I checked source code related to this issue. Currently, Pandoc seems to overwrites footnote settings in reference.docx by default footnote setting.

https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/Writers/Docx.hs#L1499

If we want to use customized footnote settings from reference.docx as same as styles, maybe we need to add Readers/Docx/Parse/Footnots.hs (and so on), I think.

And, as you shown above, to reduce the space between footnote separator and footnote text, set space after separator by editting separater's paragraph settings. This is also confirmed by my environment. <w:spacing w:after="0"/> in your code is corresponding of space after paragraph (after reduced).

Followings are captured figures in my environment (sorry captured picture is Japanese...).

image

Left: modified docx file. Right: Pandoc's output.

image

But as written above, this setting will be overwritten by Pandoc even if you use this file as a reference.docx...

jgm commented 3 years ago

That's right, we have this hard-coded in the docx writer:

-- Word will insert these footnotes into the settings.xml file
-- (whether or not they're visible in the document). If they're in the
-- file, but not in the footnotes.xml file, it will produce
-- problems. So we want to make sure we insert them into our document.        defaultFootnotes :: [Element]     
defaultFootnotes = [ mknode "w:footnote"                           
                     [("w:type", "separator"), ("w:id", "-1")]   
                     [ mknode "w:p" []                     
                       [mknode "w:r" []
                        [ mknode "w:separator" [] ()]]]
                   , mknode "w:footnote"
                     [("w:type", "continuationSeparator"), ("w:id", "0")]
                     [ mknode "w:p" []
                       [ mknode "w:r" []    
                         [ mknode "w:continuationSeparator" [] ()]]]]

I'm wondering: can we simply attach a paragraph style to the separator, which would allow it to be adjusted through styles?

jgm commented 3 years ago

But on second thought, that's just a half solution; one would be able to adjust spacing but not the other aspects of the separator. It would be better to allow one to change these directly in the reference.docx.

niszet commented 3 years ago

I tried to update pandoc locally to imcorporate footnote separator from reference.docx.

Pandoc will extract footnote tags which have w:type attribute from footnote.xml in reference.docx. From this update, any kind of footnote separator can be impremented even if the separator is multi-line, has a style, written by Japanese(maybe all CJK) and so on.

Here is an example of input and output files this update (input.zip is for uploading input.md).

input.zip output.docx reference.docx

pandoc -f markdown input.md -t docx -o output.docx --reference-doc reference.docx

You can see same footnote separator in output.docx as reference.docx.

But, if emoji is in the separator it will be failed (but maybe it's OK for normal use...).

Maybe this will solve this issue and I will send a PR of this update.

hcf-n commented 3 years ago

It seems like there still is an extra 10pt space below the footnote separator.

hcf-n commented 1 year ago

Just checking in to see if this problem has been solved

There is still problems with the footnoteseparator in v. 3.1.2. I'm not able to propose a patch myself, but would happily contribute with testing.