Show all used references when using compact numeric citation style
Asked Answered
D

1

6

I'm rendering html from markdown using bookdown, and using a compact numeric citation style so that e.g., 1, 2, 3 is shown as 1-3. I'd like references to be shown at the bottom of each page (link-citations: yes), but only the first and last reference in the range are shown (only refs 1 and 3 are shown, see screenshot below). Is there a way to have all cited references displayed on each page, with the caveat that only the first and last would be linked?

NB: all refs are correctly shown on the final bibliography.

To reproduce:

download.file('https://raw.githubusercontent.com/jgm/pandoc-citeproc/7d824e2e0d4698cf8a6d5e784aa0df27a0f2888a/tests/biblio.bib', 'ex.bib')
download.file('https://raw.githubusercontent.com/citation-style-language/styles/31187daa2c010df338c2bf9b7b30070c91b7af95/nature.csl', 'nature.csl')

and knit a markdown file with the following content:

---
title: A title
author: An author
bibliography: ex.bib
link-citations: yes
output:
  bookdown::gitbook:
    pandoc_args: [ "--csl", "nature.csl" ]
---

# Intro

baz [@item1; @item2; @пункт3]

# Refs

resulting html


Session info

> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.0 (2019-04-26)
 os       macOS Mojave 10.14.3        
 system   x86_64, darwin15.6.0        
 ui       RStudio                     
 language (EN)                        
 collate  en_AU.UTF-8                 
 ctype    en_AU.UTF-8                 
 tz       Australia/Melbourne         
 date     2020-03-29                  

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [2] CRAN (R 3.6.0)
 bookdown      0.17    2020-01-11 [1] CRAN (R 3.6.0)
 cli           2.0.2   2020-02-28 [1] CRAN (R 3.6.0)
 crayon        1.3.4   2017-09-16 [2] CRAN (R 3.6.0)
 digest        0.6.25  2020-02-23 [1] CRAN (R 3.6.0)
 evaluate      0.14    2019-05-28 [2] CRAN (R 3.6.0)
 fansi         0.4.1   2020-01-08 [1] CRAN (R 3.6.0)
 glue          1.3.2   2020-03-12 [1] CRAN (R 3.6.0)
 htmltools     0.4.0   2019-10-04 [1] CRAN (R 3.6.0)
 knitr         1.25    2019-09-18 [1] CRAN (R 3.6.0)
 packrat       0.5.0   2018-11-14 [2] CRAN (R 3.6.0)
 Rcpp          1.0.4   2020-03-17 [1] CRAN (R 3.6.0)
 rlang         0.4.5   2020-03-01 [1] CRAN (R 3.6.0)
 rmarkdown     1.16    2019-10-01 [1] CRAN (R 3.6.0)
 rsconnect     0.8.15  2019-07-22 [2] CRAN (R 3.6.0)
 rstudioapi    0.10    2019-03-19 [2] CRAN (R 3.6.0)
 sessioninfo   1.1.1   2018-11-05 [2] CRAN (R 3.6.0)
 withr         2.1.2   2018-03-15 [2] CRAN (R 3.6.0)
 xfun          0.10    2019-10-01 [1] CRAN (R 3.6.0)
 yaml          2.2.0   2018-07-25 [2] CRAN (R 3.6.0)
❯ pandoc --version
pandoc 2.9.2.1
Compiled with pandoc-types 1.20, texmath 0.12.0.1, skylighting 0.8.3.2
...
Copyright (C) 2006-2020 John MacFarlane
Web:  https://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.

❯ pandoc-citeproc --version
pandoc-citeproc 0.17
Didymous answered 29/3, 2020 at 1:31 Comment(3)
Related to community.rstudio.com/t/multi-paragraph-footnotes/47076/4 and github.com/rstudio/bookdown/issues/840?Amidst
I can't immediately see the connection, but maybe.Didymous
Note my comment here. I plan to update this post describing the workaround in due course.Didymous
K
3

My sense is that there are two elements you need to look at within the nature.csl file

[Lines 104-131].

The problem appears to be that your bibliography on line 112 is dependent on the citation definition on line 104. The term collapse interacts with your bibliography formating.

My recommendation is you take a look at the Citation Style Language web site and look over the reference styles to update your particular formating. Hoping this will help point you in the right direction.

  1. An Introduction to CSL
  2. Citation Styles Example <- Super Useful
  3. IEEE Example <- Matches your described style
  4. Visual Editor to create a style of your choosing and download

my sense is you need to create a custom cite-group-delimiter definition in your .csl file rather than use a collapse. Can be tricky but feels doable.

  1. http://docs.citationstyles.org/en/stable/specification.html#citation

<citation collapse="citation-number">
    <sort>
      <key variable="citation-number"/>
    </sort>
    <layout vertical-align="sup" delimiter=",">
      <text variable="citation-number"/>
    </layout>
  </citation>
  <bibliography et-al-min="6" et-al-use-first="1" second-field-align="flush" entry-spacing="0" line-spacing="2">
    <layout suffix=".">
      <text variable="citation-number" suffix="."/>
      <group delimiter=" ">
        <text macro="author" suffix="."/>
        <text macro="title" suffix="."/>
        <choose>
          <if type="chapter paper-conference" match="any">
            <text term="in"/>
          </if>
        </choose>
        <text macro="container-title"/>
        <text macro="editor"/>
        <text macro="volume"/>
        <text variable="page"/>
        <text macro="issuance"/>
        <text macro="access"/>
      </group>
    </layout>
  </bibliography>

Citation

The cs:citation element describes the formatting of citations, which consist of one or more references (“cites”) to bibliographic sources. Citations appear in the form of either in-text citations (in the author (e.g. “[Doe]”), author-date (“[Doe 1999]”), label (“[doe99]”) or number (“1”) format) or notes. The required cs:layout child element describes what, and how, bibliographic data should be included in the citations (see Layout). cs:layout may be preceded by a cs:sort element, which can be used to specify how cites within a citation should be sorted (see Sorting). The cs:citation element may carry attributes for Citation-specific Options and Inheritable Name Options. An example of a cs:citation element:

<citation>
  <sort>
    <key variable="citation-number"/>
  </sort>
  <layout>
    <text variable="citation-number"/>
  </layout>
</citation>

A note to CSL processor developers In note styles, a citation is often a sentence by itself. Therefore, the first character of a citation should preferably be uppercased when there is no preceding text in the note. In all other cases (e.g. when a citation is inserted into the middle of a pre-existing footnote), the citation should be printed as is.

Bibliography

The cs:bibliography element describes the formatting of bibliographies, which list one or more bibliographic sources. The required cs:layout child element describes how each bibliographic entry should be formatted. cs:layout may be preceded by a cs:sort element, which can be used to specify how references within the bibliography should be sorted (see Sorting). The cs:bibliography element may carry attributes for Bibliography-specific Options and Inheritable Name Options. An example of a cs:bibliography element:

<bibliography>
  <sort>
    <key macro="author"/>
  </sort>
  <layout>
    <group delimiter=". ">
      <text macro="author"/>
      <text variable="title"/>
    </group>
  </layout>
</bibliography>
Kerch answered 3/4, 2020 at 19:50 Comment(5)
Thanks for your explanation. Did you expect that your linked IEEE example would produce the desired ref list out of the box? I tested, thinking I could maybe modify that style to use superscript numbers, but it also omits reference 2 for my doc. (Note that the final reference list is accurate [for the nature style as well as your linked style] - all 3 references are shown. But the ref list for the current page is incomplete.)Didymous
@Didymous Always happy to help. I provided the IEEE as an example, with the knowledge that the current page reference list needs to be added to your .csl file as a modified definition. I was trying to find an example but I thought I should point you in the right direction in the immediate. It also hopefully will allow others to see how they might be able to provide a solution on top of what I shared.Kerch
Thanks for the clarification - the links are certainly useful, much appreciated.Didymous
I'll noodle on it a bit more and update if I have the complete solution. Hopefully, others can also help out.Kerch
It turns out this is due to the way that bookdown treats cites when splitting the bib into chapters. I've hacked a solution here, which can be applied after rendering the html with a non-compact numeric style (e.g. this style but with collapse="citation-number" deleted). Hopefully this will be supported by bookdown in future, or maybe @YihuiXie can suggest another workaround?Didymous

© 2022 - 2024 — McMap. All rights reserved.