MDNotes and Zotero 6 Questions

Hi all,

My intention is to use the MDNotes extension to export metadata and annotations to Obsidian using Zotero 6.

Questions / issues:
1.) Formatting the 'MDNotes Default Template' file in Obsidian

Here is the present formatting of my template:

---
alias: {{citekey}}
---

{{title}}
{{author}}

## Zotero links
{{localLibrary}}
{{cloudLibrary}}

## Metadata
- **PDF:** {{pdfAttachments}}
- **ItemType:** {{itemType}}
- **Title:** {{proceedingsTitle}}
- **Author:** {{author}}
- **Date:** {{date}}
- **Date Added:** {{dateAdded}}
- **URL:** {{url}}
- **DOI:** {{DOI}}
- **Citekey:** {{citekey}}
- **Collections:** {{collections}}
- **Related:** {{related}}
- **Tags:** {{tags}}, #Literature


{{abstractNote}}

---

PROBLEM: All of the variables generate a "* (variable name)" prior to listing the variable itself. I would like for the variables just to fill in without the asterisks and variable title, thus allowing ME to add in the titles for each variable's section. It's just cleaner that way. Also, an issue arises with the alias in which the citekey variable doesn't add in just the citekey; again, it adds "* citekey:" before listing the citekey itself. Can the template for each of these variables be changed in some way to address this issue?

2.) {{abstractNote}} variable issues
Question A: When I export annotations from Zotero into Obsidian using MDNotes, it lists in the exported Obsidian file the title "Annotations" twice before listing the annotations. I think that this is because Zotero lists the "Annotations" title in the original annotations file, and then the MDNotes variable template also lists the title. Again, can the MDNotes variable template be tweaked in some way?

Question B: My annotations in Obsidian do not have hyperlinks back to the annotation's exact location in the PDF. Is this a pending feature following the Zotero 6 upgrade? I remember that MDNotes was capable of doing this when I used it a year ago.

---

Thank you to anyone who can assist me with these questions! Take care.
  • edited May 23, 2022
    You might get help on Obsidian forum or Discord (there a whole thread academia there where people share many tips on Zotero use and templates), the creator of the plugin is active and might answer questions there :) (on the Zotero forum as well)

    Under Zotero 6 the active development now is much lighter than before, the other nice plugin for Obsidian is https://github.com/mgmeyers/obsidian-zotero-integration

    Here some interesting workflow https://publish.obsidian.md/history-notes/From+Zotero+Annotations+to+Obsidian+Research+Notes

    There is also a bibnotes formater that might have a better support for notes extracting https://github.com/stefanopagliari/bibnotes
  • edited May 23, 2022
    >PROBLEM: All of the variables generate a "* (variable name)" prior to listing the >variable itself. I would like for the variables just to fill in without the asterisks and >variable title, thus allowing ME to add in the titles for each variable's section. It's >just cleaner that way. Also, an issue arises with the alias in which the citekey >variable doesn't add in just the citekey; again, it adds "* citekey:" before listing the >citekey itself. Can the template for each of these variables be changed in some way >to address this issue?

    If you have problems with the field values it could be edited with the Preferences>advanced > Config editor but it shouldnt be the case, I never experienced this beviour
  • You said you want to use the MDNotes plugin to export metadata and notes to Obsidian, but I would like to suggest using the Obsidian Zotero Intergration aka. Zotero Desktop Connector community plugin

    Here's an Obsidian link: obsidian://show-plugin?id=obsidian-zotero-desktop-connector

    Here's the Github link: https://github.com/mgmeyers/obsidian-zotero-integration

    Using this Obsidian plugin and the template below, you can very easily import metadata and annotations / notes from Zotero into Obsidian, directly within Obsidian. The variable name will not be present after using the template.

    In my template, I have some of the metadata in the YAML frontmatter, and also in a callout below. I use callouts for the metadata and the abstract.

    You have to setup an import format (I called mine "Literature note") in the settings of the Zotero Integration plugin, which will then use the template.

    The plugin has a command called "Data explorer", which will tell you the available variables. Their templating documentation is found here: https://github.com/mgmeyers/obsidian-zotero-integration/blob/main/docs/Templating.md.


    Here's the template, but you could easily adapt your template for Zotero Integration:

    ---
    citekey: {{citekey}}
    alias: [{% if shortTitle %}"{{shortTitle | safe}}"{% else %}"{{title | safe}}"{% endif %}]
    title: "{{title}}"
    authors: {{authors}}
    tags: [{% for t in tags %}{{t.tag}}{% if not loop.last %}, {% endif %}{% endfor %}]
    year: {{date | format("YYYY")}}
    publisher: "{{publicationTitle}}"
    ---

    ## {{title}}
    >[!info]-
    >{% if bibliography %}
    >**Bibliography:** {{bibliography}}
    >{% endif %}
    >{% if hashTags %}
    >**Tags:** {{hashTags}}
    >{% endif %}
    >{%- for attachment in attachments | filterby("path", "endswith", ".pdf") %}
    > **Link:** [{{attachment.title}}](file:///{{attachment.path | replace(" ", "%20")}}){%- endfor -%}
    >
    >[**Open in Zotero**]({{desktopURI}})
    >[**Open DOI**](https://doi.org/{{DOI}})


    ---


    > [!abstract]-
    > {% if abstractNote %}
    >{{abstractNote}}
    >{% endif %}

    ---

    {% if markdownNotes %}
    {{markdownNotes}}{% endif %}
  • @ingmar93, I cannot thank you enough for this recommendation! The Zotero Integration Plugin is a HUGE leap in ease-of-use and functionality (i.e. annotations have a link that opens the exact annotation location within the PDF).

    A few quick questions related to the Zotero Integration Plugin in case you or someone else can address:
    1.) Is it possible for exported annotations to indicate the color of each annotation? The MDNotes export allows for this IF an annotation note is generated within Zotero 6, and if "display colors" are enabled for that specific annotation note.

    2.) In reviewing the readme file for the Zotero Integration Plugin, it seems like the plugin has the capability to extract annotations from a PDF without the need to generate an "annotations" note manually inside of Zotero before exporting the source into Obsidian. However, after experimenting with this plugin, I cannot find a way for it to auto-extract annotations from a PDF, regardless of whether the annotations are created within Adobe Acrobat and saved to the PDF itself, or if the annotations are created inside of Zotero 6's PDF viewer. I must generate an annotation file in Zotero in order for those annotations to carry over into Obsidian. This isn't a big deal; it would just be nice if this plugin eliminated the step of needing to generate an annotations note every time I want my annotations to appear in Obsidian.

    Happy researching!
  • Regarding 1., it is possible to indicate the color, if you change the note template for annotations under in the config editor under advanced settings. See the relevant Zotero documentation in the knowledgebase.

    2. If your problem here relates to the template I shared, then that's because it only imports the markdown notes, or annotations saved in a note using "Add note from annotations", associated with the reference.

    You can also import embedded annotations from PDFs, I have since learnt. In contrast to annotations made within Zoteto, embedded annotationa are saved under the {{annotations}} variable. So you need to add something like this to your template:

    {% for annotation in annotations %}
    {% if annotation.annotatedText %}
    > {{annotation.annotatedText}}
    > {% endif %}
    > {% if annotation.comment %}
    > {{annotation.comment}}
    {% endif %}
    {% endfor %}

    However, these embedded annotations with not come with links to the exact annotation location.

    Alternatively, you can convert embedded annotations into Zotero annotations by using File -> "Import annotations" while in the PDF reader. Then, these can be exported to an annotation note and import that way into Obsidian, along with any native notes and annotations.

    As far as I can tell, it is not yet possible to auto-extract annotations made within the Zotero PDF reader to a note, thus making it importable into Obsidian. You have to manually trigger "Add note from annotations", which makes the workflow a bit less seamless. Such an auto export/extraction feature would be great enhancement.
  • Thank you for explaining all of this! I'll read the documentation from here. It looks like extracting annotations from a Zotero PDF is the best way to go. The ability both to see highlight colors and link back to the location of each annotation is very powerful.
  • @ingmar93, I read through all of the available documentation for Zotero Integration Plugin, but see nothing that references how to indicate annotation color after importing annotations into Obsidian via the 'markdownNotes' variable. I see that this is possible when using the 'annotatedNotes' variable; however, I don't use that variable since I save my annotations using the Zotero PDF reader.

    I posted this question/issue to the GitHub for the plugin. Still, I'm mentioning it here in case you're aware of an easy way to fix this. If not, no worries. Thanks again for your (and others!) help.
  • That's because it's in the Zotero documentation, but appears to be quite buried, as it is not linked on the documentation page: https://www.zotero.org/support/note_templates

    You need to change the note template in Zotero using the config editor under advanced settings.
  • OK, we're on the same page now. I never knew about accessing the config editor inside of Zotero's advanced options. There's lots here to tweak; very cool!

    I played around with the variable 'annotations.noteTemplates'; however, still no joy in color highlights carrying over into Obsidian using the Zotero Integration Plugin. This isn't a big deal as I'm coming to realize that I could using things like blockquotes, emboldening, and italics to delineate between the varying highlight colors. Still, it would be nice if colors could be shown, like the MDNotes plugin makes possible.

    Also, I found out that I can edit all of the formatting for the MDNotes variables within the Zotero config editor that was a stated issue in the first post of this thread. I'm debating whether to do that and then go back to MDNotes, or stick with Zotero Integration Plugin. I lean toward the latter since it allows for direct hyperlinking to quoted text whereas MDNotes does not.
  • @shimel123 - "Is it possible for exported annotations to indicate the color of each annotation?"

    In your Zotero Integration template:
    <mark style="background: {{annotation.color}}">{{annotation.annotatedText}}</mark>
  • @William, thank you for your reply.

    Should I add this into my Obsidian Zotero Integration template, or in Zotero within the annotations.noteTemplates variable located in the Config Editor? I'm guessing you mean in the Obsidian template.

    Following that assumption, I tried adding in your variable into Obsidian's Zotero Integration template, but nothing changed even though I attempted to import colored highlights from Zotero (color highlights were enabled inside of Zotero before I imported into Obsidian).

    I tried placing your HTML command both within and outside of the brackets of the following annotations import code found inside of the Zotero Integration template:

    {% if markdownNotes %}
    {{markdownNotes}}{% endif %}

    Thanks again for your help!
  • This is for the Zotero Integration template. However, {{markdownNotes}} are not colored as are highlights, so there is no {{markdownNotes.color}} variable for markdownNotes. Therefore, the html mark style syntax provided will not work on {{markdownNotes}} as it does on {{annotation.annotatedText}}.
  • @William OK, I'm almost there in regard to understanding what to do, but let me know ask a few questions.

    When I've used the {{annotation.annotatedText}} variable in my ZI template before, nothing comes over after importing annotations from Zotero. In such instances, I highlighted multiple passages of a PDF, added notes to each highlight, and generated an annotations file inside of Zotero before importing into Obsidian. The only way I've managed for highlights and notes to transfer from Zotero to Obsidian has been the {{markdownNotes}}. Is there something I'm missing here in terms of either what {{annotation.annotatedText}}, or something I should be doing within Zotero before importing into Obsidian?

    Finally, when adding your HTML syntax to my ZI template, then how should I format everything? Should I just add the HTML code as you listed it, or does it need to be placed after {{annotation.annotatedText}}? For instance...

    {{annotation.annotatedText}}
    YOUR HTML CODE HERE

    Sorry, am noob with programming! Thanks for your patience.
  • edited September 20, 2022
    To get the annotations (colored highlights), put this in your template:

    {% for annotation in annotations %}
    {% if annotation.annotatedText %}
    <mark style="background: {{annotation.color}}">{{annotation.annotatedText}} </mark> [(p. {{annotation.page}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}})
    {% endif %}
    {% endfor %}
  • @shimel123

    If you want your comments as well, here is the code for both annotations and comments:

    {% for annotation in annotations %}
    {% if annotation.annotatedText %}
    <mark style="background: {{annotation.color}}">{{annotation.annotatedText}}</mark> [(p. {{annotation.page}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}})
    {% endif %}
    {% if annotation.comment %}
    {{annotation.comment}}[(p. {{annotation.page}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}})
    {% endif %}
    {% endfor %}
  • @William AMAZING! It works, and it's such an improvement over MarkdownNotes because a.) I don't have to generate an annotations file in Zotero before exporting to Obsidian; b.) highlighting of individual colors comes through; and c.) sticky notes now have hyperlinks, where they didn't with MarkdownNotes. Fantastic!

    One small issue remains: Between the annotation and the associated comment, a space of two returns is present. Similarly, between each annotation, a space of 3 returns is present. Can this be adjusted at all? I'd like to play with it so that the formatting is a little cleaner. If not, then no worries as this is a minor issue.

    Thanks again, William! If I can Paypal you some money as a thank you, just send along an appropriate email.
  • @shimel123 re: spacing, in Obsidian "editing" view, the spacing appears wide, but in the "reading" view, it should show proper spacing. However, if you want less spacing, I don't know how to make the template show less spacing in the output.

    Happy to help.
  • @William OK, that's great. Thanks for clarifying. That will be a suitable workaround. Take care.
  • edited September 29, 2022
    @shimel123 I think I found a solution to the spacing issue; modifying extensions.zotero.annotations.noteTemplates.highlight:

    <p>{{highlight}} {{citation}}</p>{{if comment}}<blockquote>{{comment}}</blockquote>{{endif}}

    Also, in my Zotero Integration template, I have a section for Notes, and I separate each {{note.note}} with a horizontal rule:

    <hr style= "margin-top: -4px; margin-bottom: 4px";>
  • @William Sorry, but this doesn't change anything for me. The spacing issue remains. The best workaround seems to be simply rendering the Obsidian file, and then the spacing issue disappears.

    When using this code:

    {% for annotation in annotations %}
    {% if annotation.annotatedText %}
    {{annotation.annotatedText}} [(p. {{annotation.page}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}})
    {% endif %}
    {% if annotation.comment %}
    {{annotation.comment}}[(p. {{annotation.page}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}})
    {% endif %}
    {% endfor %}

    Nothing is changed in terms of output whatsoever when I edit variables within the "config editor" of Zotero for the three different "noteTemplate" variables. I don't think that Zotero is referencing those variables when it is generating highlights and comments using the "annotation.annotatedText" variable. I cannot find a variable by that same name within Zotero's Config Editor.

    Turning to another matter...

    I wish that a comment attached to a highlight would immediately follow on the same line after the highlight instead of being placed on its own line like a sticky comment. If, however, I add the (annotation.comment) variable right after the highlight variable, it lists the comment in the right place, but also double-lists the comment later like it's also a sticky comment. I wish that there was a way to avoid this double listing/posting comments issue. If I cannot fix this, then this approach overall will not work for me and I'll have to go back to extracting markdown annotations from each PDF.

    Thanks again for all your help, William!
  • I'm interested to find obsidian-zotero-integration uses nunchucks, I was just requesting zotero consider liquid for its note templates in https://forums.zotero.org/discussion/101807/note-templates-engine-replace-with-a-more-common-template-engine

    I also stumbled across an emacs org-mode user who wants templated zotero export as well. I'd really love to have the zotero core and plugins use a first class, standard templating system; not the custom ones in mdnotes and zotero note templates today.

    But just like zotnote annotation extraction made it into core with 6, I'd like to see templated text export make it into core in the future (and eliminate the need for either mdnotes or obsidian-zotero-integration).

    Does that sound crazy?
  • @-william-

    Hey, thanks so much for this workaround. I was wondering if you knew how to get the template to change the default Zotoro highlight color when importing to obsidian? For example, when I import from Zotoro using the integration plugin, it colours all yellow as #ffd400, but I'd like the highlights to show up as #FFF3A3A6 in obsidian.

    Thanks!
Sign In or Register to comment.