Skip to main content
The 2024 Developer Survey results are live! See the results
25 votes
Accepted

Sort bibliography in order of appearance

You cannot mix BibTeX and biblatex. In your code remove \bibliographystyle{unsrt} (which is BibTeX language) and load biblatex with sorting=none \usepackage[backend=biber,style=numeric,sorting=none]{...
moewe's user avatar
  • 178k
22 votes
Accepted

How can I sort a list numerically?

This approach automatically orders the items by year or any other number, by using an external list on an .csv file. \documentclass{article} \usepackage{filecontents} % To create an external .csv file ...
Cragfelt's user avatar
  • 4,015
16 votes

Sorting a comma-separated list with LaTeX?

How about Lua? \def\sortlist#1{% \directlua{% local t = { #1 } table.sort(t) tex.sprint(table.concat(t,", ")) }% } \sortlist{"World", "Hello"} \bye Addendum: One of the really ...
Henri Menke's user avatar
15 votes
Accepted

Sort Numbers After Their Values

Easy with xparse and expl3: \documentclass{article} \usepackage{xparse,expl3} \ExplSyntaxOn \NewDocumentCommand{\sortnumberlist}{m} { \clist_set:Nn \l_svend_numberlist_clist { #1 } \clist_sort:...
egreg's user avatar
  • 1.1m
14 votes
Accepted

Biblatex: how to automatically sort citation by year (sortcites=ynt) when references are sorted by name (sorting=nyt)

Update With biblatex v3.18 and above you can use \localrefcontext and \GenRefcontextData to switch to a different reference context (e.g. sorting). Use \AtBeginRefsection{\GenRefcontextData{sorting=...
moewe's user avatar
  • 178k
13 votes
Accepted

Sorting a comma-separated list with LaTeX?

This seems to work, with no packages. EDITED to solve the upper/lower-case problem. EDIT: Resolved problem when a comparison ran out of letters prior to resolving the order, for example, wash, ...
Steven B. Segletes's user avatar
12 votes
Accepted

Lexicographic ordering in expl3

At present there are no built-in methods for such textual comparisons (there are generic sorting wrappers but one has to supply the comparison code). The reason for this is that sorting is complex: ...
Joseph Wright's user avatar
  • 262k
12 votes

How can I sort a list numerically?

You could make use of the glossaries package as shown in the following example: \documentclass{article} \usepackage[automake, nonumberlist]{glossaries} \newglossaryentry{1912}{name={1912}, ...
leandriis's user avatar
  • 63.1k
11 votes

Cleveref isn't sorting nested lists properly

Turns out @Karalga's explanation of the cause of this bug points in the right direction, but doesn't get to the bottom of the problem. Sorting of nested list labels was broken for two completely ...
Toby Cubitt's user avatar
  • 2,072
11 votes

Sorting a comma-separated list with LaTeX?

You can safely compare strings consisting of ASCII characters; words with accented characters will not work. \documentclass{article} \usepackage{expl3,xparse} \ExplSyntaxOn \prg_new_conditional:Nnn \...
egreg's user avatar
  • 1.1m
11 votes
Accepted

Order table by row alphabeticaly

A proof of concept, using an idea from https://tex.stackexchange.com/a/356777/4427 \documentclass{article} \usepackage{geometry} \usepackage{longtable} \usepackage{xparse} \ExplSyntaxOn \...
egreg's user avatar
  • 1.1m
11 votes
Accepted

Regex replacement for biblatex/biber to eliminate the warning "month not integer..."

\DeclareSourcemap{ \maps[datatype=bibtex]{ \map[overwrite]{ \step[fieldsource=month, match=\regexp{\A(j|J)an(uary)?\Z}, replace=1] \step[fieldsource=month, match=\regexp{\A(f|F)eb(...
moewe's user avatar
  • 178k
10 votes

How to sort entries in a .bib file with biber

For anyone using a more recent version of biber, the element names have changed slightly. As of biber 2.11, sorting is now sortingtemplate name="tool". This config file works for me: <config> ...
arprice's user avatar
  • 111
10 votes
Accepted

Using Bibtool to sort a bib file by types and keys alphabetically

Following the example on page 60 of the BibTool manual, the type can be specified with %s($type). Example: @misc{def, note = {misc entry 1} } @article{xyz, author = {John Doe}, title = {...
Marijn's user avatar
  • 39k
10 votes

Using Bibtool to sort a bib file by types and keys alphabetically

If you are using Biber you can use the following sort.conf <?xml version="1.0" encoding="UTF-8"?> <config> <output_align>true</output_align> <output_fieldcase>lower&...
moewe's user avatar
  • 178k
10 votes

How can I sort a list numerically?

If you prefer the solution to be as close to your syntax as possible: \documentclass{article} \usepackage{expl3} \usepackage{xparse} \usepackage{enumitem} \usepackage{xcolor} \begin{document} \...
Alan Xiang's user avatar
  • 5,247
9 votes

Sort thebibliography by citation order

I'd already created 150 references in a document using thebibliography, and was faced with the task of sorting them in order of first appearance in the text (a very common requirement in scientific ...
DaveW's user avatar
  • 213
9 votes
Accepted

natbib does not sort&compress

natbib is not able to sort \citet cites, because it sorts and compresses only number sequences. It does not test, whether or not the names are same, before it compresses the number sequences. So only \...
Schweinebacke's user avatar
8 votes
Accepted

Put Chinese-language entries before English-language entries in the bibliography

You could use the \noopsort device to place the Chinese-language entries ahead of the remaining entries. The macro \noopsort takes 1 argument and is defined as follows: \newcommand{\noopsort}[1]{} ...
Mico's user avatar
  • 515k
8 votes
Accepted

How to sort in biblatex by name, year, order of appearance

Look in the file biblatex.def to find definitions of the different sortings. Based on a combination of the sorting=none sorting and sorting=nyt I came up with the following which I call sorting=nyc (c ...
rasmuse's user avatar
  • 141
7 votes

Lexicographic ordering in expl3

Somthing similar can be achieved using LuaTeX. Sorting is probably much faster in Lua. To parse the comma list I use utilities.parsers.settings_to_array from ConTeXt. To do so, I have to import the ...
Henri Menke's user avatar
7 votes

Order list of names with Lua

In ConTeXt you do not have to reinvent the wheel. \def\sort#1{% \ctxlua{ context( table.concat( table.sorted( utilities.parsers.settings_to_array([[#1]]) ) , ", " ) ) }} ...
Henri Menke's user avatar
7 votes

Biblatex: how to automatically sort citation by year (sortcites=ynt) when references are sorted by name (sorting=nyt)

A 'quick and dirty' solution (less good than moewe's one) is use biblatex's sortcites=false option, to enable the manual sorting of in-line citations. \documentclass{article} \usepackage[% ...
ebosi's user avatar
  • 11.8k
7 votes
Accepted

Trying to eliminate stack overflow during recursion (Alphabetic Bubble Sorter)

something like this allows the parameter stack to be popped before the recursive call \documentclass[10pt]{article} \newcommand\alphabubblesort[1]{\def\sortedlist{}\expandafter\sortlist#1,zzzzzzzzzz,\...
David Carlisle's user avatar
7 votes
Accepted

Bibliography First Name Sorting

With Biber you can use \documentclassarticle} \usepackage[backend=biber, style=authoryear]{biblatex} \addbibresource{biblatex-examples.bib} \DeclareSortingNamekeyScheme{ \keypart{ \namepart{...
moewe's user avatar
  • 178k
7 votes
Accepted

Alphabetical sorting of the bibliography using natbib and unsrtnat

Instead of the unsrtnat bibliography style that sorts its entries by order of citation and works best with a numeric citation style, you can use the plainnat style, that sorts the entries ...
leandriis's user avatar
  • 63.1k
7 votes
Accepted

Biblatex: sorting by title if no author

useeditor is the option you are looking for. If useeditor is set to false the editor will appear after the title and the work will be sorted by title. You can add the option globally for all @...
moewe's user avatar
  • 178k
7 votes
Accepted

Random sorting of text items

You can use the built-in \seq_shuffle:N command from the kernel to shuffle items and then use \seq_map_inline:Nn to map the items to your list. Here's a version that puts everything into a single ...
Alan Munn's user avatar
  • 221k
6 votes
Accepted

Sort references by order of appearance starting midway through the document

Just copying from the aux file what biblatex adds to stop citations in a caption counting if they are copied to the list of tables results in \documentclass{article} \usepackage[ backend=biber, ...
David Carlisle's user avatar
6 votes
Accepted

How to sort reference list depending on the number of authors with Biblatex?

Satisfying this (silly) sorting scheme requires using some advanced features. You should use a custom field to sort by and use a source map to populate the field with a construction functionally ...
PLK's user avatar
  • 22.8k

Only top scored, non community-wiki answers of a minimum length are eligible