To order fields with Better Bibtex
Hi!
I'm trying to use Better Bibtex for ordering fields books. :)
But my script doesn't work how I want.
I started from the script on this page https://retorque.re/zotero-better-bibtex/exporting/scripting/#custom-field-order
if (Translator.BetterBibTeX && item.itemType === 'book') {}
const order = ['title'];
if (item.shorttitle) { order.push('shorttitle'); }
if (item.keywords) { order.push('keywords'); }
for (const field of order.concat(Object.keys(reference.has).filter(other => !order.includes(other)))) {
const value = reference.has[field]
delete reference.has[field]
reference.has[field] = value
}
And I obtain this output :
@book{eisenbergSVGProductionOrientee2003,
title = {{SVG : Production orient{\'e}e XML de graphiques vectoriels}},
publisher = {{O'Reilly {\'E}ditions}},
language = {fr-FR},
...
}
As you can see the order's fields isn't title, shorttitle and keywords,
but title, publisher and language.
Finally, I don't understand why! Thanks for your help.
I'm trying to use Better Bibtex for ordering fields books. :)
But my script doesn't work how I want.
I started from the script on this page https://retorque.re/zotero-better-bibtex/exporting/scripting/#custom-field-order
if (Translator.BetterBibTeX && item.itemType === 'book') {}
const order = ['title'];
if (item.shorttitle) { order.push('shorttitle'); }
if (item.keywords) { order.push('keywords'); }
for (const field of order.concat(Object.keys(reference.has).filter(other => !order.includes(other)))) {
const value = reference.has[field]
delete reference.has[field]
reference.has[field] = value
}
And I obtain this output :
@book{eisenbergSVGProductionOrientee2003,
title = {{SVG : Production orient{\'e}e XML de graphiques vectoriels}},
publisher = {{O'Reilly {\'E}ditions}},
language = {fr-FR},
...
}
As you can see the order's fields isn't title, shorttitle and keywords,
but title, publisher and language.
Finally, I don't understand why! Thanks for your help.
if (Translator.BetterBibTeX && item.itemType === 'book') {
const order = ['title', 'shorttitle', 'keywords'].filter(field => field in reference.has)
for (const field of order.concat(Object.keys(reference.has).filter(other => !order.includes(other)))) {
const value = reference.has[field]
delete reference.has[field]
reference.has[field] = value
}
}
(also, I do most of my support on github. I do not come here frequently)
I prefer because I think it's more easy for changing the content of the array.
// Document type book.
// Sort fields.
// If a field is not in this list, it will show up at after the ordered fields.
if (Translator.BetterBibTeX && item.itemType === 'book') {
// the bib(la)tex fields are ordered according to this array.
const order = ['title', 'shorttitle', 'keywords', 'author', 'collaborator', 'translator', 'editor', 'publisher', 'address', 'edition', 'month', 'year', 'language', 'langId', 'isbn', 'copyright'];
for (const field of order.concat(Object.keys(reference.has).filter(other => !order.includes(other)))) {
if (reference.has[field]) {
const value = reference.has[field]
delete reference.has[field]
reference.has[field] = value
}
}
}
Thanks.