hans / obsidian-citation-plugin

Obsidian plugin which integrates your academic reference manager with the Obsidian editor. Search your references from within Obsidian and automatically create and reference literature notes for papers and books.
MIT License
1.12k stars 83 forks source link

[Bug] data.entry.fields does not seem to work for list variables #152

Open Elaws opened 2 years ago

Elaws commented 2 years ago

Hello,

When defining a custom variable with multiple values (e.g. see fileRelative below), it seems they can't be accessed using data.entry.fields :

@book{adlerStudyOrchestration2002,
  title = {The Study of Orchestration},
  author = {Adler, Samuel},
  date = {2002},
  edition = {3rd ed},
  publisher = {{W.W. Norton}},
  location = {{New York}},
  isbn = {978-0-393-97572-7},
  pagetotal = {839},
  keywords = {1,music theory,orchestration},
  file = {D\:\\Software\\Zotero\\storage\\DWDDHZU3\\Adler - 2002 - The study of orchestration.pdf;D\:\\Software\\Zotero\\storage\\EB6ADAID\\Orchestration_Adler.pdf;D\:\\Software\\Zotero\\storage\\J6FYUPXG\\instrument_ranges.pdf;D\:\\Software\\Zotero\\storage\\KVJWM5SY\\instrument_names.pdf},
  fileRelative = {Zotero\\storage\\DWDDHZU3\\Adler - 2002 - The study of orchestration.pdf;Zotero\\storage\\EB6ADAID\\Orchestration_Adler.pdf;Zotero\\storage\\J6FYUPXG\\instrument_ranges.pdf;Zotero\\storage\\KVJWM5SY\\instrument_names.pdf}
}

When using {{entry.data.fields.fileRelative.[0]}} or {{entry.data.fields.fileRelative.[1]}} in Citations' template, nothing appears in the note created (no error log in Obsidian console either).

I would appreciate any help you can provide, thanks !

epelaez1 commented 2 years ago

Hi @Elaws, idk why but the plugin converts the custom variables to lower case. So, in your case, fileRelative would be filerelative.

I hope it helps.

Seraphli commented 2 years ago

Hi @Elaws @epelaez1 , I want to ask some questions. How to export the fileRelative field? I only get the file field.

And I tried {{entry.data.fields.file.[0]}}, it gives the whole list, instead of the first element. What is the right syntax? How can I fix it? BTW, I tried {{entry.data.fields.file[0]}} and it didn't work. And there might be another question. How can I export only the file name, not the file path?

Elaws commented 1 year ago

Thanks a lot @epelaez1, now I have something ! However, the formatting is completely wrong :

Zotero storage DWDDHZU3 Adler - 2002 - The study of orchestration.pdf;Zotero storage EB6ADAID OrchestrationAdler.pdf;Zotero storage J6FYUPXG instrumentranges.pdf;Zotero storage KVJWM5SY instrumentₙames.pdf

instead of :

Zotero\storage\DWDDHZU3\Adler - 2002 - The study of orchestration.pdf Zotero\storage\EB6ADAID\Orchestration_Adler.pdf

There seems to be a problem with some escape characters, when using {{entry.data.fields.filerelative.[0]}}.

@Seraphli :

How to export the fileRelative field? I only get the file field.

It is something I added manually in my BetterBibLaTeX export, with a postscript. I think this comment should help you. But as mentioned above, I have a formatting issue for now.

And I tried {{entry.data.fields.file.[0]}}, it gives the whole list, instead of the first element. What is the right syntax? How can I fix it?

The proper syntax is {{entry.files.[0]}}.

How can I export only the file name, not the file path?

I don't understand, could you please elaborate ? The filename can be retrieved with {{title}}.


But honestly, I feel that all of this is very convoluted, it should be much more streamlined. I'm looking at Zotero v6 and Zotero iOS app, maybe it brings more elegant solutions for that. I also just discovered another Zotero plugin for Obsidian, maybe easier to use.

Seraphli commented 1 year ago

@Elaws I have created an issue about the escape behavior before. If you want to temporarily fix this issue, you can check out my comments. https://github.com/hans/obsidian-citation-plugin/issues/202

Elaws commented 1 year ago

@Seraphli : Thanks for your reply.

Because when I change the postscript to replace the eprint key instead of creating a new key, the template works fine.

Could you please add details to what you modified in the postscript to make it work ?

Seraphli commented 1 year ago

@Elaws Check out this post. https://github.com/retorquere/zotero-better-bibtex/discussions/2311 I simply find out if you replace the key with eprint and that will work. I think it is because the key eprint is defined in the abstract data class.

if (Translator.BetterTeX && item.attachments) {
  var filename = item.attachments
    .filter(att => att.localPath && att.localPath.match(/\.pdf$/i))
    .map(att => att.localPath.replace(/.*[\\/]/, ''))
    .find(att => att)

  tex.add({ name: 'eprint', value: filename, enc: 'raw' })
}