Edited by moewe (2018-07-14) to conform with the new names and sorting template definitions of biblatex
>= v3.8. See the edit history for older versions.
Under any of the predefined sorting schemes, you can override the order of the bibliography using the presort
and sortkey
fields. The presort
field is intended to group entries together in the bibliography. The sortkey
field serves as a master sort key.
From the appendix the biblatex manual, you can see that the predefined sorting schemes establish chronology only with the year
and volume
fields. With biber as the backend you can use \DeclareSortingTemplate
to also consider month
and day
. When data are not available, fallback values can be specified with \literal{<value>}
. Otherwise "small" fallback values are used.
Here I've defined a new sorting scheme based on nyt
from biblatex.def
.
\documentclass{article}
\usepackage{csquotes}
\usepackage[american]{babel}
\usepackage[backend=biber,sorting=nymdt]{biblatex}
\DeclareSortingTemplate{nymdt}{
\sort{
\field{presort}
}
\sort[final]{
\field{sortkey}
}
\sort{
\field{sortname}
\field{author}
\field{editor}
\field{translator}
\field{sorttitle}
\field{title}
}
\sort{
\field{sortyear}
\field{year}
}
\sort{
\field[padside=left,padwidth=2,padchar=0]{month}
\literal{00}
}
\sort{
\field[padside=left,padwidth=2,padchar=0]{day}
\literal{00}
}
\sort{
\field{sorttitle}
}
\sort{
\field[padside=left,padwidth=4,padchar=0]{volume}
\literal{0000}
}
}
\begin{filecontents}{\jobname.bib}
@Article{ref1,
author = {Lastname, Firstname},
title = {Article entry with presort field},
journaltitle = {Journal},
volume = {12},
date = {2001-01/2001-02},
pages = {92--122},
presort = {A}}
@Book{ref2,
author = {Lastname, Firstname},
title = {A book entry with presort field},
year = {2001},
month = feb,
day = {11},
presort = {A}}
@Book{ref3,
author = {Lastname, Firstname},
title = {A book entry with sortkey field},
date = {2000-01-01},
sortkey = {1}}
@article{itzhaki:phys,
author = {Itzhaki, Nissan},
volume = {54},
number = {2},
journal = {Phys. Rev. D},
doi = {10.1103/PhysRevD.54.1557},
year = {1996},
month = {7},
day = {15},
title = {Black hole information versus locality},
pages = {1557--1563}}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\begin{document}
\nocite{ref1,ref2,ref3}
\nocite{knuth:ct,knuth:ct:a,knuth:ct:b,itzhaki,itzhaki:phys}
\printbibliography
\end{document}
Note the various ways dates are specified in the example. The date
field follows the yyyy-mm-dd
format, but you can omit -mm-dd
or -dd
. This field also takes date ranges separated by /
(e.g. yyyy/yyyy
, yyyy-mm-dd/yyyy-mm-dd
, yyyy/
). By default the beginning of ranges are used for sorting. You can also specify dates with the year
, month
and day
fields. String values for month
are accepted, but only in 3-letter abbreviations (jan
, feb
, mar
, ...). These must be given without quotes or braces (e.g. month = jul
).
You can override the chronological order somewhat with the sortyear
field. In biblatex-examples.bib
, the knuth:ct
, knuth:ct:a
and knuth:ct:b
entries are given the sortyear
values 1984-0
, 1984-1
and 1986-1
, respectively.
For descending dates, use the direction=descending
option setting for \sort
.
\DeclareSortingTemplate{ndymdt}{
\sort{
\field{presort}
}
\sort[final]{
\field{sortkey}
}
\sort{
\field{sortname}
\field{author}
\field{editor}
\field{translator}
\field{sorttitle}
\field{title}
}
\sort[direction=descending]{
\field{sortyear}
\field{year}
\literal{9999}
}
\sort[direction=descending]{
\field[padside=left,padwidth=2,padchar=0]{month}
\literal{99}
}
\sort[direction=descending]{
\field[padside=left,padwidth=2,padchar=0]{day}
\literal{99}
}
\sort{
\field{sorttitle}
}
\sort[direction=descending]{
\field[padside=left,padwidth=4,padchar=0]{volume}
\literal{9999}
}
}
Further details on \DeclareSortingTemplate
can be found in the biblatex manual.
Here's the simple solution. Well, not so simple, after all. :)
One small problem, that I'll solve in a next release of imakeidx
: for some reason (that I don't remember now) we decided that program=xindy
called texindy
anyway. But unfortunately, it seems that the calls
xindy -M mystyle -C utf8 -L portuguese words.idx
and
texindy -M mystyle -C utf8 -L portuguese words.idx
are not equivalent, as the latter throws up an incomprehensible error (probably a bug in the texindy
script).
Thus the following document will require to run manually xindy
(but you have Arara, so it's not a problem), until the small problems are corrected.
Notice that xindy
provides two commands for the letter groups, which should be redefined in the preamble to do what's wanted.
\begin{filecontents*}{mystyle.xdy}
(markup-locclass-list :open "\dotfill " :sep "\dotfill ")
\end{filecontents*}
\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}[2012/05/09]
\newcommand*{\lettergroupDefault}[1]{}
\newcommand*\lettergroup[1]{%
\par\textit{#1}\par
\nopagebreak
}
\def\pfill{\unskip~\dotfill\penalty500
\strut\nobreak\dotfil~\ignorespaces}
\def\efill{\hfill\nopagebreak}
\def\dotfil{\leaders\hbox to.6em{\hss.\hss}\hfil}
\makeindex[name=words,columns=1,program=xindy,options=-M texindy -M mystyle -C utf8 -L portuguese]
\begin{document}
Hello world.
\index[words]{abacate}
\index[words]{ábaco}
\index[words]{alavanca}
\index[words]{árvore}
\index[words]{arte}
\index[words]{ácaro}
\index[words]{aba}
\printindex[words]
\end{document}
Best Answer
When BibTex sees a sequence like
{\"O}
or{\O}
, for sorting purposes these special characters are reduced toO
. The task is therefore to trick BibTex into thinking that the first example looks likeOe
, while the second should look likeZZZZZO
. For that, we introduce two macros,\donothing
and\printsecond
.{\donothing{text}}
will show nothing in the final bibliography, but "text" will be taken into account for sorting, so{\"O}{\donothing{e}}
will print as "Ö", and sorted as "Oe".{\printsecond{foo}{bar}}
will print "bar", and be sorted as "foobar".Example:
Using the
plain
style, the sorting keys for these entries are: zzzzzostersund1000, oezkaragoz1001, oezl1002, oezj1003, ofa1004, zzz1005, which gives the correct order:Using the
alpha
style, the entries are sorted by label, which consists of three letters of the author name, and the last two digits of the year for single author references. The sorting keys are therefore: zzzzzost1000, oezk1001, oez1002, oez1003, ofa1004, zzz1005. You can see here that the special characters are treated as one character by BibTeX, even when several plain characters are extracted when generating the sorting key. The output is therefore:and indeed "Oez03" < "Özk01", as oez1003 < oezk1001, since 1 < k. If you would like it the other way round, the Özk01 has to be shortened to Öz01, which can be achieved in the database by changing the second entry to
(Note how the "invisible" e is now a special character of its own, and counted as such, as it jumped out of the first special character.)