Zotero Integration – Import Templates?

Thank you so much! This has been so useful for me.

Perhaps not a query you have needed to consider but I have found myself importing notes/highlights etc. from book pdfs. The challenge I am facing is on each import my hard work of separating annotations into their respective chapters is undone and needed again.

I have tried to search the forums and web for a work around but I am unsure I will be able to?

Hello everyone! Figured I would share my template after I spent maybe a little toooooo long on it! Shout out to @Feralflora @Qwxlea @apfelstrudelig as I mainly referenced their templates as a jumping off point.
Template:

---
aliases: 
- {{title | upper}}
- "@{{citekey}}"
year: {{date | format("YYYY")}}
related: 
{%- for r in relations %}
- {{r.citekey}}
{%- endfor %}
---
{#- This is the order in which the annotations are ordered -#}
{%-
   set categoryHeading = {
        "yellow":  "Summary, Definitions, Concepts",
        "red":     "Purpose, Hypothesis, Aim, Conclusion",
        "green":   "Methodology",
        "blue":    "Results",
        "purple":  "Connections, Agree, Disagree",
        "magenta": "Future Implications & Research Ideas",
		"orange":  "Misc Thoughts & Info to Follow Up",
		"gray":    "References to Follow Up"
   }
-%}
{%-
    set zoteroColors = {
        "#ffd400": "yellow",
        "#ff6666": "red",
        "#5fb236": "green",
        "#2ea8e5": "blue",
        "#a28ae5": "purple",
        "#e56eee": "magenta",
        "#f19837": "orange",
        "#aaaaaa": "gray"
    }
-%}
{%-
    set zoteroStrings = {
        "sm": "sm",
        "df": "&df",
        "pr": "!pr",
        "am": "!am",
        "hp": "!hp",
        "cg": "!cg",
        "cb": "!cb",
        "sb": "$sb",
        "pt": "$pt",
        "in": "$in",
        "ms": "$ms",
        "sa": "$sa",
        "ot": "$ot",
        "rs": "@rs",
        "lc": "~lc",
        "la": "~la",
        "ld": "~ld",
        "pc": "~pc",
        "pa": "~pa",
        "pd": "~pd",
        "fi": ";fi",
        "ri": ";ri",
        "mt": "?mt",
        "fu": "?fu",
        "rf": "%rf"
    }
-%}
{#- handle | characters in zotero strings used in MD -#}
{%- macro formatCell(cellText) -%}
	{{ cellText | replace("|","❕")}}
{%- endmacro -%}

{#- Macros for handling annotations -#}
{%- macro formatAnnotation(annotation, calloutString) -%}
	{%- if annotation.imageRelativePath -%}
- {{calloutString}} ![[{{annotation.imageRelativePath}}]] [Zotero, p. {{annotation.pageLabel}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}&annotation={{annotation.id}}){% if annotation.hashTags %} {{annotation.hashTags}}{% endif %} ^{{annotation.id-}}
{% if annotation.comment.substring(2) | trim | length > 0 %}
	- {{annotation.comment.substring(2) | trim}}
{% else %}
{% endif -%}
	{%- elif annotation.comment.substring(2, 3) === "-" -%}
- {{calloutString}} {{annotation.annotatedText}} 
	{%- elif annotation.comment.substring(2, 3) === "+" %} {{annotation.annotatedText}} [Zotero, p. {{annotation.pageLabel}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}&annotation={{annotation.id}}){% if annotation.hashTags %} {{annotation.hashTags}}{% endif %} ^{{annotation.id-}}
{% if annotation.comment.substring(3) | trim | length > 0 %}
	- {{annotation.comment.substring(3) | trim}}
{% else %}
{% endif -%}
	{%- elif annotation.annotatedText -%}
- {{calloutString}} {{annotation.annotatedText}} [Zotero, p. {{annotation.pageLabel}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}&annotation={{annotation.id}}){% if annotation.hashTags %} {{annotation.hashTags}}{% endif %} ^{{annotation.id-}}
{% if annotation.comment.substring(2) | trim | length > 0 %}
	- {{annotation.comment.substring(2) | trim}}
{% else %}
{% endif -%}
	{%- endif -%}
{%- endmacro %}
# {{title}}

> [!info]+ Info [Zotero]({{desktopURI}}) | {%- for attachment in attachments | filterby("path", "endswith", ".pdf") %} [PDF](zotero://open-pdf/library/items/{{attachment.itemKey}}){%- endfor %}{% if DOI %} | [DOI:{{DOI}}](http://doi.org/{{DOI}}){% elif ISBN %} | ISBN: {{ISBN}}{% endif %}{%if url %} | [URL]({{url}}){% endif %}
> 
> **Bibiography:** {{bibliography}}
> 
> **Authors::** {% for a in creators %} [[{{a.firstName}} {{a.lastName}}]]{% if not loop.last %}, {% endif %}{% endfor %}
> 
> **Journal::** {{publicationTitle}}
> 
> **Ztags::**{% for t in tags %} [[{{t.tag}}]]{% if not loop.last %}, {% endif %}{% endfor %}
> 
> **First-page**: {% for annotation in annotations %}{% if loop.first %}{{annotation.pageLabel}}{% endif %}{% endfor %}

{%- if relations.length > 0 %}
{{ "" }}
> [!summary]+ Related Zotero items ({{ relations.length}}):  
>
> | title | Literature Note | Links |
> | --- | --- | --- |
{%- for r in relations %}
> | {{formatCell(r.title)}} | [[{{r.citekey}}]] | [Zotero]({{r.desktopURI}}){%- for rAttachment in r.attachments | filterby("path", "endswith", ".pdf") %} [PDF](zotero://open-pdf/library/items/{{rAttachment.itemKey}}){% endfor %} |
{%- endfor -%}
{{ "" }}
{%- endif %}

> [!tldr]+ Non-Zotero Links to This Note
> ```dataview
> TABLE tags as Tags
> FROM [[{{citekey}}]]
> WHERE !contains(file.path, "ZI LiteratureNotes")
> ```

> [!abstract]-{% if abstractNote %}
> {{abstractNote | striptags(true) | replace("BACKGROUND:","**BACKGROUND:**") | replace("CONCLUSIONS:","**CONCLUSIONS:**") | replace("CONCLUSION:","**CONCLUSION:**") | replace("DESIGN:", "**DESIGN:**") | replace("EXPOSURES:","**EXPOSURES:**") | replace("IMPORTANCE:","**IMPORTANCE:**") | replace("INTERVENTIONS:","**INTERVENTIONS:**") | replace("INTRODUCTION:","**INTRODUCTION:**") | replace("METHODS:","**METHODS:**") | replace("OBJECTIVE:", "**OBJECTIVE:**") | replace("PARTICIPANTS:","**PARTICIPANTS:**") | replace("PURPOSE:","**PURPOSE:**") | replace("RECOMMENDATIONS:","**RECOMMENDATIONS:**") | replace("RESULTS:","**RESULTS**:") | replace("SETTING:","**SETTING:**") | replace("CONCLUSIONS AND RELEVANCE:","**CONCLUSIONS AND RELEVANCE:**") | replace("DATA SOURCES:","**DATA SOURCES:**") | replace("DESIGN, SETTING, AND PARTICIPANTS:","**DESIGN, SETTING, AND PARTICIPANTS:**") | replace("ELIGIBILITY CRITERIA:","**ELIGIBILITY CRITERIA:**") | replace("ELIGIBILITY CRITERIA FOR SELECTING STUDIES:","**ELIGIBILITY CRITERIA FOR SELECTING STUDIES:**") | replace("MAIN OUTCOME MEASURES:","**MAIN OUTCOME MEASURES:**") | replace("MAIN OUTCOMES AND MEASURES:","**MAIN OUTCOMES AND MEASURES:**") | replace("PROCESS AND EVIDENCE SYNTHESIS:","**PROCESS AND EVIDENCE SYNTHESIS:**") | replace("RESEARCH DESIGN AND METHODS:","**RESEARCH DESIGN AND METHODS:**") | replace("STUDY DESIGN AND SETTING:","**STUDY DESIGN AND SETTING:**")}}{% endif %}

# Persistent Notes
{% persist "notes" %}


{% endpersist %}
# Annotations (Exported: [[{{exportDate | format("YYYY-MM-DD")}}]])
{% for colorHex, colorCategory in zoteroColors %}
## {{categoryHeading[colorCategory]}}

{% for beginString, calloutString in zoteroStrings %}
{%- for annotation in annotations | filterby("color", "startswith", colorHex) | filterby("comment", "startswith", beginString) %}
{%- if annotation -%}
{%- if annotation.comment.substring(0,2) === "sm" -%}
> [!summary] Summary
> {{annotation.comment.substring(2) | trim}}
> ^{{annotation.id}}
{% else -%}
{{formatAnnotation(annotation, calloutString)}}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{%- endfor -%}

Literature Note in Editing View:

This template was created with the aim of synthesizing a literature matrix from literature notes exported from Zotero Integration. As such, I wanted to have all annotated text, embedded images, and comments appear in a list format, as it is possible to TABLE query list content under sections (headers) using dataview. It was also important for me to have colored highlights be grouped together AND types of information highlighted sorted as well. For example, under the “Methodology” section, it would be important to have all information about subjects together, then information about the study protocol, then about instrumentation used, so on and so forth.

To achieve this, I used the List Callouts plugin (thank you @mgmeyers!) and, after using a for loop to go through the Zotero colors in the order I wanted, use a for loop to go through the callout characters used for List Callouts in the order I wanted as well! To make this work, I comment every annotation I make in Zotero with the callout characters, regardless if I need to make an actual comment or not. Example below:

With every string of callout characters having a length of 2, I then have the template substring the callout characters from the comment and then place them in the beginning of a image or text annotation with a special character appended to the beginning. I do this because I am admittedly quite lazy and don’t want to always be typing the special characters while annotating or even try to remember them. The section of the template I define the callout characters is near the beginning, “zoteroStrings”. List Callout plugin recognizes the characters and then decorates the literature note accordingly.

A novel thing I implemented in the template is the ability to append same-color annotations together, when there is a different-color annotation between them. To exemplify this, refer to the figure below:


As you can see, I started the magenta annotation right at the tail end of page 5, where it continues onto page 6. However, I also wanted to annotate the table at the end of page 5 with a blue highlight (for results). To append the annotations together, I place a “-” sign at the end of the callout characters for the annotation that is cutoff and don’t make any further comments. The next magenta annotation, I place a “+” sign at the end of the callout characters to append the annotated text to the previous magenta annotation, as well as comment whatever else I want. This is how it looks in the literature note:

So far, this works for cut-off annotations of the same color, with a different colored annotation between them and without any annotation between them. It does not work if the between annotation is the same color as the cut-off annotations. So in the above example, if I wanted to highlight the table with magenta, it would not work :frowning: . Only way I can see solving that is having all image annotations go last or go first by having callout characters for image comments be the same.

Thats pretty much it for the template. There was quite a bit of setting up to do in the List Callout plugin settings, which I am happy to post my settings if people are interested. I figure what people may be more interested in and adapt from this template is

  • the procedure of commenting every annotation in zotero with unqiue callout characters so that they can then be sorted in a manner you prefer
  • appending same colored cut-off annotations with a different colored annotation between them and without any annotation between them

If you have any questions feel free to holler. Thanks!

12 Likes

Thank you for this, it looks incredible! Is it possible to change the bibliography section of your code so that it instead spits out APA-style references?

1 Like

Do you mind sharing (I would prefer all, but if not, a few) Dataview queries you use with this template? I’m new to Dataview and I don’t yet understand all the features of Dataview and how I can structure my notes to be querri-able (if that’s even a word) by Dataview. Thanks for such detailed explanation of your template. I like it a lot. Using List Callouts instead of embedding the colors in HTML for sure make the md files much more readable.

Hey @aberjohn, thanks, glad you like it!

Yes, you can do that when you set up the import in Zotero Integration’s settings:

I have a note called Literature processing that gives me an overview of the following in my literature notes: tasks, annotations with certain tags, and the reading status and priority (although I also use the Projects plugin for that, following this guide).

Here’s what the Literature processing note looks like:

# Reading status

```dataview
TABLE 
without ID link(file.link, aliases) as Article,
priority as Priority,
status as Status,
date-created as Created
FROM "03 - Source notes/Zotero" AND -#MOC
SORT priority DESC
```

# Literature tasks

```dataview
task
from "03 - Source notes/Zotero" and #literature-note
group by meta(section).subpath
```

# Analysis annotations

```dataview
TABLE without ID link(file.link, aliases) as Article,
L.text AS "Sections"
FROM "03 - Source notes/Zotero"
FLATTEN file.lists AS L
WHERE contains(L.tags, "#analysis")
```

## Inspiration

```dataview
TABLE without ID link(file.link, aliases) as Article,
L.text AS "Sections"
FROM "03 - Source notes/Zotero"
FLATTEN file.lists AS L
WHERE contains(L.tags, "#inspiration")
```

and some screenshots:



You could also use this query to see all list items under a certain heading:

TABLE L.text AS "Bullets"
FROM "03 - Source notes/Zotero"
FLATTEN file.lists AS L
WHERE meta(L.section).subpath = "Research"

This will display all list items under a Research heading in the given path. There’s more options, like grouping by file as well, in the guide @jujumartini shared.

7 Likes

Yes, it’s possible. Look in my gist , lines 154 and 161 create a persistent block. Those will not be overwritten. I must add that having persistent blocks is both a blessing and a curse, it is a bit finecky.

Thank you! I don’t know how I missed this.

1 Like

Thank you! You have been very generous with your knowledge.

Hi @Qwxlea thank you for sharing this. I was wondering how I would change your template for my purposes of textbook annotation. I would like to make it so that it maintains your template format and the way it updates, but it would separate annotations/highlights by Chapter and sub heading designated by color highlight. It would go something like this:

  • Chapter 1 (yellow)

    • Subheading 1 (orange)
      • Other color highlights/comments
    • Subheading 2 (orange)
      • Other color highlights /comments
  • Chapter 2 (yellow)

    • Subheading 1 (orange)
      • Other color highlights /comments
    • Subheading 2 (orange)
      • Other color highlights /comments

And so on.

Thank you so much for any guidance you can give!

Although I have my Literature processing note, I would also be interested in seeing your Literature matrix table, @jujumartini.

1 Like

Would anyone kindly be willing to share a template for a vault?

Is there a video available of someone using this workflow?

What kind of template do you mean?

Hmm, I would’t really know how to implement that. It’s no problem to color chapter titles yellow, but it would then group all the chapter titles together.

You would need remove line 149 {% for color, colorCategorie in zoteroColors %} and the corresponding {% endfor -%} on line 165, from the template which is responsible for the grouping of the highlights.

Lines 11 to 19 are responsible for setting what the colors “mean”

Lines 149-165 are the loop that write out the annotations

The best way would be to just experiment. I must have imported zotero item a hundred times creating my template…

2 Likes

You can preview the import as you make changes to the template in the Data explorer.

However, I must admit that I also just delete and reimport the same item again and again…

1 Like

Something like this. I’m pretty new here but you’ve never heard of an obsidian vault template?

https://www.reddit.com/r/ObsidianMD/comments/wxrtup/how_can_i_check_out_some_really_cool_obsidian/?utm_source=share&utm_medium=android_app&utm_name=androidcss&utm_term=1&utm_content=share_button

https://www.reddit.com/r/ObsidianMD/comments/zophon/a_highly_opinionated_fully_functioning_obsidian/?utm_source=share&utm_medium=android_app&utm_name=androidcss&utm_term=1&utm_content=share_button

Hi everyone,

All of these template examples are great :). I’m currently working on my own version, although not as advanced.

I am currently stuck on one thing. I use Zotero’s “Related” tab to link papers together and have found a way to import those linked papers’ citekeys. This gives me a “Research Rabbit” style graph with automatic wiki-linking. My issue is that I’m not sure how to sort this list during import.

I’m trying to sort it by newest to older (by publication date) so that the most recent papers are listed first. So far all I have is:

> [!example]- Related Papers
> {% set relations = relations | sort(attribute"date”, reverse=true) %}{% for relate in relations %}
> - [[@{{relate.citekey}}]]{% endfor %}

This lists the citekeys of the related documents but does not sort it. I don’t come from a coding background so any help would be appreciated.

1 Like

I was asking for clarification because you seemed lost. This thread is for templates for a particular plugin, namely the Zotero Integration template.

You’ll want to go to this thread for example vaults, and check the links therein: List or repository of downloadable vaults?

Here’s a short video explaining the Zotero Integration workflow: Zotero Obsidian Integration - YouTube

Figured out a solution to my problem. Leaving my snippet for anyone who also uses linked papers in Zotero.

{%- macro DateCompare(a, b) -%}
{%- set dateA = a.date | moment('YYYY-MM-DD') -%}
{%-set dateB = b.date | moment('YYYY-MM-DD') -%}
{%- if dateA.isBefore(dateB) -%}
-1
{%- elif dateA.isAfter(dateB) -%}
1
{%- else -%}
0
{%- endif -%}
{%- endmacro -%}
{%- set relations_sorted = relations | sort(attribute='date', reverse=true, comparator=DateCompare) -%}
{% for relation in relations_sorted %}
- [[@{{ relation.citekey }}]]{% endfor %}

This code will list the citekeys for all linked papers in the “Related” tab in reverse chronological order.

7 Likes