5

I'm creating a document with rmarkdown (pandoc), which includes some bibliography in a .bib file. What I'd like to do is add a link to the title of the references, so that each of them links to a page of the form http://sample.com/citation-key.html, like this:

Author. (2017). Sample Title. Journal, 1(1), 1–2.

I've tried modifying the .csl file by adding prefixes and suffixes to the title, but everything I put in there is escaped, whether I use markdown or HTML syntax. Unfortunately, I can't change the .bib file. The relevant part of the .csl file is this:

<text variable="title"/>

Sample files are:

  • literature.Rmd:

    ---
    output: html_document
    bibliography: literature.bib
    csl: literature.csl
    ---
    
    @author2017word says this doesn't work.
    
    ## References
    
  • literature.bib

    @article{author2017word,
             author = {Author},
             journal = {Journal},
             number = {1},
             pages = {1--2},
             title = {{Sample Title}},
             volume = {1},
             year = {2017}
    }
    
  • literature.csl: I'm using the APA style from here (line 231).

Julián Urbano
  • 8,378
  • 1
  • 30
  • 52
  • Can you go into details about the link adress? Would it be http://sample.com/author2017word.html in this example? – Martin Schmelzer Jun 09 '17 at 13:04
  • @MartinSchmelzer yep, exactly, though the problem is not so much the actual url as it is to add any url. – Julián Urbano Jun 09 '17 at 13:15
  • And the final document is HTML? You could add the links afterwards with jQuery. Would that be sufficient? – Martin Schmelzer Jun 09 '17 at 13:28
  • Yep, it'll be HTML. Postprocessing with JS would be the last resort. Ideally it'll have to be hardcoded in the HTML. – Julián Urbano Jun 09 '17 at 13:54
  • 2
    Just to say that you definitely *can't* do this with CSL. I think it's also not available in pandoc, so Martin's suggestion to postprocess is the only way to go, but not certain about the latter one. – adam.smith Jun 09 '17 at 21:45
  • Well, at this point a JS-based solution would be fine then. Anyone up for it? – Julián Urbano Jun 10 '17 at 15:00
  • Came here wanting to do the same. I've been manuallly adding urls via `...` to each of the `title` fields in my `.bib` file, but wanted to see if I could get CSL to do this for me. @adam.smith's answer makes me sad but also spares me a lot of headache trying in vain to customize my CSL file. – sh37211 Oct 06 '20 at 18:45

1 Answers1

3

My pull request to citeproc adding support this feature was recently merged, and as a result, the latest release of Pandoc (v2.14.2) now hyperlinks titles by default when the citation does not already show a raw URL! From the citeproc readme:

When linkBibliography=True automatically linkifies any identifiers (DOI, PMCID, PMID, or URL) appearing in a bibliography entry. When an entry has a DOI, PMCID, PMID, or URL available but none of these are rendered by the style, add a link to the title (or, if no title is present, the whole entry), using the URL for the DOI, PMCID, PMID, or URL (in that order of priority). See Appendix VI of the CSL v1.0.2 spec.

In pandoc, this option is controlled by the link-bibliography metadata field, which is True by default.

Benjamin Bray
  • 416
  • 4
  • 14