ZotFile: my user-defined wildcard for bibtex-key-type title abbreviation

I recently needed to bring some order to the file names of many of the PDF files attached to my Zotero database, and managed to find ZotFile. My plan was to obtain file names which were (almost) the same as the BibTeX or BibLaTeX keys generated by Zotero, but ZotFile could not do this...

...out of the box.

Initially, I was slightly intimidated by putting Javascript code into a
custom JSON structure. I have never hacked Javascript before, and this zotfile.wildcards.user option was labeled as being "for advanced users" and "without any error checking". Then I realised that the Zotero code responsible for creating the BibTeX and BibLaTeX keys was also Javascript, so the chances were high I could get away with some spirited copy and paste.

...and I did! Here follows a fresh copy from my zotfile.wildcards.user:

{"1":{"default":{"field":"title","operations":[{"function":"toLowerCase"},{"function":"replace","regex":"\\b(a|an|the|some|from|on|in|to|of|do|with|der|die|das|ein|eine|einer|eines|einem|einen|un|une|la|le|l\\'|el|las|los|al|uno|una|unos|unas|de|des|del|d\\')(\\s+|\\b)","replacement":""},{"function":"exec","regex":"([\\w-]+)","group":1}]}}}

Indented with the help of http://pro.jsonlint.com, the JSON validator recommended in the documentation for ZotFile, the same code looks like this:

{
"1": {
"default": {
"field": "title",
"operations": [
{
"function": "toLowerCase"
},
{
"function": "replace",
"regex": "\\b(a|an|the|some|from|on|in|to|of|do|with|der|die|das|ein|eine|einer|eines|einem|einen|un|une|la|le|l\\'|el|las|los|al|uno|una|unos|unas|de|des|del|d\\')(\\s+|\\b)",
"replacement": ""
},
{
"function": "exec",
"regex": "([\\w-]+)",
"group": 1
}
]
}
}
}

I used this together with the ZotFile renaming format
{%a|%d_}{%1_}{%y}
which produced file names close enough to the BibTeX/BibLaTeX keys produced by Zotero.

I hope someone will find this useful...

This is an old discussion that has not been active in a long time. Before commenting here, you should strongly consider starting a new discussion instead. If you think the content of this discussion is still relevant, you can link to it from your new discussion.

Sign In or Register to comment.