Zotero Integration – Import Templates?

Handwriting in the PDF broke the import for me. I opened a bug report and also PR. Now its fixed in the latest version. I suggest updating the plugin. :slight_smile:

You also want to update to the latest Better-Bibtex plugin in Zotero. Sometimes annotation imports didn’t happen (e.g. when there was a HTML item and PDF at the Zotero item). This was also fixed this week.

If you want to have your handwriting imported, I suggest to open a ticket in the plugins github page.

1 Like

Hey Strudel,

Thanks for sharing your templates. I just integrated your section for extracting annotations into my template, but for some reason comments on annotations do not show up in my note - other than that it works smoothly. Do you have any idea what might be the issue?

Hi, I’ve been violently fighting with Obsidian and new Zotero 6 for several months, with not too much progress on my side. I am trying to accomplish exactly what you are describing here, meaning:

  • I highlight several sections on a PDF over Zotero 6 (in yellow, orange, etc)
  • Then I generate the ‘Annotations’ file from within Zotero by using the new functionality (before I was using zotfile with Zotero 5 and everything worked fine)
  • This Annotations file seems to collect my highlights, and even I can switch the annotation colors.
  • Then I have tried to follow step by step the tutorial on your blog and haven’t succeed. It is imposible for my template to capture the ‘highlights’ from the Annotations file.

One thing I noticed on your template, it is that it seems to access the template variable {annotations}, but after checking my ‘Annotations’ file generated from Zotero 6, I saw that this variable is not accessible at all. In fact when I use the ‘Zotero Integration: Data Explorer’ tool from the Obsidian Zotero Integration plugin , I cannot see the ‘annotations’ key anywhere. All my highlights appear collected under a single ‘markdownNotes’ key, with no subkeys at all. So it is impossible to loop through it. I need to add the following statement on my template in order to see them, but with no information on the colours (which I associate to a particular classification according to the color) :

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

What am I doing wrong here? why do you get a different result and the separate highlighted chunks? From what I understood you are using also Zotero 6 annotations and Zotero notes template. Could be this a problem of my own Zotero notes template? How do I access to it?. Everything grows utterly confusing with this Obsidian/Zotero workflow, as days pass by.

Thanks!

Did you highlight the pdf with the Zotero 6 reader? If you annotated those pdfs before with another tool, you might need to port those annotations with the File > Import annotations tool. I have also had the case where, even though I ported annotations they just never showed up. I ended up re-doing the annotations on Zotero 6 to get things to work.

Yes, just in case I have started from scratch, but nothing works, I summarize the steps below:

  1. I highlighted several paragraphs on a paper, directly using Zotero 6 pdf reader. For testing purpose I highlighted 3 paragrahs: one in yellow, another in purple, the third one in red
  2. From Zotero, I right click on the paper item and select ‘Add Note from Annotations’
  3. An ‘Annotations’ file is created in Zotero. I can see there the highlighted paragraphs, and toggle the ‘Show annotation colors’ (from the three dot menu)
  4. Back on Obsidian, I have followed both the @mgmeyers and @erazlogo approaches above: I have created the corresponding CSS snippets in Obsidian, and registered through the ‘Appearance’ settings in obsidian. Then I have created the Import Templates in both examples above (my templates are called ‘test_note_1’ and ‘test_note_2’), and registered in the Zotero Integration plugin settings.
  5. I go back to Obsidian, and from the command palette, i select ‘Zotero Integration test_note_1’, then the file with some of the extrated paper information is created in Obsidian…but none of the highlighted paragraphs appear there. Empty. Same when trying the second example from @erazlogo

Maybe I am missing something here, but I have reviewed the steps repeteadly, and nothing comes up.

Any suggestions? Thanks

Is this happening with all your pdfs or only with this particular one? In my case, I saw this happening only with this one pdf that required me re-download the pdf and re-annotate it. My advice os that you try using Zotero Integration’s data explorer on a different pdf to determine if this is a general issue or not.

Hi, I have tried on a fresh pdf paper, still same issue. I better explain it with some screenshots for clarity:

  1. From Zotero 6 PDF reader, I highlight some sentences (in this case I use a ‘red’ highlight, and the standard ‘yellow’):

  1. Then, on that particular paper, I right-click and select ‘Add note from Annotations’.

  2. This generates an ‘Annotations’ file which contains my highlighted chunks. Up to here, all good:

Screenshot 2022-10-30 at 16.09.39

  1. Now it is when things start going strange. If I set up any of the template examples above (@erazlogo or @mgmeyers ), none of these highlighted chunks appear on the generated Obsidian note. For example, using @mgmeyers template, I get everything nicely formatted…except the highlighted chunks. That section appears completely empty:

  1. I saw that both @mgmeyers and @erazlogo make use of the variable “{annotations}” in their templates, and then loop through it, which apparently retrieves each ‘annotation’ (I understand they refer also to ‘highlighted’ paragraphs, apart from the written notes that one can add to the PDF):

{%- for annotation in annotations %}
{% if annotation.color !== “#ffd400” %}

  1. However, that variable doesn’t appear to be exposed on my Zotero generated ‘Annotations’ file. In fact, I tried another template with Zotero Integration in which ‘highlighted’ chunks are retrieved as a whole using an esoteric and mysterious variable called ‘markdownNotes’…which apparently stores ALL the highlighted chunks as a SINGLE big note:

Notes

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

  1. Using that variable…yes, highlights are somehow extracted as you can see below, but with no color information and no mechanism so to loop through each of them and detect under which color were they highlighted.

  1. Basically this is the problem. I ignore how people is doing so to access the highlights using that ‘annotations’ variable. In my case that variable seems non-existent. I only can access that strange ‘markdownNotes’ variable, which stores everything as a big chunk. In fact, using Zotero Integration’s ‘Data Explorer’ tool…you can see exactly how things are organized inside that ‘markdownNotes’ from Zotero Annotations generated file…basically all the highlights dumped there alltogether:

Screenshot 2022-10-30 at 16.42.02

Sorry for the lengthly post. but I wanted to give as much details as possible.

Cheers

1 Like

Thanks for the screenshots. A few things I’d like to point out:

  1. With Zotero 6, you do not need to export annotations by right-clicking and selecting Add note from annotations. You just need to highlight, write annotations, etc, and that’s it. I don’t know if maybe this is part of the problem, but maybe you can try not exporting annotations and see if that works.
  2. The annotations variable in the data explorer is shown above the screenshot you showed on step 8. It is usually at the top as variables are organized alphabetically. Here is a screenshot of mine. If you can’t see that variable, I think there is something more fundamental not working with the plugin that maybe a reinstall can help fixing.
  3. You can try this piece of my template in the section where you want your annotations to come and see if that helps
{% persist "annotations" %}
{% for annotation in annotations %}{% if annotation.comment %}
{{annotation.comment}}{% endif %} 
{% if annotation.annotatedText %}> {{annotation.annotatedText}}[{{citationKey}}:{{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}){% endif %}
{%- if annot.imageRelativePath %} > ![[{{annot.imageRelativePath}}]] {%- endif %} {%- if annot.ocrText %} > {{annot.ocrText}} {%- endif %}
{% endfor %}{% endpersist %}
2 Likes

Many thanks!! I followed your suggestions, so I skipped the export notes step in Zotero, and re-installed the Obsidian plugin, then added that little snippet of yours and finally got the highlights! I knew I was missing the point somewhere in my workflow , got maybe a bit confused with some many posts about the matter, so many thanks again for point it out.

2 Likes

Many thanks!! I followed your suggestions, so I skipped the export notes step in Zotero, and re-installed the Obsidian plugin, then added that little snippet of yours and finally got the highlights! I knew I was missing the point somewhere in my workflow , got maybe a bit confused with some many posts about the matter, so many thanks again for point it out.

3 Likes

I am a complete newbie but have spent the better part of an hour working on this to no avail from mgmeyers’ template. Below are screenshots of the beginning of the code/the output for a zotero paper I imported. Does this look like a CSS problem or a copy/paste problem? (Sorry for such a seemingly dumb question but I’m hoping I’m just missing something simple because I don’t know what I’m doing)


l

Hi,

On the second screenshot, I cannot see the full output, however that bit looks ok…but I think you need to turn on the ‘Reading view’ so to see the final formatting, as now you are seeing the ‘Editing mode’ (that little icon on the top right of the tab with the imported paper information). In my case, the import looks like this on the ‘Editing mode’:

And when I switch the ‘Reading view mode’, I get the visual formatting as per the CSS:

I am using my own template, mixing bits and pieces of both @mgmeyers and @erazlogo templates and adapted for my own workflow

2 Likes

Looks as expected, you’re just in source view.

1 Like

Ohhh, you’re right. I had a logic error in there (forgot to close an if-statement after the image part) but never corrected it in the Gist.
The annotation part should be something like:

{% for annotation in annotations %}{% if annotation.annotatedText %}
> <span style="color: {{annotation.color}};">&#9632;</span> {{annotation.annotatedText}} ([p. {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}&annotation={{annotation.id}}))
{% elif  annotation.imageRelativePath %}
> <span style="color: {{annotation.color}};">&#9632;</span> ![[{{annotation.imageRelativePath}}]]
{%- endif %}
{% if annotation.comment %}- {{annotation.comment}}
{% endif %}{% endfor %}{% endif -%}

great thank you! I don’t know why I didn’t even think to try that.

Hi. Thank everyone for sharing their template. Recently I used @mgmeyers template for my workflow and it ran smoothly, except the annotation’s color. I tried reinstall the plugin and reapply the css snippet, but nothing seems to work.
Any suggestions?
Thanks

Could you share your raw template?

Try again (I typed some nonsense before). I think the colors in that template don’t match the current Zotero palette. I don’t use mgmeyers CSS anymore for this reason. But by reading this CSS snippet which works with a bog-standard install of Zotero 6.0.17 on MacOS, you should be able to work out what to change in the template and CSS:

/* Yellow */
.research-note .callout[data-callout-metadata="#ffd400"] {
  --callout-color: 255, 204, 0;
}

/* Red */
.research-note .callout[data-callout-metadata="#ff6666"] {
  --callout-color: 255, 59, 48;
}

/* Green */
.research-note .callout[data-callout-metadata="#5fb236"] {
  --callout-color: 40, 205, 65;
}

/* Blue */
.research-note .callout[data-callout-metadata="#2ea8e5"] {
  --callout-color: 0, 122, 255;
}

/* Purple */
.research-note .callout[data-callout-metadata="#a28ae5"] {
  --callout-color: 125, 84, 222;
}

(my snippet is from another template, but I think substituting “literature-note” for “research-note” is the only difference.

By editing the colorValueToName macro’s case statements you’ll fix the wording of the callout. By tweaking the literatureNote.css file’s data-callout-metadata fields you’ll get better colors for the callout.

2 Likes

You fixed it. I knew something wrong with the CSS snippet but couldn’t figure out. Thank you and have a great day!

1 Like

I followed @erazlogo template and all annotations seem to render correctly, except the yellow annotations which don’t show up as a callout.

You can see a screenshot here. In the template, yellow (#ffd400) seems not to be included, but I had no luck including it – removing that if statement messes up the render entirely.

I also tried just changing the color name to something unused (e.g. #ffd405) but that also messed up the render.