书目计数器、逆序编号和关键词

书目计数器、逆序编号和关键词

请参阅下面的 mwe

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

输出内容如下:

在此处输入图片描述

问题是,如何让 J 的 bib 条目的标签为 1 而不是 2?通过关键字功能,我们正在过滤传递给cvsectionnum,但似乎计数器是在过滤之前确定的,因此超出范围且标签不连续。

这个帖子也可能提供额外的背景信息。

答案1

我使用一个额外的计数器来计算条目,这需要两次编译。

filecontents 包已经过时了,我用 [overwrite] 选项替换了它。

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

在此处输入图片描述

答案2

问题来自于

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

我变成了

{\printfield[labelnumberwidth]{labelnumber}}%

通过从中汲取一些灵感biblatex 用户指南第 156 页。

结果是:

在此处输入图片描述

相关内容