Hot answers tagged

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
  • 173k
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
  • 3,985
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
  • 173k
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
  • 257k
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
  • 62.4k
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,062
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
  • 173k
10 votes

Expandable (quick) sort array macro?

A short demo using l3sort: \documentclass{article} \usepackage{expl3,l3sort,xparse} \ExplSyntaxOn \cs_set:Npn \quicksort_fp:nnTF #1#2 { \fp_compare:nNnTF {#2} > {#1} } \...
Joseph Wright's user avatar
  • 257k
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
  • 35.9k
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
  • 173k
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
  • 4,912
9 votes
Accepted

Grouping sorted bibliographyies by langid

Of course one can just put a \sort{\field{langid}} into the sorting procedure, but that will sort the languages lexicographically, so English will appear first, then Greek and then Russian, not ...
moewe's user avatar
  • 173k
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
  • 113
9 votes
Accepted

How to sort entries in a .bib file with biber

Actually with biber 2.3, which is what you are using, it should work with a suitable <sorting> specification in your biber.conf. There was a bug in 2.4, fixed in the 2.5 dev version currently on ...
PLK's user avatar
  • 22.5k
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
  • 495k
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

Sort sections according to alphabetical order

The Idea The solution uses one technique you did not prefer. Namely, putting sections in separate files. However, that is is only (non-cumbersome) I can find in order to sort the sections. Anyway, ...
Masroor's user avatar
  • 17.7k
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.5k
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
  • 173k

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