jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.02k stars 3.35k forks source link

Add `<title>References` to `<ref-list>` for references in JATS output #8364

Closed castedo closed 1 year ago

castedo commented 1 year ago

This feature request is to include a <title> in the <ref-list> that is generated for references. As of 2.19.2 it is not output.

For example, here's what pandoc generates:

<back>
  <ref-list>
    <ref id="ref-shannon_mathematical_1998">
      <element-citation publication-type="book">
      ...
      </element-citation>
    </ref>
  </ref-list>
</back>

whereas this is what an eLife XML file (#63435-v3) looks like:

<back>
  ...
  <ref-list>
    <title>References</title>
    <ref id="bib1">
      <element-citation publication-type="journal">
      ...
      </element-citation>
    </ref>
...
</back>

The pandoc command is the following:

pandoc input.md -s --to=jats+element_citations --citeproc --metadata link-citations=true

with the attached input.md.

In addition to producing JATS XML that is more compatible with other JATS readers, I suspect this feature will also be useful for a separate pandoc JATS reading feature I'll submit separately.

I would tweak the JATS template if I could to get this functionality but the entire <back> element is generated from one $back$ template variable.

jgm commented 1 year ago

Does it help if you put reference-section-title in your metadata? (see the manual)

castedo commented 1 year ago

Good idea! I didn't know about that. But sadly it does not add the title into the <back><ref-list>, only the body.

jgm commented 1 year ago

Can you quote the xml more fully so I can see where it adds the title?

castedo commented 1 year ago

My pleasure!

...
<article ... >
...
  <body>
...
  </body>
  <back>
...
    <ref-list>
      <title>References</title>
      <ref id="bib1">
...
      </ref>
...
    </ref-list>
  </back>
...
</article>

The full XML in all its glory is here: https://raw.githubusercontent.com/elifesciences/elife-article-xml/master/articles/elife-63435-v3.xml

jgm commented 1 year ago

I meant, where does pandoc currently add the title when you use reference-section-title?

castedo commented 1 year ago

With reference-section-title: Referencias added to input.md meta I get:

<article ... >
...
<body>
...
<sec id="bibliography">
  <title>Referencias</title>
</sec>
</body>
<back>
<ref-list>
  <ref id="ref-shannon_mathematical_1998">
    <element-citation publication-type="book">
...
      <isbn>978-0-252-72548-7 978-0-252-72546-3</isbn>
    </element-citation>
  </ref>
</ref-list>
</back>
</article>
jgm commented 1 year ago

Oh, yes, that's no good at all.

castedo commented 1 year ago

A quick update: I hack around this limitation in wrapper utilities of pandoc for generating JATS XML. After calling pandoc, I string replace <ref-list> in pandoc's XML output with <ref-list><title>References</title> An example of this hack in this this utility:

https://gitlab.com/castedo/jatex/-/blob/7b90d1eebf44e976d54d26c07437fc20fa6a87aa/jatex/__init__.py#L31

jgm commented 1 year ago

I've made some changes that yield this output:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.2 20190208//EN"
                  "JATS-archivearticle1.dtd">
<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">
<front>
<journal-meta>
<journal-id></journal-id>
<journal-title-group>
</journal-title-group>
<issn></issn>
<publisher>
<publisher-name></publisher-name>
</publisher>
</journal-meta>
<article-meta>
<permissions>
</permissions>
</article-meta>
</front>
<body>
<p>Doe (2006)</p>
</body>
<back>
<ref-list>
  <title>References</title>
  <ref id="ref-test">
    <mixed-citation>Doe, J. (2006). Test,
    <italic>81</italic>.</mixed-citation>
  </ref>
</ref-list>
</back>
</article>

I think that's desired.

castedo commented 1 year ago

Oh bummer. @jgm That test case is beautiful, but it missed a regression bug with a heading in the input document: #9017 Sorry!

castedo commented 1 year ago

This enhancement does not appear to be working for element citations, see #9021.