-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBibTeX-CiteKey mod.js
74 lines (68 loc) · 3.81 KB
/
BibTeX-CiteKey mod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
"translatorID": "e35ec5c9-3166-471d-9267-1988fea4c351",
"label": "BibTeX-CiteKey",
"creator": "Jonathan Whiteley, based on work by Simon Kornblith and Richard Karnesky that was tweaked by Andrew Leifer",
"target": "bib",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 300,
"displayOptions": {
"exportCharset": "UTF-8",
"exportNotes": false,
"exportFileData": false
},
"inRepository": false,
"translatorType": 3,
"lastUpdated": "2011-12-23 11:00:00"
}
/* Quick Copy or Drag & Drop BibTeX-style cite commands, such as "\cite{key}" from
* This file is a wrapper around a modified version of the "BibTex" translator from Zotero 2.1.10,
* which uses available methods from that translator for extracting / generating a BibTeX-compatible cite key.
* This Translator uses a greatly simplified doExport() function to output only "\cite{key}" on export.
* By setting "Quick Copy" to use this translator (in Zotero 'Export' Preferences), you can
* Drag & Drop citations in the form of a Bibtex "\cite{key}" from Zotero.
* There are a few variables near the top that allow simple control over the formatting of this exported content,
* Such as which command to use (if any), and what to put between multiple items.
*
* Modified by: Jonathan Whiteley (jaw) jonathan [dot] whiteley [at] mail [dot] mcgill [dot] ca
* Original tweaks by: Andrew Leifer leifer ( at ) fas ( dot ) harvard (dot) edu
* Inspired by similar work by: Avram Lyon ajlyon [at] gmail.com
*/
/*TODO
* There should be a more elegant solution, ideally by calling methods from the default '.bib' import translator,
* then picking up / overriding the export method to produce the desired output.
*/
var citeCommand = "\\citep"; //jaw -- specify preferred cite command (escape the backslash).
var keySep = ", "; //jaw -- used to separate multiple keys within the command above.
/*jaw
* Multiple keys will be separated by `keySep`: default is a comma + space ", "
* The cite key(s) will be wrapped in curly braces {}, with `citeCommand` appended to the front.
* Leave this blank ("") if you just want the naked cite key(s) on Quick Copy.
*/
var bibtexTranslator = Zotero.loadTranslator("import");
bibtexTranslator.setTranslator("afea7040-40d1-40cc-915a-7b4e308d81d6"); // This is my modified version.
// The GUID for the 'official' BibTeX translator included in Zotero 2.1.10 is: 9cb70025-a888-4a29-a210-93ec52da40d4
// The GUID for my modified version of the BibTeX translator is: afea7040-40d1-40cc-915a-7b4e308d81d6
// NB: the BibTeX translator included in Zotero does not have an export{} property of objects available to other translators.
// Mine does, although this script seems to work fine if importing the built-in BibTeX translator anyway. *shrug*
function doExport() {
//Zotero.write("% BibTeX export generated by Zotero "+Zotero.Utilities.getVersion());
// to make sure the BOM gets ignored
var first = true;
var citekey = ""; //jaw: initialize here to keep it accessible outside the getTranslatorObject() callback
var citekeys = new Object();
var item;
if (citeCommand != "") Zotero.write(citeCommand+"{"); //jaw modified to use custom cite command
while(item = Zotero.nextItem()) {
// extract, or create a unique citation key
bibtexTranslator.getTranslatorObject( function (bibtex) {
citekey = bibtex.buildCiteKey(item, citekeys);
})
if (first == false) Zotero.write(keySep); //jaw: insert key separator before the next item
// write citation key
Zotero.write(citekey); //jaw
first = false;
// Deleted a whole bunch of stuff in here. --Andy
}
if (citeCommand != "") Zotero.write("}"); //jaw close custom cite command
}