Closed daaaaaaaaaniel closed 2 years ago
Line 6 above is missing a .has
, but this should work too:
if (Translator.BetterTeX) {
function split(title) {
const m = (title || '').match(/(.+?)([?]"|[?:;])(.*)/)
return m ? { title: m[1], sub: m[2].trim() } : null
}
let title
if (title = split(reference.has.booktitle && reference.has.booktitle.value)) {
reference.add({ name: 'booktitle', value: title.title })
reference.add({ name: 'booksubtitle', value: title.sub })
}
// Authors who use parentesis in their titles break all sorts of conventions. Don't even bother seriously parsing.
if ((title = split(reference.has.title && reference.has.title.value)) && !title.title.match(/\((?!.*\))/)) {
reference.add({ name: 'title', value: title.title })
reference.add({ name: 'subtitle', value: title.sub })
}
}
@retorquere Awesome!! I made one minor fix to your suggestion.
Line 4 should use m[3]
instead of m[2]
. Your version sets the (book)subtitle to nothing more than a semicolon for most items. Furthermore, I tweaked the title value on that same line so that titles ending in "?" retain the "?". With these adjustments, line 4 reads:
return m ? { title: m[1] + m[2].replace(RegExp("\:"), "").trim(), sub: m[3].trim() } : null
And it seems to run perfectly! Thank you!!!
Thanks for the feedback; there's no way you could have known, but @retorquere prefers to keep bugreports/enhancements open as a reminder to merge the changes into a new release.
Support log:
NPJ6NYB6-refs-euc
Zotero does not have a separate field for subtitles. Space-semicolon-space has been the recommended delimiter in the past, as discussed in other threads on the zotero forums[1]. I've tried addressing this missing feature in various ways ie.
container-title-short:
and/ortex.subtitle:
in the Extras field. But using a postscript to automate it seems like the least laborious route.A similar question was asked here over a year ago, and the postscript below was provided as the solution. I tested it today and confirmed that it works without issue for splitting a subtitle from a title.
Originally posted by @retorquere in https://github.com/retorquere/zotero-better-bibtex/issues/1759#issuecomment-798949707
However, I tried tweaking it slightly so that it would operate in the same manner on the
booktitle
container field for book sections in addition to the section title.I can't figure out how to adapt this postscript so that it works for titles and booktitles.