[Tex/LaTex] How to sort entries of numerically referenced and split bibliographies alphabetically, but having citation numbers in order of appearance

biberbiblatexsorting

I've got a question regarding Biblatex with Biber backend. I'd like to have a split bibliography: One for print media and one for online resources. I would like to have quite a special kind of sorting:

  • Split bibliographies are done by using keywords.
  • The numeric style is used for citations and for bibliography.
  • It is necessary that both bibliographies, the one for print media and the one for online media, are sorted alphabetically (e.g. name of authors, year and title).
  • The numbers used for the citation labels in the two bibliographies should belong to separate and independent number ranges.
  • The citation numbers should be assigned in order of appearance in the text.

I've got a minimum working example:

\documentclass[12pt,oneside]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[%
    backend=biber, 
    defernumbers=true,
    style=numeric,
    sortcites=true,
    sorting=none
]{biblatex}   

\begin{filecontents}{testlit.bib}   
    @BOOK{al2013,
        author =   {Alice},
        title =    {Book of Alice},
        date =     {2013}
    }
    @BOOK{bo2014,
        author =   {Bob},
        title =    {Book of Bob},
        date =     {2014}
    }   
    @ONLINE{to2012,
        keywords = {secondary},
        author =  {Tom},
        title =   {Website of Tom},
        year =    {2012}
    }
    @ONLINE{ja2014,
        keywords = {secondary},
        author =  {James},
        title =   {Website of James},
        year =    {2014}
    }   
\end{filecontents}

\addbibresource{testlit.bib}

\begin{document}
  This is the first book I reference \cite{bo2014}. I can also reference 
  a first online resource \cite{to2012}. At the end of this sentence, I 
  reference the second book \cite{al2013} and the second online resource 
  \cite{ja2014}.

  \printbibliography[%
      notkeyword=secondary,
      heading=subbibliography,
      title={Print Media},
      sorting=nty,
      prefixnumbers={A-}
  ]

  \printbibliography[%
      keyword=secondary,
      heading=subbibliography,
      title={Online Media},
      sorting=nty,
      prefixnumbers={B-}
   ]    
\end{document}

The result I get looks as expected but not as desired:

Result of Working Example with **defernumbers** activated

The problem is that sorting the entries in the two bibliographies results in having the citation numbers in the text in an unsorted way.

If I set defernumbers to false, I get the following result:

Result of Working Example with **defernumbers** deactivated

This is quite close to the result that I'd like to have. But now both bibliographies share the same number range: There are, for example, no citations with labels A-2 and no B-1.

So my question is: Is there any way to tweak Biblatex and/or Biber to produce something like this:

Desired Output

Of course, it would be even nicer to have suffixes instead of the prefixnumbers, but I could live with that (I have a hack which produces suffixes for the two bibliographies, but it also needs defernumbers to be enabled to function).

Thank you very much in advance!

Kinds regards,

Steffen

Best Answer

It can be done removing sorting=none option when loading biblatex and adding the following lines in your preamble (see https://tex.stackexchange.com/a/37850/27635 for reference):

\AtDataInput{%
  \csnumgdef{entrycount:\strfield{prefixnumber}}{%
    \csuse{entrycount:\strfield{prefixnumber}}+1}}

\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}
\newrobustcmd*{\mkbibdesc}[1]{%
  \number\numexpr\csuse{entrycount:\strfield{prefixnumber}}+1-#1\relax}

MWE

\documentclass[12pt,oneside]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[%
    backend=biber,
    defernumbers=true,
    style=numeric,
    sortcites=true,
]{biblatex}

\AtDataInput{%
  \csnumgdef{entrycount:\strfield{prefixnumber}}{%
    \csuse{entrycount:\strfield{prefixnumber}}+1}}

\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}
\newrobustcmd*{\mkbibdesc}[1]{%
  \number\numexpr\csuse{entrycount:\strfield{prefixnumber}}+1-#1\relax}

\begin{filecontents}{testlit.bib}
    @BOOK{al2013,
        author =   {Alice},
        title =    {Book of Alice},
        date =     {2013}
    }
    @BOOK{bo2014,
        author =   {Bob},
        title =    {Book of Bob},
        date =     {2014}
    }
    @ONLINE{to2012,
        keywords = {secondary},
        author =  {Tom},
        title =   {Website of Tom},
        year =    {2012}
    }
    @ONLINE{ja2014,
        keywords = {secondary},
        author =  {James},
        title =   {Website of James},
        year =    {2014}
    }
\end{filecontents}

\addbibresource{testlit.bib}

\begin{document}
  This is the first book I reference \cite{bo2014}. I can also reference
  a first online resource \cite{to2012}. At the end of this sentence, I
  reference the second book \cite{al2013} and the second online resource
  \cite{ja2014}.

  \printbibliography[%
      notkeyword=secondary,
      heading=subbibliography,
      title={Print Media},
      sorting=nty,
      prefixnumbers={A-}
  ]

  \printbibliography[%
      keyword=secondary,
      heading=subbibliography,
      title={Online Media},
      sorting=nty,
      prefixnumbers={B-}
   ]
\end{document} 

Output

enter image description here