jgm/citeproc

`link-bibliography` option does not hyperlink references without URLs in notes

Opened this issue · 6 comments

The link-bibliography option links DOIs, URLs, etc. whenever they are printed in the notes or bibliography (such as with the Chicago full-note style). If the style does not render these fields, it links the titles instead but only in the bibliography, leaving the notes unlinked.

Would it be possible instead, please, to link the title whenever it appears, regardless of whether this is in the notes or bibliography?

jgm commented

In pure citeproc, this corresponds to the linkBibliography option in CiteprocOptions.
The option is described thus in the library documentation:

    --   * Automatically linkify any DOI, PMCID, PMID, or URL
    --     appearing in a bibliography entry.
    --   * When a bibliography entry has a DOI, PMCID, PMID, or URL available
    --     (in order of priority), but the style does not explicitly render at
    --     least one of them, add a hyperlink to the title instead.
    --   * A bibliography item with a DOI, PMCID, PMID, or URL available
    --     (in order of priority) will be wrapped in a hyperlink when the hyperlink
    --     has not already been applied to one of its parts (e.g. to the title).
  }

So the change you're suggesting would extend the first two bulleted behaviors to citations as well...I assume we wouldn't want the third.
Correct?

Exactly – Pandoc already applies the first action to citations as well as bibliography entries, and I am suggesting that this logic be extended to the second point. This would be especially helpful when working with note-only styles that do not include a separate bibliography.

I agree that it would be strange to link entire citations that do not include a title; plus this would conflict with author–date citations when the feature for linking to bibliography entries is enabled.

I checked the section of the CSL specification on links, which doesn't have anything to say about this.

Thank you for considering this!

jgm commented

This diff would do it:

diff --git a/src/Citeproc/Eval.hs b/src/Citeproc/Eval.hs
index e0d6ffe..6c7e6cd 100644
--- a/src/Citeproc/Eval.hs
+++ b/src/Citeproc/Eval.hs
@@ -1229,10 +1229,10 @@ evalItem layout (position, item) = do
              usedTitle <- gets stateUsedTitle
              inBiblio  <- asks contextInBibliography
 
-             -- when no links were rendered for a bibliography item, hyperlink
+             -- when no links were rendered for an item, hyperlink
              -- the title, if it exists, otherwise hyperlink the whole item
              let xs' =
-                   if usedLink || not inBiblio
+                   if usedLink
                      then xs
                    else case mburl of
                          Nothing  -> xs
@@ -1240,7 +1240,9 @@ evalItem layout (position, item) = do
                                         -- hyperlink the title
                                         then fmap (transform (linkTitle url)) xs
                                         -- hyperlink the entire bib item
-                                        else [Linked url xs]
+                                        else if inBiblio
+                                                then [Linked url xs]
+                                                else xs
 
              let mblang = lookupVariable "language" ref
                           >>= valToText

But the problem I see is that, if link-citations and link-bibliography are both set, we'd get invalid nested links. link-citations would cause the entire citation item to link to the bibliography, but then there would be links within this.

One possibility, I suppose, would be to do this only for styles without a bibliography.

Another would be to do it only if linkCitations is not set -- but this is difficult to achieve, because the code in Eval doesn't have access to this setting (currently it only affects the rendering stage).

Thank you for spending time on this!

I assume link-citations is only used for inline citations, whereas one would only want to link titles in note styles. Is there a way to restrict it to this context?

jgm commented

The types allow you to set linkCitations even for a note style.
Of course, you wouldn't want to, but you can.

As I noted, we could perhaps add code that makes linkCitations get ignored for note styles, and code that makes linkBibliography affect citations for note styles.

Have you decided whether it would be sensible to implement the patch you envisaged here?

(My aim is to reduce the length of citations by omitting URLs; but to make the reader's life easier by linking titles in the footnotes, on both first and subsequent citations, to the stored DOI/URL.)