2

I would like to do something like in this question, but be able to pass a sub-set of the bibresource to \nocite{}. The main problem is that \nocite{*} passes the whole bibliography and then the reverse numbering scheme uses the total number of references in the bibresource instead of just those being cited.

So, either I need a new way to use \nocite{} on a subset of the bibliography, or a way to count the entries in a refsection

This is for a CV and I simply don't want to hand list the citations for each section, I would rather do something like: "cite all articles in this section, and give them reverse ordering".

The code below does the reverse ordering, but it takes into account all of the \nocite{*} entries. So I end up with something like:

  • [17] a citation of an article
  • [16] another citation of an article
  • [15] yet another of an article

instead of the desired [3], [2], [1], again I don't want to provide the entire list (which is larger than 3) using manual entry of each key.

\documentclass{article}
\usepackage[backend=bibtex,style=numeric,sorting=ydnt]{biblatex}

% Count total number of entries in each refsection
\AtDataInput{%
  \csnumgdef{entrycount:\therefsection}{%
    \csuse{entrycount:\therefsection}+1}}

% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}    
\newrobustcmd*{\mkbibdesc}[1]{%
  \number\numexpr\csuse{entrycount:\therefsection}+1-#1\relax}

\newcommand{\printbibsection}[2]{%
  \begin{refsection}%
    \nocite{*}%
    \printbibliography[type={#1}, title={#2}, resetnumbers=true]%
  \end{refsection}}

\addbibresource{xampl.bib}

\begin{document}
    \printbibsection{article}{article in peer-reviewed journal} % Print all articles from the bibliography

    \printbibsection{book}{books} % Print all books from the bibliography
\end{document}
1
  • 2
    Maybe package citeall has the right solution.
    – Johannes_B
    Nov 11, 2016 at 18:37

1 Answer 1

2

If I've understood well your request, looking at your mwe, I don't think refsection is needed.

Here is my solution (since you didn't provide some bibitem examples, I've invented them):

\documentclass{article}
\usepackage[backend=biber,style=numeric,sorting=ydnt,defernumbers=true]{biblatex}

\newcounter{total}
\newcounter{totarticles}
\newcounter{totbooks}
\AtDataInput{%
    \ifentrytype{article}%
        {\stepcounter{totarticles}}%
        {}%
    \ifentrytype{book}%
        {\stepcounter{totbooks}}%
        {}%
    }%

% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}    
% Print labelnumber as actual number, plus item total, minus one
\newrobustcmd{\mkbibdesc}[1]{%
    \number\numexpr\thetotal+1-#1\relax}

\newcommand{\printbibsection}[2]{%
    \printbibliography[type={#1}, title={#2}, resetnumbers=true]%
    }%

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{article1,
  title={Title A},
  author={Author, Allegra},
  journal={Journal A},
  volume={1},
  pages={1},
  year={2001},
  publisher={Publisher A}
}
@article{article2,
  title={Title B},
  author={Buthor, Bee},
  journal={Journal B},
  volume={2},
  pages={2},
  year={2002},
  publisher={Publisher B}
}
@article{article3,
  title={Title C},
  author={Cuthor, Carla},
  journal={Journal C},
  volume={3},
  pages={3},
  year={2003},
  publisher={Publisher C}
}
@book{book1,
  title={Book A Title},
  author={Author, Allegra},
  year={2011},
  publisher={Book A Publisher}
}
@book{book2,
  title={Book B Title},
  author={Buthor, Bee},
  year={2012},
  publisher={Book B Publisher}
}
@article{article4,
  title={Title D},
  author={Duthor, Duck},
  journal={Journal D},
  volume={4},
  pages={4},
  year={2014},
  publisher={Publisher D}
}
@book{book3,
  title={Book C Title},
  author={Cuthor, Carla},
  year={2003},
  publisher={Book C Publisher}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
    \nocite{*}
    This document has \thetotbooks{} books and \thetotarticles{} articles. % I've added this line only to show the counters

    \setcounter{total}{\thetotarticles}
    \printbibsection{article}{article in peer-reviewed journal} % Print all articles from the bibliography

    \setcounter{total}{\thetotbooks}
    \printbibsection{book}{books} % Print all books from the bibliography
\end{document}  

enter image description here

If your selection criteria are not simply type-based but more complex, you can create specific categories:

\documentclass{article}
\usepackage[backend=biber,style=numeric,sorting=ydnt,defernumbers=true]{biblatex}

\DeclareBibliographyCategory{article}
\DeclareBibliographyCategory{book}

\newcounter{total}
\newcounter{totarticles}
\newcounter{totbooks}
\AtDataInput{%
    \ifentrytype{article}% here you can put more complex selection criteria
        {\addtocategory{article}{\thefield{entrykey}}\stepcounter{totarticles}}%
        {}%
    \ifentrytype{book}%
        {\addtocategory{book}{\thefield{entrykey}}\stepcounter{totbooks}}%
        {}%
    }%

% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}    
%\makeatletter
% Print labelnumber as actual number, plus item total, minus one
\newrobustcmd{\mkbibdesc}[1]{%
    \number\numexpr\thetotal+1-#1\relax}

\newcommand{\printbibsection}[2]{%
    \printbibliography[category={#1}, title={#2}, resetnumbers=true]%
    }%

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{article1,
  title={Title A},
  author={Author, Allegra},
  journal={Journal A},
  volume={1},
  pages={1},
  year={2001},
  publisher={Publisher A}
}
@article{article2,
  title={Title B},
  author={Buthor, Bee},
  journal={Journal B},
  volume={2},
  pages={2},
  year={2002},
  publisher={Publisher B}
}
@article{article3,
  title={Title C},
  author={Cuthor, Carla},
  journal={Journal C},
  volume={3},
  pages={3},
  year={2003},
  publisher={Publisher C}
}
@book{book1,
  title={Book A Title},
  author={Author, Allegra},
  year={2011},
  publisher={Book A Publisher}
}
@book{book2,
  title={Book B Title},
  author={Buthor, Bee},
  year={2012},
  publisher={Book B Publisher}
}
@article{article4,
  title={Title D},
  author={Duthor, Duck},
  journal={Journal D},
  volume={4},
  pages={4},
  year={2014},
  publisher={Publisher D}
}
@book{book3,
  title={Book C Title},
  author={Cuthor, Carla},
  year={2003},
  publisher={Book C Publisher}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
    \nocite{*}

    \setcounter{total}{\thetotarticles}
    \printbibsection{article}{article in peer-reviewed journal} % Print all articles from the bibliography

    \setcounter{total}{\thetotbooks}
    \printbibsection{book}{books} % Print all books from the bibliography
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .