Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting references in alphabetical order using natbib #25

Closed
zavud opened this issue Jun 11, 2021 · 13 comments
Closed

Sorting references in alphabetical order using natbib #25

zavud opened this issue Jun 11, 2021 · 13 comments

Comments

@zavud
Copy link

zavud commented Jun 11, 2021

I want to use natbib for my references, and therefore I set use-biblatex: false and use-natbib: true in the YAML and change nothing else. When I knit the document, the references are ordered (in the references section) not in an alphabetical order, but some strange/unpredictable order. How I can solve this?

@ulyngs
Copy link
Owner

ulyngs commented Jun 12, 2021

my guess is that they're presented in the order in which they appear in the text - to change to alphabetical order, google for how to set this as an option for natbib, then try to adjust accordingly in template.tex at this location

\usepackage{natbib}
\setcitestyle{$natbib-citation-style$}
\bibliographystyle{$natbib-bibliography-style$}

@ulyngs
Copy link
Owner

ulyngs commented Jun 13, 2021

Ok, I just looked at this properly.

Turns out I already designed the template to make this easy to set directly from index.Rmd's YAML header. Just use e.g.

use-natbib: true
natbib-citation-style: authoryear
natbib-bibliography-style: plainnat

(remember to set use-biblatex: false)

see https://tex.stackexchange.com/questions/425837/alphabetical-sorting-of-the-bibliography-using-natbib-and-unsrtnat

@ulyngs ulyngs closed this as completed Jun 13, 2021
@zavud
Copy link
Author

zavud commented Jun 14, 2021

@ulyngs I have seen this post (tex stackexchange) and tried the trick before and nothing helped. I have tried other things as well, still no progress.

Regarding your assumption on how the references are ordered: they are not presented in the order they appear in the text. After analyzing it a bit, I figured out how they are presented: they are actually presented alphabetically, however, based on the name that comes the last. For example, if some author is called "Lee Zaa Ann" then this will come the first (because the last name in the full name starts with "A"). Conversely, if someone is called "Ann Lee Zaa" then this will be presented as the last reference. But what I really want is "Ann Lee Zaa" to be treated as the first author and so on. Do you happen to have a workaround for this? Thanks :)

@ulyngs
Copy link
Owner

ulyngs commented Jun 14, 2021

Interesting, so you want ordering based on first number rather than last name? That feels slightly strange to me - wouldn't you always want sorting based on family name?

Either way, I think there's two options:

  • if you actually meant ordering based on family name, but it just happens to be the case that some other name than the actual family is parsed as as the family name, then the issue is just in your .bib entry. Go and find the entry and correct the name in there.
    • In the case of names like 'von Goethe', which I just realised was sorted incorrectly by 'von' instead of 'Goethe', you just add sortname={Beethoven} in your bib entry (see this tex stackexchange - I just fixed this in the oxforddown sample content)
  • if you do indeed mean ordering based on first name, then you can use a custom .bst file for the bibliography style (like the example I've included in the templates folder of the ACM reference format) - google how to tweak a bst file to make the sorting based on first name rather than family name

@zavud
Copy link
Author

zavud commented Jun 14, 2021

@ulyngs I am not really sure if I have to sort based on family or last name. I am just trying to write a normal-looking thesis (following the universal rules) :) and I read a lot of scientific papers and other theses and in all of them ordering is based on whatever comes first. And honestly, I do not know which name is someone's family and first names.

For example, this is a part from the last page of my references:

image

As you can see, you can find authors in the last page whose names start with "A" or "D" and so on. This may look very confusing and strange to the readers.

@ulyngs
Copy link
Owner

ulyngs commented Jun 14, 2021

So the sorting in your current reference list is indeed by last name, i.e. family name:

  • Rosema
  • Schlerf
  • Senf
  • Simon
  • Sinha
  • Suits
  • Tuia
  • Upreti

This is expected behaviour.

It sounds like you actually just want their names to appears as "Upreti, Deepak" and so on, so that their family name is written before their first name in the reference list, which makes it immediately obvious that the sorting is alphabetical by family name

https://tex.stackexchange.com/questions/131087/displaying-authors-name-in-a-bibliographic-entry-in-the-form-surname-first-in

@zavud
Copy link
Author

zavud commented Jun 14, 2021

@ulyngs yes, this post makes sense. I downloaded the plainnat.bst file and put it in the templates directory. And then, I followed the answer in the link you shared. However, nothing really changed. Perhaps the the line natbib-bibliography-style: templates/myplainnat.bst in the yaml is overwritten by some line in the template.tex?

Even before I downloaded the plainnat.bst file, everything looked the same in the reference. Before downloading plainnat.bst , ACM-Reference-Format.bst was in use

@ulyngs
Copy link
Owner

ulyngs commented Jun 14, 2021

to see if anything is getting overridden in unexpected ways, have a look at docs/_main.tex after you built to PDF - then you can see exactly what gets inserted in the .tex file that LaTeX builds the PDF from

you should also just try changing something at random in your templates/mypainnat.bst file and see if that propagates to the final PDF in the way you'd expect. The simplest way to start would be to just write a bunch of gibberish in that file and see if you get an error message when trying to build to PDF, as you'd expect

@zavud
Copy link
Author

zavud commented Jun 14, 2021

@ulyngs I checked the docs/_main.tex file as suggested. templates/myplainnat.bst has been inserted, which seems right.

I also did templates/mypainnat.bst as you suggested. It did give me an error without completing the knitting process.

@ulyngs
Copy link
Owner

ulyngs commented Jun 14, 2021

... and are you able to make some sort of change in the bst files that also changes things in the reference list? E.g. try to remove the author names from appearing at all, just to make sure you can actually make it affect stuff in the output, then experiment from there

@zavud
Copy link
Author

zavud commented Jun 15, 2021

I am not sure how you completely remove the author names from appearing (first time in my life that I am dealing with a .bst file :D ). But I did remove the line { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't := from the .bst file and I got an error when I tried to knit the file.

@ulyngs
Copy link
Owner

ulyngs commented Jun 15, 2021

does it work as expected when you change this

{ s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=

to this

{ s nameptr "{vv~}{ll}{, f.}{, jj}" format.name$ 't :=

As per this

@zavud
Copy link
Author

zavud commented Jun 15, 2021

@ulyngs it actually does! I am really surprised because I did it multiple times yesterday (I swear :D) and failed to achieve this. But when copying from your comment here, it somehow (and perhaps "magically") worked! Thanks a lot for bearing with me and continuously giving suggestions! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants