TransWikia.com

Plainnat like bibliography style but order by first name

TeX - LaTeX Asked by Nathan Explosion on August 8, 2021

By default, in the reference list generated by using the plainnat, the references are ordered by their last names.

How to order them by their first names?

Here I attach an MWE

article.tex

documentclass[]{article}
usepackage{natbib}

begin{document}

Test citep{a1,a2,a3}

bibliographystyle{plainnat}
bibliography{refs}

end{document}

refs.bib

@article{a1,
    title={Test paper 1},
    author={Albert Zwick},
    journal={Nature},
    year={2000}
}
@article{a2,
    title={Test paper 2},
    author={Christ Johnson},
    journal={Nature},
    year={2000}
}
@article{a3,
    title={Test paper 3},
    author={John Doe},
    journal={Nature},
    year={2000}
}

By default we will get

enter image description here

which are ordered by the last name. How to order by first name while sticking with plainatstyle?

One Answer

Sorting by given (first) name is extremely unusual with Western names. With natbib's authoryear style it also makes references much harder to find in the bibliography since your readers only know the family (last) names.

Anyway, to achieve the desired sorting you need to modify the .bst file

  1. Locate plainnat.bst on your machine. You can do this by typing kpsewhich plainnat.bst into the command line/terminal. Alternatively, obtain a copy of the file from CTAN http://mirrors.ctan.org/macros/latex/contrib/natbib/plainnat.bst

  2. Copy the file to a location where TeX can find it. The document directory will do fine.

  3. Rename the file to plainnat-sortby-first.bst

  4. Open the file and replace the block starting with FUNCTION {sort.format.names} (ll. 1207-1235 in my version) by

    FUNCTION {sort.format.names}
    { 's :=
      #1 'nameptr :=
      ""
      s num.names$ 'numnames :=
      numnames 'namesleft :=
        { namesleft #0 > }
        {
          s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
          nameptr #1 >
            {
              "   "  *
              namesleft #1 = t "others" = and
                { "zzzzz" * }
                { numnames #2 > nameptr #2 = and
                    { "zz" * year field.or.null * "   " * }
                    'skip$
                  if$
                  t sortify *
                }
              if$
            }
            { t sortify * }
          if$
          nameptr #1 + 'nameptr :=
          namesleft #1 - 'namesleft :=
        }
      while$
    }
    

The only change here is from s nameptr "{vv{ } }{ll{ }}{ ff{ }}{ jj{ }}" format.name$ 't := to s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=.

  1. Add your name and date and explain the modification in the comments at the top of the file.

  2. Use bibliographystyle{plainnat-sortby-first.bst} instead of bibliographystyle{plainnat} in your document.

As alternative to steps 1 to 5 above, you can get plainnat-sortby-first.bst from https://gist.github.com/moewew/203188e9933fdac3873601770b932357.

documentclass[]{article}
usepackage{natbib}

begin{filecontents}{jobname.bib}
@article{a1,
  title   = {Test paper 1},
  author  = {Albert Zwick},
  journal = {Nature},
  year    = {2000},
}
@article{a2,
  title   = {Test paper 2},
  author  = {Christ Johnson},
  journal = {Nature},
  year    = {2000},
}
@article{a3,
  title   = {Test paper 3},
  author  = {John Doe},
  journal = {Nature},
  year    = {2000},
}
end{filecontents}

begin{document}
Test citep{a1,a2,a3}

bibliographystyle{plainnat-sortby-first}
bibliography{jobname}
end{document}

Albert Zwick. Test paper 1. Nature, 2000.//Christ Johnson. Test paper 2. Nature, 2000.//John Doe. Test paper 3. Nature, 2000.


If you want given-family order everywhere (not just for sorting, but also in citations), get plainnat-firstlast.bst from https://gist.github.com/moewew/008625af47bc58c76e2e89ef2789fa1a.

Correct answer by moewe on August 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP