inukshuk / jekyll-scholar

jekyll extensions for the blogging scholar
MIT License
1.13k stars 101 forks source link

natbib-style textual citations #238

Open mcnesium opened 6 years ago

mcnesium commented 6 years ago

Is there a citation variant like natbibs \citet that renders the author's names outside of the parentheses:

Example et al. (2016)

I am aware of --suppress_author but that requires to write the name of the author separately. If this is not implemented yet, I can try to contribute if someone can point me to where that needs to be done.

inukshuk commented 6 years ago

I'd search through the available author-date styles (hover over a style to see the preview) and pick one that looks like natbib; or pick one that comes close and adjust the style accordingly.

(Suppressing the author is mostly intended for cases where you mentioned the authors already in the natural flow of the sentence.)

mcnesium commented 6 years ago

This is not about the bibliography style, but for the in-text-citations using {% cite example %}.

I am trying to find a switch from the default citation style (Author, Year) style to a textual citation like Author (Year) which from my understanding is independent of the general CSL style.

Maybe there can be something like -A for suppressing the author, like -T for textual citations.

inukshuk commented 6 years ago

CSL styles format both bibliography and the in-text-citation (the latter is what the cite command renders). You can very easily adapt a style that, e.g. renders as (Author Year) to render as Author (Year) (you just need to change the prefix/suffix that render the parentheses). You save that style, e.g., as natbib with your other CSL styles and then you can always use it like {% cite example -s natbib %} (or set it as the default style if you always want that format).

mcnesium commented 6 years ago

ok let's get back to this (sorry for long timeout).

What I am trying to achieve is not a certain citation style imho, but as you already stated a different way of citing a reference. Let me give you some examples:

The default way is to be used like this (this would be equivalent to natbib's \citep:

CSL styles format both bibliography and the in-text-citation {% cite inukshuk2018 %}

CSL styles format both bibliography and the in-text-citation (inukshuk, 2018)

Your suggestion using --suppress-author would look like this:

In his last post, {% cite inukshuk2018 --suppress-author %} wrote about CSL styles

In his last post, (2018) wrote about CSL styles

But what I want to achieve, is the equivalent to natbib's \citet that would look like this:

In his last post, inukshuk (2018) wrote about CSL styles.

which is not a different citation style but a textual instead of parenthetical citation (natbib doc). It does render the author's name and links it, but it is a real part of the sencence.

This mode is either missing here or I have not found how to use it. So I would like to contribute this, if I was pointed to where and how this must be done.

inukshuk commented 6 years ago

Like I said, --suppress-author is intended for exactly this case: the author has been mentioned already, so you want to suppress it. I don't see how you could generically solve printing the author name in the cite command in all possible cases; your example covers just the case where the authors go right before the reference:

 In his last post, Inukshuk (2018) mentioned, that ...

But what about if the style guide wants you to write it like this:

 In his last post, Inukshuk mentions, that ... (2018).

There are many other possible cases and I don't see how you could possible cover them all. That's the intention behind suppress author after all: the names have been cited already (the style does not know how or where) so don't print them again.

Maybe you say that does not matter to you, because you are only interested in this one case: print the authors (formatted as the style would normally) followed by the full reference, but with authors suppressed. That's fair, but if this is the goal, then, like I said above, I would create a variant of the style you're using that prints the author first and then everything else. Then you can use the normal cite command, using your adjusted style whenever you would use citet. For example, if you're using apa.csl you make a copy apa-citet.csl which pulls the names node out of the parens and then use {% cite --style apa %} and {% cite --style apa-citet %} in your text.

Alternatively, it would be useful to have the reverse of --suppress-author: i.e., render the reference, but only the authors and nothing else. If we had such a command it would be easy to provide a citet command which simply calls cite --only-authors followed by cite --suppress-authors. This could be accomplished rather easily now that I think about it:

  1. Fetch the style's citation rendering node
  2. Search for the first (normally there should be only one) names node with variable authors
  3. Render just this node

The most difficult part is probably step 2, because for most styles you will have to expand macros as you search.

mcnesium commented 6 years ago

Looks like it depends on how you are used to do citations. I have never seen citations, where the list auf authors and the year are separated across the sencence, like shown your second example.

It seems somehow inconvenient to me, for example if you switch citation styles along the way. Say, there are multiple authors and you wish to switch from "Alice, Bob and Eve" to just "Alice et al.", using --suppress-author and then writing the names by hand somewhere in the sencence would mean to change every occurence by hand as well, while using some citet-style method would change all of them automatically.

Your proposal to use an equivalent --only-authors would cause the resulting markup to have two links dealing with one reference, which is also pretty unusual imho:

In his last post, Inukshuk mentions, that ... (2018).

Another advantage of my citet-style proposal is that you don't have to take care of the correct spelling of the author's name(s), because you only need to write down the bibtex slug.

Referring to your apa-citet.csl proposal, this would mean for every citation style there would be one copy needed, just to switch the place of the parentheses. This is of course an option, but again not a very convenient one, imho.

So again I would like to argue, that a switch to put the opening parenthesis from the beginning of the citation to after the however styled list of authors would be useful.

inukshuk commented 6 years ago

--only-authors could easily disable automatic linking.

So again I would like to argue, that a switch to put the opening parenthesis from the beginning of the citation to after the however styled list of authors would be useful.

Look, I don't know how you expect to solve this in a generic way. You keep talking about parenthesis, for example, but there is no guarantee a style even uses parenthesis. What you're suggesting, it seems to me, would have to involve: rendering the citation, suppressing any rendering of the authors (handling all cases where author names get substituted by the style), then rendering the authors (again, rendering them just as if the style had rendered them, taking into account, substitution, disambiguation, et-al shortening, etc.) and prefixing them to the style. If you're interested in implementing something like this, be my guest. I would suggest, however, to either a) type the names by hand and use --suppress-author or b) create and use a -citet variant of your style.

mcnesium commented 6 years ago

If you're interested in implementing something like this, be my guest

That's why I asked for help on where to start. My experience in developing jekyll-plugins is rather minimal. The excessive nesting of files is confusing to me. I haven't even been able to find the place, where exactly the rendering of a default citation string is done. This might also be due to the complexity of those style definitions.

Can you explain in a few words and with some links to the places in the code, how a

{% cite inukshuk2018 %}

transforms into

(inukshuk & mcnesium, 2018)

if the bibtex snippet looks like this:

article{inukshuk2018,
  title={natbib-style textual citations},
  author={inukshuk, Alice and mcnesium, Bob},
  year={2018}
}

if using the default apa.csl style

inukshuk commented 6 years ago

The CSL style is parsed using the csl Gem and rendered using citeproc-ruby; the functionality would have to be implemented using those two Gems (the jekyll-plugin just passes the citation data and the style to the renderer here)

mcnesium commented 6 years ago

The correct term for the type of citation seems to be narrative citation, as seen on Wikipedia

… to cite any reference in a paper, the writer should cite the author and year of the work, either by putting both in parentheses separated by a comma (parenthetical citation) or by putting the author in the narrative of the sentence and the year in parentheses (narrative citation).

So what I am trying to achieve is far from being uncommon. I declare this to be a feature request.

inukshuk commented 6 years ago

It is a feature request for CSL. Since jekyll-scholar is based on CSL the way to get this done outside of CSL is as I've outlined above.

justasmundeikis commented 5 years ago

@mcnesium did you manage somehow to solve your issue? I would also need a simple \citet instead of \citep solution.

mcnesium commented 5 years ago

@justasmundeikis no, sorry. I actually stopped using jekyll-scholar.

bradyneal commented 4 years ago

Has anyone solved this? Coming from machine learning, where all the conferences I submit to use natbib, I don't actually know how to write (more academic) blog posts without making regular use of narrative citations (natbib's \citet).

justasmundeikis commented 4 years ago

@bradyneal No, there is apparently no solution. I also stopped using jekyll-scholar.

bradyneal commented 4 years ago

For now, I'm just using something like [Flanagan & Matsumoto (2008)](#ruby) to reference

@book{ruby,
  title     = {The Ruby Programming Language},
  author    = {Flanagan, David and Matsumoto, Yukihiro},
  year      = {2008},
  publisher = {O'Reilly Media}
}
takeshi-teshima commented 8 months ago

For those who reach here, I use this workaround following the suggestion by inukshuk above.

I keep the following file as <jekyll-project-root>/_bibliography/narrative.csl, and I am using {% cite <key> --style _bibliography/narrative %} to render the narrative citation. The file has been created by ChatGPT, so please use it at your own risk.

<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0" class="in-text">
  <info>
    <title>Minimal Author-Year Style with Et Al</title>
    <updated>2024-01-25T00:00:00+00:00</updated>
  </info>

  <citation>
    <layout>
      <group delimiter=" ">
        <names variable="author">
          <name form="short" and="symbol" delimiter=", " initialize-with="" name-as-sort-order="all" et-al-min="4" et-al-use-first="1">
            <name-part name="family"/>
          </name>
          <et-al term="et-al"/>
        </names>
        <date variable="issued" prefix="(" suffix=")">
          <date-part name="year"/>
        </date>
      </group>
    </layout>
  </citation>

  <bibliography/>

</style>