Insert a "XXXX et al." citation.
Before everything, thank you so much for this wonderful plugin ! It's a joy to use !
What is proposed
To make it even more flexible, I'd love to be able to add a proper XXXX *et al.*, YYYY citation type in Markdown format. This is in the particular case of wanting your markdown notes to be properly formatted without being parsed by pandoc.
In Markdown, this would look like:
As it is said by [Test *et al.*, 2018](link/to/paper), blablabla
Rendered, it would look like:
As it is said by Test et al., 2018, blablabla
As of today, the plugin is already almost capable of doing this, using an extremely convoluted handlebars sentence:
[{{#each entry.author}}{{#if @first}}{{#if this.family}}{{this.family}}{{#unless @last}} *et al.*{{/unless}}{{else}}{{../authorString}}{{/if}}{{/if}}{{/each}}, {{#if year}}{{year}}{{else}}no date{{/if}}]({{zoteroSelectURI}})
What the sentence does is to:
- Display the family name of the first author (if it has one)
- Add "et al." next to it if this first author if it is not the last author of the list of authors (if not, write nothing since there's no other authors)
- If the author has no family name or given name (which happens when it's an organization with only one name), I can't get the name of the author via
this.givenorthis.family; so, the sentence writes the authorString in full (not ideal) - If there is a year, add it.
- As a link, add the zotero select URI (my personal preference; can be replaced by the DOI URL via
https://doi.org/{{DOI}}or other URL)
It works pretty well, but it seems a bit complex for most users. It took me a lot of time myself 😄 !
What is needed
Ideally, I imagine that allowing the use of a csl file to custom the appearance of this citation would be ideal; but it would require a lot of work.
Using this type of long handlebar syntax could be good, but needs to be explained to the users properly; maybe this example could be given ?
If it is given, it could be nice to think of a way to replace the authorString in case the name of the author cannot be gathered via this.given or this.family. If you have a pointer for that, I'd be much obliged.
Thanks again for your work !
This sounds really good, after wandering around I've come to your solution and as non-TS guy, it saved my day, thanks @Klemet!
I'm not super familiar with handlebars, would it be possible to tweak your sentence to add et al. if there are more than two authors, rather than more than one?
So:
Brand and Hoth, 2017 instead of Brand et al., 2017
But still Brand et al., 2017 for Brand, Hoth, and Smith, 2017`?
I wanted to do that, @baileymh ; however, I couldn't find a term in the handlebar syntax that gave the number of authors in the list of authors.
The only thing that I could test for was to see if the first author is also the last of the list; if that's the case, that means that there's only one author. If not, the sentence adds "et al.".
Gotcha. I tried looking through a bit but couldn't see anything, wasn't sure if there was just more that I didn't know about.
Either way, thanks a lot for the work above, gets me most of the way to what I want, much appreciated!
EDIT I had a few misconceptions, so I updated the post.
I was trying to use this for the note creation template, however in a slightly changed form, so that articles that came out in the same year have the year appended by a letter, as is the case in zotero. I don't speak Handlebars however.
{{#each entry.author}}{{#if @first}}{{#if this.family}}{{this.family}}{{#unless @last}} et al.{{/unless}}{{else}}{{../authorString}}{{/if}}{{/if}}{{/each}} ({{#if year}}{{year}}{{#if isNaN (Number entry.id.[entry.id.length - 1])}}{{entry.id.[entry.id.length - 1]}}{{/if}}{{else}}no date{{/if}})
I wanted to base the syntax on these two posts: one, two. However, I guess I would need to use helpers for that, but I don't know how. It already doesn't work if I just try to print entry.id.length - 1.
Hi all, I'm impressed by your Handlebars solutions here! CSL-driven automatic rendering of inline citations will be coming in the next major release. Stay tuned!
See also more creative JS solutions in #53 .
@hans
Hi all, I'm impressed by your Handlebars solutions here! CSL-driven automatic rendering of inline citations will be coming in the next major release. Stay tuned!
Hi @hans, is the new major update of the citation plugin still in the works? I would really love for this functionality to work.