5

Please see the mwe below

\NeedsTeXFormat{LaTeX2e}
\documentclass[12pt]{article}

\usepackage[backend=biber,%
isbn=false,%
style=numeric,%
sorting=ydnt,%
giveninits=true,% initials of first names
maxbibnames=20,%
defernumbers,%
labeldateparts,% for academic cv
locallabelwidth% for academic cv
]{biblatex} 

\usepackage{filecontents}

\begin{filecontents}{\jobname_a.bib}
@Article{Fabulous2016a,
  author  = {Fabulous, Jason},
  title   = {How to be fabulous - The Story of My Life},
  journal = {Fancy Journal},
  year    = {2016},
  volume  = {56},
  number  = {3},
  pages   = {1-99},
  keywords = {include},
}

@Article{FabulousFaulkner2019a,
  author  = {Fabulous, Jason and Faulkner, Trent},
  title   = {One Fabulous Moment after Another -  A chat with my buddy Trent},
  journal = {Journal},
  year    = {2018},
  volume  = {56},
  number  = {3},
  pages   = {1-99},
  keywords = {},
}
\end{filecontents}

\begin{filecontents}{\jobname_b.bib}
@Article{Fuca2019a,
  author  = {Fuca, Wanda},
  title   = {Ridges, Plates and Seamounts},
  journal = {Journal 2},
  year    = {2019},
  volume  = {56},
  number  = {3},
  pages   = {1-99},
  keywords = {include},
}

@Article{Fuca2015a,
  author  = {Fuca, Wanda},
  title   = {How to truly know whether your parents were Hippies},
  journal = {Journal},
  year    = {2015},
  volume  = {56},
  number  = {3},
  pages   = {1-99},
  keywords = {include},
}
\end{filecontents}

\begin{filecontents}{cvsectionnum.tex}
% define a bibenvironment for an numbered bib entry
\defbibenvironment{bibenvcvsectionnum}%
{\list%
{\printtext[labelnumberwidth]{%
\printfield{labelprefix}%
\printfield{labelnumber}}}%
{\setlength{\leftmargin}{\bibhang}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}%
{\endlist}%
{\item}%

% cvsectionnum
\newcommand\cvsectionnum[3]{%
\section*{#1}%
\begin{refsection}[#2]%
\nocite{*}%
\printbibliography[heading=none,env=bibenvcvsectionnum,#3]%
\end{refsection}%
}%
\end{filecontents}


\begin{filecontents}{reverse_order_bib_entry_numbering.tex}
\AtDataInput{%
\csnumgdef{entrycount:\therefsection}{%
\csuse{entrycount:\therefsection}+1}}%
%
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}%
\newrobustcmd*{\mkbibdesc}[1]{%
\number\numexpr\csuse{entrycount:\therefsection}+1-#1\relax}%
\end{filecontents}

\addbibresource{\jobname_a.bib}%
\addbibresource{\jobname_b.bib}%

% declare section names
\def\sectiona{J's Publications}%
\def\sectionb{Wanda's Pulications}%


% definition of `cvsectionnum'
\input{cvsectionnum.tex}

% reverse order numbering
\input{reverse_order_bib_entry_numbering.tex}


\begin{document}

% J
\cvsectionnum{\sectiona}{\jobname_a.bib}{keyword={include}}%

% Wanda
\cvsectionnum{\sectionb}{\jobname_b.bib}{keyword={include}}%

\end{document}

Here is what the output looks like:

enter image description here

The question is, how to make J's bib entry have a 1 as a label instead of a 2? Via the keywords functionality, we are filtering each of the publication lists passed to the cvsectionnum command, yet it seems that the counter is being determined before filtering, hence the out of range and non-sequential label.

This post might also provide additional context.

2 Answers2

3

I use an additional counter to count the entries, this requires two compilations.

The filecontents package is obsolete, I replaced this with the [overwrite] option.

\NeedsTeXFormat{LaTeX2e}
\documentclass[12pt]{article}
\usepackage{refcount}
\usepackage[backend=biber,%
isbn=false,%
style=numeric,%
sorting=ydnt,%
giveninits=true,% initials of first names
maxbibnames=20,%
defernumbers,%
labeldateparts,% for academic cv
locallabelwidth% for academic cv
]{biblatex}

\begin{filecontents}{\jobname_a.bib} @Article{Fabulous2016a, author = {Fabulous, Jason}, title = {How to be fabulous - The Story of My Life}, journal = {Fancy Journal}, year = {2016}, volume = {56}, number = {3}, pages = {1-99}, keywords = {include}, }

@Article{FabulousFaulkner2019a, author = {Fabulous, Jason and Faulkner, Trent}, title = {One Fabulous Moment after Another - A chat with my buddy Trent}, journal = {Journal}, year = {2018}, volume = {56}, number = {3}, pages = {1-99}, keywords = {}, } \end{filecontents}

\begin{filecontents}{\jobname_b.bib} @Article{Fuca2019a, author = {Fuca, Wanda}, title = {Ridges, Plates and Seamounts}, journal = {Journal 2}, year = {2019}, volume = {56}, number = {3}, pages = {1-99}, keywords = {include}, }

@Article{Fuca2015a, author = {Fuca, Wanda}, title = {How to truly know whether your parents were Hippies}, journal = {Journal}, year = {2015}, volume = {56}, number = {3}, pages = {1-99}, keywords = {include}, } \end{filecontents} \newcounter{mybibcount} \begin{filecontents}[overwrite]{cvsectionnum.tex} % define a bibenvironment for an numbered bib entry \defbibenvironment{bibenvcvsectionnum}% {\setcounter{mybibcount}{-1}\list% {\stepcounter{mybibcount}\printtext[labelnumberwidth]{% \printfield{labelprefix}% \printfield{labelnumber}}}% {\setlength{\leftmargin}{\bibhang}% \setlength{\itemsep}{\bibitemsep}% \setlength{\parsep}{\bibparsep}}}% {\refstepcounter{mybibcount}\label{bibcount\therefsection}\endlist}% {\item}%

% cvsectionnum \newcommand\cvsectionnum[3]{% \section{#1}% \begin{refsection}[#2]% \nocite{}% \printbibliography[heading=none,env=bibenvcvsectionnum,#3]% \end{refsection}% }% \end{filecontents}

\begin{filecontents}[overwrite]{reverse_order_bib_entry_numbering.tex} \AtDataInput{% \csnumgdef{entrycount:\therefsection}{% \getrefnumber{bibcount\therefsection}}}% % \DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}% \newrobustcmd*{\mkbibdesc}[1]{% \number\numexpr\csuse{entrycount:\therefsection}+1-#1\relax}% \end{filecontents}

\addbibresource{\jobname_a.bib}% \addbibresource{\jobname_b.bib}%

% declare section names \def\sectiona{J's Publications}% \def\sectionb{Wanda's Pulications}%

% definition of `cvsectionnum' \input{cvsectionnum.tex}

% reverse order numbering \input{reverse_order_bib_entry_numbering.tex}

\begin{document} % J \cvsectionnum{\sectiona}{\jobname_a.bib}{keyword={include}}% % Wanda \cvsectionnum{\sectionb}{\jobname_b.bib}{keyword={include}}% \end{document}

enter image description here

Ulrike Fischer
  • 327,261
2

The problem comes from

{\printtext[labelnumberwidth]{%
\printfield{labelprefix}%
\printfield{labelnumber}}}%

that I changed into

{\printfield[labelnumberwidth]{labelnumber}}%

by taking some inspiration in the biblatex User Guide p. 156.

The result is:

enter image description here

  • This solution fulfills one criterion (eliminating labels which don't start at one and potential non-sequential gaps between labels), but note that we're trying to implement reverse order numbering. Some choose to implement reverse order numbering this because they're attuned to the fact that some others like to count and are lazy. If you number in reverse order, the reader only needs to glance at the first entry to guage the total number of entries in the list. – John Chris Oct 28 '19 at 17:21
  • Edited title of question to reflect the importance of reverse order numbering. – John Chris Oct 28 '19 at 17:25
  • 2
    \printtext[labelnumberwidth]{% \printfield{labelprefix}% \printfield{labelnumber}} (modulo line breaks) is a perfectly fine idiom. Indeed, dropping labelprefix means that this function is no longer supported in the bibliography. – moewe Oct 28 '19 at 19:58