Biblatex / biber 反向编号带关键字过滤

Biblatex / biber 反向编号带关键字过滤

我对 (流行的) biblatex 更改感到困惑,2016 年的升级导致反向标签无法正常工作。有人提供了按类型过滤的解决方案这里这里此解决方案声称可以用于关键字过滤,但不能用于反向编号。以下是我的 MWE,它没有产生所需的结果,其应如下所示:

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). 

具体来说,1)按命令顺序定义的顺序\nocite{a},或者如果这不是一个选项,则按时间倒序排列,2)按关键字过滤,3)使用labelprefix

如果有人可以提供一些代码/建议来实现上述功能,我将不胜感激。

\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}

答案1

我可以通过一些小改动生成您想要的输出。话虽如此,我不确定该解决方案是否足够通用,可以满足实际目的。更改如下:

  • biblatex使用defernumbers选项加载
  • 使用\jobname.bib代替\jobname作为 bib 资源(否则 biber 使用\jobname.tex作为 bib 资源
  • entrycount:*仅当labelprefix字段为空时才步进值
  • entrycount为所有关键字定义一个

得到的 MWE 为:

\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}

相关内容