Making Citations Clickable Hyperlinks
If I'm using Zotero to write articles, research papers, etc., that are published electronically (e.g., online), is there any way to make the citations (in the body of the text) clickable so that the reader is taken to the abstract, full study, etc.?
For example, let's take the following excerpt about supplementation with oral glutathione:
"Setria (oral) glutathione has been shown to increase blood levels of glutathione. (1) Sublingual glutathione has also been shown blood levels of glutathione. (2) However, is there any head-to-head comparative data?"
In this example, I'd like to hyperlink citation 1 to this study: https://www.ncbi.nlm.nih.gov/pubmed/24791752
And I'd like to hyperlink citation 2 to this study: https://www.ncbi.nlm.nih.gov/pubmed/26262996
Is there any way to do this automatically through Zotero? Or, is this something that needs to be done manually (e.g., after writing, unlink citations, then manually add hyperlinks)?
Thank you very much for your time and help!
For example, let's take the following excerpt about supplementation with oral glutathione:
"Setria (oral) glutathione has been shown to increase blood levels of glutathione. (1) Sublingual glutathione has also been shown blood levels of glutathione. (2) However, is there any head-to-head comparative data?"
In this example, I'd like to hyperlink citation 1 to this study: https://www.ncbi.nlm.nih.gov/pubmed/24791752
And I'd like to hyperlink citation 2 to this study: https://www.ncbi.nlm.nih.gov/pubmed/26262996
Is there any way to do this automatically through Zotero? Or, is this something that needs to be done manually (e.g., after writing, unlink citations, then manually add hyperlinks)?
Thank you very much for your time and help!
Upgrade Storage
There are also several methods discussed in various places on these forums to link the numeric citations to the bibliography entry, and you can include the DOI or URL there and use Word AutoFormat to make them clickable links.
Thanks so much for taking the time to provide such a thoughtful reply. I should have noted that I did attempt to do my due diligence in searching these forums before posting my question. I know it's a cardinal sin not to do so :)
I don't know much about using Word macros, so I'll need to look into that.
In another thread here on the forums, I think I saw someone mention that the Zotero plug-in for WordPress may have the capability to do what I'm looking for. The articles I'm writing are published in WordPress -- although that's done by someone else in my organization -- so maybe that's something for me to consider as well.
Thank you very much for your time and help!
In Word this would be done with bookmark references.
Feel free to improve the code.
import uno
from ast import literal_eval as to_dict
document = XSCRIPTCONTEXT.getDocument()
#alter this for citations divided by comma
ns = ";"
def copylinks():
oSearch = document.createSearchDescriptor()
oSearch.SearchRegularExpression = True
oCurs = document.getText().createTextCursor()
refmarks = document.ReferenceMarks
for refmark in refmarks:
a = refmark.Name
b, _ = a.rsplit(" ", 1)
_,_, c = b.split(" ", 2)
d = to_dict(c)
cite = d["properties"]["formattedCitation"]
plain_cite = d["properties"]["plainCitation"]
plain_cite = plain_cite.replace("(", "")
plain_cite = plain_cite.replace(")", "")
#alter this for citations divided by comma
names = list(plain_cite.split(ns))
if "citationItems" in d.keys():
list_e = d["citationItems"]
else:
continue
for g in list_e:
if "itemData" in g.keys():
h = g["itemData"]
authors = h["author"]
m = authors[0]
author = m["family"]
citatation = list(filter(lambda x: author in x,names))
oCurs = refmark.getAnchor()
oCursor = oCurs.getStart()
oSearch.SearchString = citatation[0]
oFound = document.findNext(oCursor, oSearch)
oCursor2 = oFound.Text.createTextCursorByRange(oFound)
if "DOI" in h.keys():
DOI = h["DOI"]
else:
DOI = ""
if "source" in h.keys():
source = h["source"]
else:
source = ""
if "note" in h.keys():
note = h["note"]
else:
note = ""
else:
continue
if DOI:
oCursor2.HyperLinkURL = "https://doi.org/" + DOI
aaa = oCursor2.HyperLinkURL
elif source == "PubMed":
_, n = note.split(": ")
oCursor2.HyperLinkURL = "https://pubmed.ncbi.nlm.nih.gov/" + n
else:
pass
I found this answer in another place and I just apply a small Word macro that automatically turns numeric Zotero citations like [1] into clickable links that jump to the corresponding entry in the bibliography.
Instructions:
- Finish your document using Zotero (add/remove citations, finalize style, etc.).
- [optional, but recommended] Save a backup copy of your file.
- In Word, go to the Zotero tab and click Unlink Citations (this converts all citations and the bibliography to plain text).
Press Alt + F11 to open the VBA editor.
Go to Insert → Module and paste the macro below into the new module.
"""
Option Explicit
Sub MakeZoteroNumericCitationsClickable()
Dim doc As Document
Dim i As Long
Dim blockStart As Long, blockEnd As Long
Dim lastBlockStart As Long, lastBlockEnd As Long
Dim p As Paragraph
Dim listType As WdListType
Dim bibStartPos As Long
Dim num As Long, maxNum As Long
Dim rngSearch As Range
Dim findRange As Range
Dim n As Long
Set doc = ActiveDocument
' 1) Find the LAST numbered list block (assumed bibliography)
blockStart = 0
blockEnd = 0
lastBlockStart = 0
lastBlockEnd = 0
For i = 1 To doc.Paragraphs.Count
Set p = doc.Paragraphs(i)
listType = p.Range.ListFormat.ListType
If listType <> wdListNoNumbering Then
If blockStart = 0 Then blockStart = i
blockEnd = i
Else
If blockStart <> 0 Then
lastBlockStart = blockStart
lastBlockEnd = blockEnd
blockStart = 0
blockEnd = 0
End If
End If
Next i
' If document ends inside a list
If blockStart <> 0 Then
lastBlockStart = blockStart
lastBlockEnd = blockEnd
End If
If lastBlockStart = 0 Then
MsgBox "No numbered list (bibliography) was found.", vbExclamation
Exit Sub
End If
bibStartPos = doc.Paragraphs(lastBlockStart).Range.Start
' 2) Create bookmarks ref1, ref2, ... in the bibliography
maxNum = 0
On Error Resume Next
For i = lastBlockStart To lastBlockEnd
Set p = doc.Paragraphs(i)
num = p.Range.ListFormat.ListValue
If num > maxNum Then maxNum = num
doc.Bookmarks.Add Name:="ref" & CStr(num), Range:=p.Range
Next i
On Error GoTo 0
If maxNum = 0 Then
MsgBox "No list numbers were detected in the bibliography.", vbExclamation
Exit Sub
End If
' 3) Find [n] in the main text and turn them into hyperlinks
Set rngSearch = doc.Range(0, bibStartPos - 1)
For n = 1 To maxNum
Set findRange = rngSearch.Duplicate
With findRange.Find
.ClearFormatting
.Text = "[" & CStr(n) & "]"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
doc.Hyperlinks.Add Anchor:=findRange.Duplicate, _
SubAddress:="ref" & CStr(n), _
TextToDisplay:="[" & CStr(n) & "]"
findRange.Collapse wdCollapseEnd
Loop
End With
Next n
MsgBox "Numeric citations linked to bibliography.", vbInformation
End Sub
"""
Close the VBA editor.
Press Alt + F8, select MakeZoteroNumericCitationsClickable, and click Run.
The macro assumes:
You are using numeric citations like [1], [2], …
Your bibliography is the last numbered list in the document.
Now, clicking on any [n] in the text will jump directly to reference n in the bibliography.
(If you have a long document, Word may lag a little bit while the macro runs, just wait.)
https://github.com/altairwei/ZoteroLinkCitation
From this thread:
https://forums.zotero.org/discussion/comment/460379/#Comment_460379