Closed Elaws closed 2 years ago
I don't think Zotero has documented this anywhere, but if you export an item to BetterBibTeX JSON
you can see exactly what is available to the postscript.
It is always OK to ask if anything is unclear.
Thank you for your reply ! This answers my question.
Zotero IDs of attachments are not exported to the BetterBibTex JSON
, so I will just try to extract it from the attachment path.
Have a great day ;)
It'd be easy to add the itemkey.
To add the Zotero IDs of attachments you meant ?
The use case would be for each attachment to get the "attachmentKey/attachmentName" path so that we have a cross-platform link, in case where you are syncing Zotero's storage folder on multiple platforms.
I can't think of an application of "attachmentKey" alone, but since "attachmentName" is available in the BetterBibTex JSON
(title
), "attachmentKey/attachmentName" would then obviously be achievable.
attachments and items are both mostly just "items" to Zotero, they both have an itemKey
Well, I had no luck so far, there's something I must not understand.
So in order to keep only storage\attachmentKey\documentName
I added the following postscript :
if (Translator.BetterBibLaTeX && item.attachments) {
reference.add({ name: 'fileRelative', value: item.attachments.filter(a => a.defaultPath).replace(/.+?(?=Zotero\\)/, ''), enc: 'attachments' })
}
But fileRelative
is unfortunately not added to BibLaTeX export. I'm not against a little help at this point !
Also, attachments in my BetterBibTeX JSON
are as follow :
"attachments": [
{
"dateAdded": "2022-01-06T18:22:33Z",
"dateModified": "2022-01-06T18:22:33Z",
"itemType": "attachment",
"path": "D:\\Software\\Zotero\\storage\\K24ANA76\\document.pdf",
"relations": [],
"tags": [],
"title": "document.pdf",
"uri": "http://zotero.org/users/8362141/items/K24ANA76"
}
For now :
relativePath
is added only if the value
in my postscript is item.attachments.filter(a => a.defaultPath)
: as soon as I add the regex, it disappears.a.path
instead of a.defaultPath
, nothing appears, which is odd because the Better BibTeX JSON
has a path
field in attachments
, not defaultPath
field. enc:
does not seem documented anywhere ?Thanks a lot !
if (Translator.BetterBibLaTeX && item.attachments) {
reference.add({ name: 'fileRelative', value: item.attachments.filter(a => a.localPath).map(a => ({ ...a, localPath: a.localPath.replace(/.+?(?=Zotero\\)/i, '') })), enc: 'attachments' })
}
For now :
* `relativePath` is added only if the `value` in my postscript is `item.attachments.filter(a => a.defaultPath)` : as soon as I add the regex, it disappears.
That's because the .filter
leaves an array of attachment objects, not the path.
* if I use `a.path` instead of `a.defaultPath`, nothing appears, which is odd because the `Better BibTeX JSON` has a `path` field in `attachments`, not `defaultPath` field.
Yeah, my bad. The BBT JSON format is mostly what the postscript gets. That's mostly but not entirely true for attachments -- the postscripts have mostly been used for single-value fields, and tags. defaultPath
is available if you are exporting the attachments. localPath
is always present for file attachments and it the actual path into the storage directory. The .filter
is still necessary because non-file attachments won't have localPath
.
* `enc:` does not seem documented anywhere ?
Same reason: the postscripts have been mostly used for single-value fields, and then you don't really need the enc
parameter. It defaults to latex
, and BBT knows which fields are the other types and selects the appropriate one automatically, so in most cases, you don't need enc
. The valid values are:
raw
: pass-throughurl
: url encoding, which is close to verbatim
but subtly differentverbatim
: verbatim-mode latexcreators
: never called directly, must use addCreators
literal
: literal encoding, which is close to verbatim
but subtly differentlatex
: the format we all know and love (although that love is complicated)tags
: latex
encoding with removal of some invalid characters for the keywords
field, with commas between the tagsattachments
: only used for item.attachments
, adds Jabref-specific metadata if that is on in the prefs.Thanks a lot for the added details and your help for the script : it's perfect :)
Comments on a closed issue reopen the issue ;) You're welcome.
Hello,
Scripting section of Better BibTeX documentation mentions the following :
However, I can't seem to find anywhere a complete description of the available fields. For exemple, a message in Zotero forum shows the following example :
But
item.itemKey
does not seem mentionned anywhere else (I've also looked in extra fields section of Better BibTeX documentation and Zotero Item Types and Fields of Zotero official documentation).Hence the following questions :
item
fields available in Better BibTeX API described somewhere ?storage/ZoteroID/documentName.pdf
part of its path : are thereitem
fields that would help for that or do I need to filter the full path using regex to get these values ?Thanks for taking time to read this, and I'm sorry if this has been answered before, I really tried to search before asking but may have missed it !