Citekeys with Internal Links

Hi all,

I'm new to Zotero, and have been doing my best to piece together how to use this program from around the web.

I'm running into two problems with BetterBibTex with which I could use others' help/advice:

1.) Using quick-copy, I want to generate Citekeys with @ in front of them instead of \cite. How do I adjust the quick-copy template in this regard?

2.) I understand that it's possible for citekeys to have an internal hyperlink attached to them such that when the internal hyperlink is followed, it will open up Zotero to the exact item reference via the Citekey. How is this possible? I would love it if quick-copy could generate a citekey with the internal hyperlink included.

Thank you all for your help!
  • 1. Set the quick copy format to pandoc in the BBT prefs

    2. Set the quick copy format to select link with citekey in the BBT prefs
  • Thank you for the help!

    1.) Done, and works.

    2.) I cannot find this option under BBT preferences. I'm in the "citation key" sub-menu. After selecting "pandoc" as the quick-copy citation method, there are no other options to attach a Zotero internal link to the citatation.

    Here is an example of what I would like for Zotero to output for quick placement within an Obsidian note - [@seneca,SENECASHORTNESSLIFE,2016](zotero://select/library/items/3K9BG22A)

    Instead, I can only configure Zotero using BBT to output the @citekey with no link, or the zotero link with no citekey, depending on the quick-copy format I select.

    Once again, I appreciate the assistance very much.
  • Sorry, 2. would have to be "Citekey select link". It's the one or the other I'm afraid, Zotero allows just one translator to be selected for quick copy, and the setting that worked for you in 1. is just a way to configure the behavior of the BBT quick copy translator.

    But if you want both as one, you can select "Eta template" and enter

    <% it.items.forEach(function(item) {
    const [ , kind, lib, key ] = item.uri.match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/)
    const select = (kind === 'users') ? `zotero://select/library/items/${key}` : `zotero://select/groups/${lib}/items/${key}`
    %>[@<%= item.citationKey %>](<%= select %>)<% }) %>


  • Wow! This works! Thank you!!! Did you write that code yourself? If so, I'm deeply grateful. Saving this so that I have it accessible for years to come!!!
  • That was my handy work indeed.
  • edited June 3, 2021
    It'd be quite embarrassing if I couldn't have written that though. All of BBT is my handy work, and the scripting bits are more to fight off the urge to add any and all enhancement requests regardless of how universally useful they are, so by and large I write most of these scripts on demand.
  • Well, what you have created is extremely useful to me, and I imagine countless others. Thank you for all that you do! I just sent you a donation.
  • *grin* technically true since I do not have any telemetry so I quite literally can't count the users. But you're welcome, and much appreciated. Today wasn't entirely great, and seeing BBT be useful is a nice end of the day pick-me-up.
  • @emilianoeheyns WOW, this is amazing!! So useful! I tried to replace the "zotero link" with "url" since I sometimes take note on the webpage. It works for most of the time, but fails sometimes. I found that is because item.attachments has a varying length. I've spent some time learning eta template, but still don't known how to fix it.

    Thank you for your help!

    ```
    <% it.items.forEach(function(item) {
    const [ , kind, lib, key ] = item.uri.match(/^https?:\/\/zotero\.org\/(users|groups)\/((?:local\/)?[^/]+)\/items\/(.+)/)
    const select = (kind === 'users') ? `zotero://select/library/items/${key}` : `zotero://select/groups/${lib}/items/${key}`
    %>[@<%= item.citationKey %>](<%= item.attachments[[1]][["url"]] %>)<% }) %>
    ```
  • I think I've fixed it.

    ```
    <% it.items.forEach(function(item) {
    const tem = item.attachments
    const len = tem.length
    const link = tem[tem.length-1]

    %>[@<%= item.citationKey %>](<%= link[["url"]] %>)<%

    })
    %>
    ```
  • edited January 30, 2023
    I'm not sure about those double brackets. This should work:

    <% it.items.forEach(function(item) {
    const att = (item.attachments || []).slice(-1)[0] || {};
    %>[@<%= item.citationKey %>](<%= att.url %>)<%
    }) %>
  • But in your earlier script you wanted the 2nd item from the attachments? Do you want the last attachment (like in your last script, although that seems pretty arbitrary to me), or do you want any one attachment that has an URL?
  • @emilianoeheyns YES, I want any one attachment that has an URL ^_^. I found that only items created from PMID have an attachment with URL, while items created with DOI do not have an attachment but have a non-empty "URL" field. So I write a condition code. It's ugly but it works.

    ```
    <% it.items.forEach(function(item) {
    const tem = item.attachments

    if (tem.length === 0) {
    if (item.url) {
    %>[[@<%= item.citationKey %>]](<%= item.url %>)<%
    } else {
    %>[[@<%= item.citationKey %>]](<%= item.DOI %>)<%
    }
    } else {
    const link = tem[tem.length-1]
    const url = link[["url"]]
    %>[[@<%= item.citationKey %>]](<%= url %>)<%
    }
    })
    %>
    ```

    BTW, is it possible to export an embedded hyperlink citation with eta template code? Currently I used macOS Shortcut to run pandoc to convert quick copy from clipboard to rtf, and paste it into my Scrivener. The workflow is fine for me, though a little bit clunky.

    Thank you for your help!
  • I have no idea how link[["url"]] could possibly work in Javascript.

    This is how I would do it:

    <% it.items.forEach(function(item) {
    const att = (item.attachments || []).find(a => a.url)
    if (att) {
    %>[[@<%= item.citationKey %>]](<%= att.url %>)<%
    }
    else if (item.url) {
    %>[[@<%= item.citationKey %>]](<%= item.url %>)<%
    }
    else {
    %>[[@<%= item.citationKey %>]](<%= item.DOI %>)<%
    }
    })
    %>
    BTW, is it possible to export an embedded hyperlink citation with eta template code?
    I don't understand what you mean by this.
  • Thank you !!
    I meant is it possible to export rich-text quick copy using eta template code? I currently export it as plain text ( [xxx](http://xxx) ) and use pandoc to convert it into rich-text.
  • You can generate any text you want -- it could be HTML, RTF, you name it.

    <% it.items.forEach(function(item) {
    const att = (item.attachments || []).find(a => a.url)
    if (att) {
    %><a href="<%= att.url %>">@<%= item.citationKey %></a><%
    }
    else if (item.url) {
    %><a href="<%= item.url %>">@<%= item.citationKey %></a><%
    }
    else {
    %><a href="<%= item.DOI %>">@<%= item.citationKey %></a><%
    }
    })
    %>


    but drag&drop / copy&paste would tell the receiving application it is getting plaintext. There isn't a way to tell the receiving application "and interpret that as HTML/RTF". If the application auto-detects it, that would work, otherwise you'd just get the markup in your text.
  • WOW! I get it! Thank you so much!!! (^_^)
Sign In or Register to comment.