Add a link to the title of references
Asked Answered
G

1

6

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).

Guam answered 9/6, 2017 at 11:54 Comment(7)
Can you go into details about the link adress? Would it be sample.com/author2017word.html in this example?Diseased
@MartinSchmelzer yep, exactly, though the problem is not so much the actual url as it is to add any url.Irvinirvine
And the final document is HTML? You could add the links afterwards with jQuery. Would that be sufficient?Diseased
Yep, it'll be HTML. Postprocessing with JS would be the last resort. Ideally it'll have to be hardcoded in the HTML.Irvinirvine
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.Cyclostome
Well, at this point a JS-based solution would be fine then. Anyone up for it?Irvinirvine
Came here wanting to do the same. I've been manuallly adding urls via <a href="...">...</a> 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.Dottiedottle
P
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.

Pimbley answered 25/8, 2021 at 16:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.