Zotero Citations to Markdown Links via CSL
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
XML <macro name="url-intext">
<choose>
<if variable="DOI">
<text variable="DOI" prefix="https://doi.org/"/>
</if>
<else-if variable="URL">
<text variable="URL"/>
</else-if>
<else>
<text value=""/>
</else>
</choose>
</macro>
<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">
<sort>
<key macro="year-date"/>
</sort>
<layout delimiter="; ">
<group prefix="([" suffix="]" delimiter=", ">
<group delimiter=", ">
<text macro="author-short"/>
<text macro="year-date"/>
</group>
<group>
<label variable="locator" form="short" suffix=" "/>
<text variable="locator"/>
</group>
</group>
<text macro="url-intext" prefix="(" suffix="))"/>
</layout>
</citation>
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!
What links here from around this blog?