jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.28k stars 3.36k forks source link

JATS writer regression: incorrect placement of <ref-list> inside <body> instead of inside <back> when heading inside input document #9017

Closed castedo closed 11 months ago

castedo commented 1 year ago

REPO STEPS Using input-with-heading.md

pandoc --to jats -s --citeproc input-with-heading.md

outputs

...

<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="1.2" article-type="other">

...

<body>
<sec id="i-like">
  <title>I like</title>
  <p>(DeGroot 2002).</p>
  <ref-list>
    <ref id="ref-degroot_probability">
      <mixed-citation>DeGroot. 2002. “Probability.”</mixed-citation>
    </ref>
  </ref-list>
</sec>
</body>
<back>
</back>
</article>

EXPECTED

The <ref-list> element should be inside <back>, not <body>.

NOTES

Changing the input heading from "# I like" to just text "I like" eliminates the bug. E.g. using input-no-heading.md outputs the <ref-list> inside the <back>.

Pandoc version? I reproduce this with 3.1.6.2, 3.1.6.1, 3.1.4, but not 3.1.3. So this appears to be a regression from 3.1.3 to 3.1.4.

jgm commented 1 year ago

The problem is splitBackBlocks in https://github.com/jgm/pandoc/commit/4f440583a82d1090dbe212afe77eace8deb0531f

jgm commented 1 year ago

Added a header to the test case in #8364, and it still created a back section. I think this is because that test specifies reference-section-title in the metadata.

jgm commented 1 year ago

Here's the diagnosis. If you end your file with a header or provide reference-section-title in metadata, a heading will be added to the references, and then makeSections will create a proper section for it, and splitBackBlocks will put this section in the back matter.

If you don't create a section heading for your references, then makeSections will incorporate the references into the final section of the document, and it won't be split into back matter.

One possible fix would be to look for a refs Div prior to calling makeSections, and ensure that there is a preceding Header element. (If not, add an empty one?)

castedo commented 1 year ago

Thank for this information, I think I now see a work-around so that I can use the latest release for my document processing.

Some quick information to share since it was confusing me regarding this:

Here's the diagnosis. If you end your file with a header or provide reference-section-title in metadata, ...

It seems if one does BOTH end a file with header "# References" AND provides a reference-section-title of the same title text AND the penultimate section is not empty, then the ref-list gets misplaced in the body and not placed in back.

castedo commented 1 year ago

Regarding possible fixes, I'm not sure ... but another possibility is to essentially treat reference-section-title as always having a default value of "References" when outputing JATS XML. But I don't understand the Haskell very well to have a sense on which possibility is better.

jgm commented 11 months ago

This was wrongly closed I think. The commit above has nothing to do with this issue and I think it was just a typo.

jgm commented 11 months ago

Never mind - it was properly closed but not by the referenced issue above.