Word: Possibility to link references and bibliography in a document?

2
  • I am also writing my PhD thesis and I really need this option. I tried to use the macro but it doesn't work for me. Can any one please explain how to use it?
    Thanks
  • captaindare: You are more likely to get help if you explain how it did not work for you. What did you do and did you get an error message.
  • thank you for your quick reply. I never used VB before, so I just copy paste the code in the VB editor, saved it to get the ZoteroLinkCitation macro and then execute it in the word file containing the references and the bibliography. But nothing happened! so I changed the format of the Zotero citation format from bookmarks to fields but then this message show up "Word finished checking the selection. Do you want to continue checking the remainder of the document?" and I had to restart word...
    I replaced the line 67 and added the bookmark "zoteto bibliography" but nothing changed!
    so can you please tell me the steps I have to take?
    Thank you
  • I tried again and now it creates links but all of them are pointing to the beginning of the document not to the biblio. And when I convert to pdf even those links disappear but the blue color and the underline remained!
    By the way is it possible to make links without the underline?
  • there is some improvement... I commented this line:
    ' titleAnchor = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(title, " ", "_"), "&", "_")

    and now the links work well in word. That's great! but they disapper in the converted pdf
  • well, I took sometime to solve a part of the problem:
    - because my titles have more strange characters so I had to clean them adding some other Replace to titleAnchor.
    - then I created a bookmark for each reference (instead of only one "Zotero_Bibliography"):
    Add Range:=Selection.Range, Name:=titleAnchor
    - and finally I pointed the link to the bookmarks:
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", SubAddress:=ActiveDocument.Bookmarks(titleAnchor), ScreenTip:="", TextToDisplay:="" & numOrYear

    And it worked fine in both word and pdf!

    Now still the problem of getting only the first two citations linked when there ar 3 or 4 (e.g. [2, 5, 22]). Is it related to n1 and n2? Can you please help me with that?
  • I agree that this would be really useful - especially the ability to jump/mouseover references while writing. It's the only feature which makes me want to use Endnote.

    I had a go at implementing antikorpo's script in a file I had and made some changes. This should now be able to cope with more than 2 references in the same field, and also adds a tooltip when you hover over the references. Note that I was using IEEE format and didn't try this with anything else.

    Oddly I noticed that Word will accept up to 255 characters for the tooltips, but the links break when the file is closed and reopened if they are too long!

    Code included below incase it helps someone. Perhaps someone who knows more about VBA than me (or better still, the next version of Zotero) could turn this into something more robust.



    Public Sub ZoteroLinkCitation()

    ' get selected area (if applicable)
    Dim nStart&, nEnd&
    nStart = Selection.Start
    nEnd = Selection.End

    ' toggle screen updating
    Application.ScreenUpdating = False

    ' define variables
    Dim title As String
    Dim titleAnchor As String
    Dim style As String
    Dim fieldCode As String
    Dim numOrYear As String
    Dim pos&, n1&, n2&

    ActiveWindow.View.ShowFieldCodes = True
    Selection.Find.ClearFormatting

    ' find the Zotero bibliography
    With Selection.Find
    .Text = "^d ADDIN ZOTERO_BIBL"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute

    ' add bookmark for the Zotero bibliography
    With ActiveDocument.Bookmarks
    .Add Range:=Selection.Range, Name:="Zotero_Bibliography"
    .DefaultSorting = wdSortByName
    .ShowHidden = True
    End With

    ' loop through each field in the document
    For Each aField In ActiveDocument.Fields
    ' check if the field is a Zotero in-text reference
    If InStr(aField.Code, "ADDIN ZOTERO_ITEM") > 0 Then
    fieldCode = aField.Code
    pos = 0
    inc = 1

    ' find the title field within the field code
    Do While InStr(fieldCode, """title"":""") > 0
    n1 = InStr(fieldCode, """title"":""") + Len("""title"":""")
    n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), """,""") - 1 + n1

    title = Mid(fieldCode, n1, n2 - n1)

    ' make title a valid bookmark name
    titleAnchor = title
    titleAnchor = MakeValidBMName(titleAnchor)

    ActiveWindow.View.ShowFieldCodes = False
    Selection.GoTo What:=wdGoToBookmark, Name:="Zotero_Bibliography"

    '' locate the corresponding reference in the bibliography
    '' by searching for its title
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = Left(title, 255)
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute

    ' select the whole caption (for mouseover tooltip)
    Selection.MoveStartUntil ("["), Count:=wdBackward
    Selection.MoveEndUntil ("[")
    lnkcap = "[" & Selection.Text
    lnkcap = Left(lnkcap, 40)

    ' add bookmark for the reference within the bibliography
    Selection.Shrink
    With ActiveDocument.Bookmarks
    .Add Range:=Selection.Range, Name:=titleAnchor
    .DefaultSorting = wdSortByName
    .ShowHidden = True
    End With

    ' jump back to the field
    aField.Select

    ' find and select the numeric part of the field which will become the hyperlink
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "^#"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With

    Selection.Find.Execute

    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=pos

    Selection.Find.Execute

    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    numOrYear = Selection.Range.Text & ""
    pos = pos + Len(numOrYear) + 4 * inc

    ' store current style
    style = Selection.style

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", SubAddress:=titleAnchor, ScreenTip:=lnkcap, TextToDisplay:="" & numOrYear
    aField.Select

    ' reset the style
    Selection.style = style

    ' uncomment to force black font/no underline
    ' With Selection.Font
    ' .Underline = wdUnderlineNone
    ' .ColorIndex = wdBlack
    ' End With

    ' next title within this field
    fieldCode = Mid(fieldCode, n2 + 1, Len(fieldCode) - n2 - 1)
    Loop

    End If
    Next aField ' next field

    ' go back to original range selected
    ActiveWindow.View.ShowFieldCodes = False
    ActiveDocument.Range(nStart, nEnd).Select

    End Sub


    Function MakeValidBMName(strIn As String)
    Dim pFirstChr As String
    Dim i As Long
    Dim tempStr As String
    strIn = Trim(strIn)
    pFirstChr = Left(strIn, 1)
    If Not pFirstChr Like "[A-Za-z]" Then
    strIn = "A_" & strIn
    End If
    For i = 1 To Len(strIn)
    Select Case Asc(Mid$(strIn, i, 1))
    Case 49 To 57, 65 To 90, 97 To 122
    tempStr = tempStr & Mid$(strIn, i, 1)
    Case Else
    tempStr = tempStr & "_"
    End Select
    Next i
    tempStr = Replace(tempStr, " ", " ")
    MakeValidBMName = Left(tempStr, 40)
    End Function
  • I also am in the same boat with many in this thread, and would really like to see this feature implemented. My approach to implementation would be to modify the text (field) Zotero inserts, concatenating a bookmark (or something like that) with each item in the bibliography, and wrapping the inline citation text in Word's equivalent of <a href="...">...</a> tags.

    I see other threads on this here, here, and here (thanks in part to aurimas above).
  • edited November 24, 2014
    Thanks to antikorpo and cjac1 for the macros!

    I found that while cjac1's version of the macro worked with more than 2 references in the same field (i.e. "[1], [2], [4]") it also messed up the handling of a range (i.e. "[1]-[3]"). What ends up happening is the next number in the document (any number, not just a reference) gets the hyperlink added to it instead.

    I don't have experience with VB at all, but from what I can tell this has to do with the "pos = pos + Len(numOrYear) + 4 * inc" part that cjac1 added. I don't know how to fix this, so as a workaround I'm just using antikorpo's and cjac1's macros one after the other to get all the references hyperlinked, and then manually deleting the undesired hyperlinks.

    I would appreciate if someone with VB experience could look at the code above and suggest a fix to cjac1's version. Perhaps some kind of if statement, where if the relevent text is in the form "[1]-[3]" use antikorpo's method, and if it is in the form "[1], [2], [4]" use cjac1's method?
  • Hi everybody, thanks to anticorpo and cjac1 for the macros. I try cjac1 macros and this code works with citation in form [1], [2], ..., [n] but not with citation in form [1,2] or [1]-[3] or [1-3]. I try this script with IEEE Style and I prepare document in this struture:

    Text [1] next text. Text [1], [2] next text. Text [1-3] next text. Text [4] next text. The first three citations ([1], [1], [2]) are correctly linked to right records in bibliogrphy, the fourth citation ([1]) is uncorectly linked to second record in biblography. Last citation [4] is again correctly linked to right record in bibliography.
  • I had a document that had two way hyperlink in microsoft word with zotero ... but it was messed up in a few ways (I had been working on a while and forgot how I got it). I think I inserted a bibliography using word (not zotoero) een though I inserted citations with zotero ... I assume not a good thing to do.??.
  • I think you're confusing endnotes and bibliography: Endnotes are auto-linked by Word. You'd never have automatically linked bibliographies using Zotero out of the box and using Word's bibliography feature with Zotero citations simply wouldn't work at all.
  • +1 to the OP's suggestion of bibliography hyperlinking, i.e. (if I understood it correctly) having the full reference appear in a tool tip when hovering the mouse over the in-text citation, and being able to click on the in-text citation as a hyperlink to the relevant part of the Bibliography.
  • Has there been progress on the hyperlink issue?

    I fear that convincing people of zotero (in my company) will be very hard without hyperlinks :-(

    thanks for the great work.
  • nothing new. Does any non-LaTeX program do this?
  • Using an automatically numbered list as bibliography in word gives you links. But you have to deal with content by hand ;-)
    And these hyperlinks are *really* popular, here.

    In other words, currently, we have hyperlinks and people do not want to take a step in a direction that feels like backwards...
    cheers from Bavaria
  • I tried the macro that cjac1 posted but it did not work. I wonder if this could be because this macro only works for numbered references?

    I have a document with APA formatted references, which look like this in the text:
    (Miller & Smith, 2007) and like this in the reference list: Miller, A.B., & Smith, C.D. (2007). An essay on references. Journal of the Internet, 5, 3-10.

    The result of running the macro was that the yearnumber in the in-text citations was turned into a hyperlink, and these links pointed at various points in the document and/or in the reference list.

    Could it be that I did something wrong (I just copy/pasted the code and ran it)? Or can I give up tryping because the macro does not work unnumbered references?

  • I haven't looked at the code in detail, but looking at how it works, it should work for any in-text citation.
  • edited August 2, 2017
    Sorry I found answer in another thread. It is not done yet.
  • Has anyone created a version of this macro that works with superscript numbers? If so would you be willing to share? I'm trying to figure out how to hyperlink my references to the bibliography but need to use superscript numbers.
  • edited May 7, 2018
    So, in-line citations by Zotero do not hyperlink to the full citation in the bibliography, right? I did not realize this functionality is missing. I've seen PDFs with this feature and it is very useful. Not sure where we are on path to completion but an update would help.

    Other threads that discuss this:
    https://forums.zotero.org/discussion/21045/hyperlink-to-bibliography
    https://forums.zotero.org/discussion/56840/hyperlinks-to-bibliography
    https://forums.zotero.org/discussion/7534/hyperlinking-citations-to-bibliography-in-openoffice
    https://forums.zotero.org/discussion/27602/in-text-citations-hyperlink-to-bibliography
  • Hey everyone,
    I'd like to reinforce the desire for this update. That would be very helpful.
    I'm new here in the forum, so how can we make this happen? Zotero developers see our threads here? Should we send a formal suggestion to them or something?
    Thanks guys and sorry if I missed something from the discussion.
  • Zotero devs see this, yes.
  • Hello everyone,
    Antikorpo's initial script (thanks!) inspired me to write an extended version of it.
    I put it here: https://github.com/pavelninin/zotero_two_way_hyperlinking.
    The script is based on the search of certain elements in the Word document and then it does the job (see the code for details). It also tries to maintain the local cache to accelerate the processing and it also has some other features (see opt_xxx variables). Note: I am not yet strong in VBA programming, so sorry for the bad code style. However, even this version was sufficient for me to do the job. Improvements are welcome!
  • Hello everyone !
    And thanks a lot for the various macros...
    Here is my experience : I have a 300 pages document with 330 citations.
    I used antikorpo's script, which worked just fine but did not transfer the links to the PDF (I use Adobe Acrobat Pro).
    I used Cjac1's macro, and it work just fine. One citation (labeled in zotero as "email") mde it crash at line :
    title = Mid(fieldCode, n1, n2 - n1)
    Since I changed the label in zotero, everything works fine and I have the links in the PDF.

    Lastly I tried to use Pavelninin's macro for two way linking, and I have this error message :
    "Object required (Error 424)" at line "Call UI_PROGRESS_BAR.Show(vbModeless)".

    Any ideas ?

    Anyway, one way linking is already something very nice to integrate ! Again thanks a lot !
    Victor
  • Hello all,

    The scripts/macro's posted didn't work for me personally; I might be using them wrong/have the citations such that it isn't compatible. I would love it if this would become a functionality of Zotero. I prefer it above EndNote but I do need this functionality.

    I would like to 1) focus attention on this topic/thread and 2) ask if a dev could tell us if this is something that is being added? I think that many would, and continue to do so, really appreciate it!

  • ask if a dev could tell us if this is something that is being added?
    We'd like to have this, but it would require a rather large amount of work for a feature that's not that high on the priority list so we have no plans for the near future.
  • Also interested in this feature. Numerous others would seriously consider moving their company on to Zotero if this was a standard feature. A link from an in-text citation to the bibliography is a must-have.
Sign In or Register to comment.