[Tex/LaTex] Separate bibliographies with global labels

biblatexsubdividing

I have several categories of bibliographic entries which I would like to present satisfying the following requirements:

  1. Each category goes into its own subsection (for example, journal articles, books, etc.) of my "Bibliography" section.

  2. I would like to have entries in each category numbered separately and in reverse, for example [J10]-[J1], [B3]-[B1] etc.

  3. Different types of my entries do not necessarily correspond to different bibtex types (for example, @article entries may be split into two categories). I find it easiest to keep the entries of each category in a separate .bib file.

  4. References to the various bibliographic entries may appear anywhere in the text.

All requirements apart from (4) can be satisfied if each category corresponds to a separate refsection (see here for requirement (2), just add the option prefixnumbers when printing each bibliography). Unfortunately, refsections seem only to produce local labels and therefore each entry can only be referenced inside its own refsection.

If the above is correct, refsections cannot be used, and some other way of segregating entries will be required, for example by keywords or using biblatex categories. But then I don't see how the solution to (2) can be applied since it seems tied to refsections.

Any ideas?

Best Answer

Assuming that the categories are indicated in the usera field, the following document demonstrates how you can meet requirements 1, 2 and 4.

\documentclass{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[backend=biber,style=numeric,defernumbers,sorting=ydnt]{biblatex}
\usepackage{hyperref}

\makeatletter

% Store value passed to category option for \printbibliography
\apptocmd{\blx@key@category}{\edef\bbx@thecategory{\detokenize{#1}}}{}{}

% Initialize category counters
\def\bbx@initcategory#1{\csnumgdef{bbx@count@#1}{0}}
\forlistloop{\bbx@initcategory}{\blx@categories}

% Increment category counters
\def\bbx@countcategory#1{%
  \iffieldequalstr{usera}{#1}
    {\csnumgdef{bbx@count@#1}{\csuse{bbx@count@#1}+1}%
     \addtocategory{#1}{\thefield{entrykey}}%
     \listbreak}
    {}}
\AtDataInput{\forlistloop{\bbx@countcategory}{\blx@categories}}

% Print labelnumber as actual number, plus item total, minus one
\newrobustcmd*{\mkbibdesc}[1]{%
  \ifcitation
    {\number\numexpr\csuse{bbx@count@\thefield{usera}}+1-#1\relax}
    {\number\numexpr\csuse{bbx@count@\bbx@thecategory}+1-#1\relax}}

\makeatother

\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}

\begin{filecontents}{test.bib}
@Periodical{jcg,
  title = {Computers and Graphics},
  issuetitle = {Semantic {3D} Media and Content},
  volume = {35},
  number = {4},
  year = {2011},
  issn = {0097-8493}}
@Article{sarfraz,
  author = {M. Sarfraz and M. F. A. Razzak},
  title = {An algorithm for automatic capturing of the font outlines},
  journal = {Computers and Graphics},
  volume = {26},
  number = {5},
  pages = {795--804},
  year = {2002},
  issn = {0097-8493},
  doi = {10.1016/S0097-8493(02)00134-6}}
\end{filecontents}

\addbibresource{biblatex-examples.bib}
\addbibresource{test.bib}

\DeclareBibliographyCategory{primary}
\DeclareBibliographyCategory{secondary}

\defbibheading{bibliography}{\section*{Bibliography}}
\defbibheading{primary}{\subsection*{Primary references}}
\defbibheading{secondary}{\subsection*{Secondary references}}

\begin{document}
Filler text \parencite{companion,cms,sarfraz,nussbaum}.
\printbibheading
\printbibliography[heading=primary,category=primary,prefixnumbers={P}]
Filler text \parencite{ctan}.
\printbibliography[heading=secondary,category=secondary,prefixnumbers={S}]
Filler text \parencite{jcg}.\par\pagebreak
Filler text.
\end{document}

enter image description here

Thanks to a previous answer from PLK, requirement 3 can be supported with biber. The following sourcemap adds the data needed in the usera field. Just save this in a separate file called biber.conf.

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <sourcemap>
    <maps datatype="bibtex" bmap_overwrite="1">
      <map>
        <per_datasource>biblatex-examples.bib</per_datasource>
        <map_step map_field_set="USERA" map_field_value="primary"/>
      </map>
      <map>
        <per_datasource>test.bib</per_datasource>
        <map_step map_field_set="USERA" map_field_value="secondary"/>
      </map>
    </maps>
  </sourcemap>
</config>

Some caveats:

  • The new format typically needs an extra latex run to get the label numbers right, even if biblatex doesn't tell you to "rerun LaTeX".

  • The new format will generally screw up citation labels with the sortcites=true or style=numeric-comp option settings, unless all citation lists are limited to a single category. The citation list in the sample document, for example, doesn't meet this condition.