3

I'm struggling with the (popular) biblatex change where the 2016 upgrade stopped reverse labeling from working. Someone has provided a solution for filtering by type here and here. This solution claims to work for keyword filtering, but not the reverse numbering. Below is my MWE, which does not produced the desired result, which should look like:

Foo
[F2] x y. “b”. In: j (1995).
[F1] x y. “a”. In: j (1990). 
Bar
[B2] x y. “d”. In: j (2005).
[B1] x y. “c”. In: j (2000). 

Specifically, 1) order defined by order of \nocite{a} commands, OR reverse chronological order if that is not an option, 2) Filtered by keyword, 3) using labelprefix.

If someone can offer some code/advice to get the above functionality I would be grateful.

\documentclass{article}

\usepackage[style=numeric,
sorting=none,
% sorting=ydnt  % prefer to sort manually w/ \nocite commands
backend=biber,
]{biblatex}

\begin{filecontents*}{\jobname.bib}
@article{b, author={x y}, title={b}, journal={j}, year=1995, keywords={foo}}
@article{a, author={x y}, title={a}, journal={j}, year=1990, keywords={foo}}
@article{c, author={x y}, title={c}, journal={j}, year=2000, keywords={bar}}
@article{d, author={x y}, title={d}, journal={j}, year=2005, keywords={bar}}
\end{filecontents*}
\addbibresource{\jobname}

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

\begin{document}
Some text w/o citations.
% foo in reverse chronological order
\nocite{b} \nocite{a}
% bar in reverse chronological order
\nocite{d} \nocite{c}

\newrefcontext[labelprefix=F]
\printbibliography[keyword=foo, title=Foo]
\newrefcontext[labelprefix=B]
\printbibliography[keyword=bar, title=Bar]

\end{document}
2
+50

I can generate your desired output with a couple of small changes. That said, I am not sure the solution is general enough for the real purpose. The changes are:

  • Load biblatex with the defernumbers option
  • Use \jobname.bib instead of \jobname as the bib resource (otherwise biber uses \jobname.tex as the bib resource
  • Only step the entrycount:* value when labelprefix field is empty
  • Define an entrycount for all keywords

The resulting MWE is:

\documentclass{article}

\usepackage[style=numeric,
sorting=none,
% sorting=ydnt  % prefer to sort manually w/ \nocite commands
backend=biber,defernumbers,
]{biblatex}

\begin{filecontents*}{\jobname.bib}
@article{b, author={x y}, title={b}, journal={j}, year=1995, keywords={x, foo}}
@article{a, author={x y}, title={a}, journal={j}, year=1990, keywords={foo, x}}
@article{c, author={x y}, title={c}, journal={j}, year=2000, keywords={bar, y}}
@article{d, author={x y}, title={d}, journal={j}, year=2005, keywords={y, bar}}
\end{filecontents*}
\addbibresource{\jobname.bib}

\makeatletter
\define@key{blx@bib1}{keyword}{\xdef\mykeyword{#1}}
\makeatother

\newcommand{\stepKeywordCount}[1]{\csnumgdef{entrycount:#1}{\csuse{entrycount:#1}+1}}

\AtDataInput{%
  \iffieldundef{labelprefix}{%
    \begingroup%
      \edef\mytemp{\strfield{keywords}}
      \expandafter\forcsvlist\expandafter{\expandafter\stepKeywordCount\expandafter}\expandafter{\mytemp}%
    \endgroup%
  }{}%
}%

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

\begin{document}

Some text w/o citations.
% foo in reverse chronological order
\nocite{b} \nocite{a}
% bar in reverse chronological order
\nocite{d} \nocite{c}

\newrefcontext[labelprefix=F]
\printbibliography[keyword=foo, title=Foo]

\newrefcontext[labelprefix=B]
\printbibliography[keyword=bar, title=Bar]
\end{document}
  • This works, but perhaps my MWE wasn't complicated enough. It doesn't work if one of the keyword fields is changed to: {foo, x}. That better represents my actual .bib file. – mankoff Oct 18 '16 at 3:04
  • @mankoff I think that is much more involved. What happens if the keyword is {foo, bar} and {bar, foo}? Is the list of potential keywords known in advance? – StrongBad Oct 18 '16 at 4:00
  • Yes more advanced. This is very frustrating because this all worked fine in the <2016 version of TeXLive. Just to clarify, keywords={foo,bar} is two separate keywords, not one keyword with a comma. Currently keyword list isn't known. If needed, I can simplify to one keyword per entry so that the MWE you posted works, but would rather not. – mankoff Oct 18 '16 at 4:16
  • @mankoff see edits. You should edit your question to make it clearer what you want. – StrongBad Oct 18 '16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.