how to adapt the sorting of a custom type @standard in using biblatex/biber

In my bibliography I have some standards for which I have modified the declaration given here according to the suggested way of citing given here (sorry, this site is not available in English).

The problem now is, that the entries in the bibliography are sorted wrong in the default nty style, because the author is always the same and next comes the title (as can be seen in the picture below, which is the result of the given code as is).

So the question is, how can I convince biblatex/biber to sort the entries correct, i.e. they have to be sorted after the number field?

What I have found out so far is that I can define a new sorting scheme with \DeclareSortingScheme (inspired by this answer), but I haven't found out, if there is a possibility to apply it only to specified entrytypes.

What I have found is that there is a possibility of removing fields for sorting for specified entrytypes using the \DeclareSortExclusion command. Combining this with an extended version of \DeclareSortingScheme{nty}{...} gives the desired result (have a look at the commented part of the code before \begin{document}).

But maybe there is a more elegant way to achieve the desired result.?

\begin{filecontents}{test1.bib}
@STANDARD{ISO2240,
author       = {{International Organization for Standardization}},
title        = {Photography -- Colour reversal camera films -- Determination
of ISO speed},
year         = {2003},
number       = {ISO 2240:2003-10},
langid       = {english},
}
@STANDARD{ISO9660,
author       = {{International Organization for Standardization}},
title        = {Information processing; volume and file structure of CD-ROM
for information interchange},
year         = {1988},
number       = {ISO 9660:1988-04},
langid       = {english},
}
\end{filecontents}
\documentclass{article}
\usepackage[
style=numeric,
%    sorting=nty,   <-- default
]{biblatex}
% -------------------------------------------------------------------------------------------------
%%% define own style for standards
%%% at <https://tex.stackexchange.com/questions/65637/how-to-cite-a-standard-iso-etc-in-biblatex>
%% it was given as ...
%\DeclareDatamodelEntrytypes{standard}
%\DeclareDatamodelEntryfields[standard]{type,number}
%\DeclareBibliographyDriver{standard}{%
%  \usebibmacro{bibindex}%
%  \usebibmacro{begentry}%
%  \usebibmacro{author}%
%  \setunit{\labelnamepunct}\newblock
%  \usebibmacro{title}%
%  \newunit\newblock
%  \printfield{number}%
%  \printfield[parens]{type}%
%  \newunit\newblock
%  \usebibmacro{location+date}%
%  \newunit\newblock
%  \iftoggle{bbx:url}
%    {\usebibmacro{url+urldate}}
%    {}%
%  \newunit\newblock
%  \setunit{\bibpagerefpunct}\newblock
%  \usebibmacro{pageref}%
%  \newunit\newblock
%  \usebibmacro{related}%
%  \usebibmacro{finentry}
%}
% ... but according to <http://www.beuth.de/de/hilfe/hilfezitierenvonnormen>
% much less fields are required
\DeclareDatamodelEntrytypes{standard}
\DeclareDatamodelEntryfields[standard]{type,number}
\DeclareBibliographyDriver{standard}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\printfield{number}%
\printfield[parens]{type}%
\newunit\newblock
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}
\usebibmacro{finentry}
}

%% unfortunately then the entries are not sorted as one likes, because they are
%% sorted as "nty", so after "author, title, year" and not after the number'
%% field
%% (have a look at section 4.5.5 "Sorting" (on page 183 of v3.4 of the manual))
%
%% this is the way how they should be sorted
%\DeclareSortingScheme{sortStandard}{
%    \sort{
%        \field{presort}
%    }
%    \sort[final]{
%        \field{sortkey}
%    }
%    \sort{
%        \field{number}
%    }
%    \sort{
%        \field{sorttitle}
%        \field{title}
%    }
%}
%% ----- uncomment the following block which brings up the desired result -----
% but because there seems to be no way of applying this scheme to an entrytype'
% the "standard" nty' sorting scheme has to be modified and the fields which
% should not be used for @standard' are excluded from sorting
%\DeclareSortingScheme{nty}{
%    \sort{
%        \field{presort}
%    }
%    \sort[final]{
%        \field{sortkey}
%    }
%    \sort{
%        \field{sortname}
%        \field{author}
%        \field{editor}
%        \field{translator}
%        \field{sorttitle}
%        \field{title}
%        \field{number}
%        % ---------------------
%    }
%    \sort{
%        \field{sorttitle}
%        \field{title}
%    }
%    \sort{
%        \field{sortyear}
%        \field{year}
%    }
%}
%\DeclareSortExclusion{standard}{
%    sortname,
%    author,
%    editor,
%    translator,
%    sorttitle,
%    title,
%    sortyear,
%    year,
%}
%% ----------------------------------------------------------------------------
\begin{document}
\cite{ISO2240,ISO9660}
\printbibliography
\end{document}


• Not really - I thought about adding per-type sorting schemes but this hardly makes any sense - if the whole bibliography list is not sorted by the same rule, it would not really be sorted in a meaningful way because you would be, at some point, comparing dissimilar fields. – PLK Mar 21 '16 at 0:12
• @PLK, In general you are right, but don't you think that in my case the default sorting scheme "fails" and it would be nice if one could set an entry type basis sorting scheme? Please also have a look at the answer of moewe and my comment there. – Stefan Pinnow Mar 21 '16 at 21:22
• I don't really understand - why can't you just declare a sorting scheme where number comes first and use it for everything? If this interacts with number fields in other entries which are not standards, then call the field something else like standardnumber and sort on that first. – PLK Mar 21 '16 at 21:35

I think what you are doing is not bad at all. And if it gives the desired result what more should you ask for?

Because an answer only stating that would be a bit meagre let me offer an alternative solution. You can use the normal sorting scheme if you add the following source mapping

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\pertype{standard}
\step[fieldsource=number, final]
\step[fieldset=sortkey, origfieldval]
}
}
}


it simply copies the number field (which you want for sorting) to the sortkey field that is considered before other fields.

• Thanks for the answer. In my opinion your solution is much better than mine. My solution (as given) only works when using the sorting=nty while yours -- as far as I understand it -- works for any sorting value. – Stefan Pinnow Mar 21 '16 at 21:18
• @StefanPinnow Yes, it should work with all (properly coded) sorting schemes (that includes at least the standard schemes). It can only sort with the contents of number though, one could possibly devise more cunning ways of appending to the sortkey field to get more advanced sorting, but that of course has its limitations. – moewe Mar 22 '16 at 7:06
• Thanks for the confirmation. To add another sorting field is not necessary in my opinion, because given "the number" as I have done it, e.g. ISO 9660:1988-04, is always unique. This information alone is sufficient to identify the standard. Adding the other fields to the output is just to get a better idea what hides behind the number. – Stefan Pinnow Mar 22 '16 at 7:18
• I should have probably specified what I meant when I said properly coded above, it just means that the sortkey field is part of the sorting scheme and ranks high in the priority (not much later than presort which should be the first field, it should probably also come with the final option). – moewe Mar 22 '16 at 7:20