Zotero Citations to Markdown Links via CSL

by @edent | , ,

I use Zotero to manage my references. Instead of in-text citations of (Smith, 1984) - I want that to be hyperlinked to the academic paper referenced.

For example ([Smith, 1984](https://doi.org/.....))

This is possible, if you're willing to hack around with CSL - the Citation Style Language.

Here's a fragment of CSL that I've adapted from Brenton M. Wiernik's zotero-tools/apa-doi-in-text.csl

  <macro name="url-intext">
      <if variable="DOI">
        <text variable="DOI" prefix="https://doi.org/"/>
      <else-if variable="URL">
        <text variable="URL"/>
        <text value=""/>
  <citation et-al-min="4" et-al-use-first="1" disambiguate-add-year-suffix="true" disambiguate-add-names="true" disambiguate-add-givenname="true" collapse="year">
      <key macro="year-date"/>
    <layout delimiter="; ">
      <group prefix="([" suffix="]" delimiter=", ">
        <group delimiter=", ">
          <text macro="author-short"/>
          <text macro="year-date"/>
          <label variable="locator" form="short" suffix=" "/>
          <text variable="locator"/>
      <text macro="url-intext" prefix="(" suffix="))"/>

I'm a neophyte at CSL, so I'm sure there is a better way to do it. Essentially, this is creating a group, starting with ([. Inside that it places the author(s) and date. It ends the group with ] - then obtains the URl from a macro, surrounds it by ( and )), then prints it.

There are a few bugs. If there is no URl, you might end up with mismatched brackets. But it seems to work OK.

My University insists on Cite Them Right's Harvard style - so that's what I'm using.

I've released a Zotero CSL file on GitLab if you want to use it. Feedback is very welcome - because I have no idea what I'm doing!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: