使用不同类别的 biblatex 书目进行反向编号

使用不同类别的 biblatex 书目进行反向编号

我使用(见下文)对参考书目中的条目设置了不同的类别(过滤器) biblatex。我想为条目添加编号。由于条目按年份降序排列,因此(每个类别中的)编号也应递减。

基本上,我看到了两条路可走:

1)第一种是使用style=numeric并提出解决方案这里。然而,在我的(不那么简单的)示例中,出现了两个问题。首先,数字不会为每个类别重新开始(而是继续)。其次,我得到了奇怪的数字(最多 400),尽管我只有几个包含相同关键字的条目。

2)我发现第二个(可能更容易)这里。这实际上是一个好主意(并允许您指定编号等),但我无法弄清楚两件事:首先,如何获得递减编号。其次,如果您有 > 9 个条目,则为标签保留的空间太小,并且第 10 个条目与之前的 9 个条目不垂直对齐。这可能可以用 进行调整itemindent,但当我尝试时,调整没有效果。

\documentclass{scrartcl}

% packages
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[
backend=bibtex,
style=authoryear,% numeric,
sorting=ydnt% sort by year (descending), name, title
]{biblatex}

% create dummy .bib file
\usepackage{filecontents}
\begin{filecontents*}{mybib.bib}
@article{mykey1,
    author={I Me},
    journal={Journal of LaTeX questions},
    pages={1--10},
    title={My first LaTeX problem},
    volume={2},
    number={2},
    year={2011},
        keywords={published}}

@article{mykey2,
    author={I Me},
    journal={Journal of LaTeX questions},
    pages={1--10},
    title={My second LaTeX problem},
    volume={1},
    number={1},
    year={2012},
        keywords={submitted}}

@article{mykey3,
    author={I Me},
    journal={Journal of LaTeX questions},
    pages={1--10},
    title={My third LaTeX problem},
    volume={3},
    number={3},
    year={2013},
        keywords={submitted}}
\end{filecontents*}

% bibliography settings
\setlength{\bibhang}{1em}% separate bibitems by indentation
\defbibheading{submitted}{\large\sffamily Submitted}% heading
\defbibheading{published}{\large\sffamily Published}% heading
\defbibfilter{submitted}{keyword=submitted}% filter
\defbibfilter{published}{keyword=published}% filter
\addbibresource{mybib.bib}% bibliography data

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

% Idea 2)
\defbibenvironment{bibliography}
{\enumerate{}
{\setlength{\leftmargin}{\bibhang}% => adjustments seem to have no effect
\setlength{\itemindent}{-\leftmargin}% => adjustments seem to have no effect
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endenumerate}
{\item}


\begin{document}
\section*{Publications}
\nocite{*}
\printbibliography[heading=submitted, filter=submitted]
\noindent\printbibliography[heading=published, filter=published]
\end{document}

更多信息

1)bibtex因为这里特意使用了后端(以便自动texi2pdf运行biblatex

2) 这个问题来自一份简历。我的想法是使用\nocite{*}(而不是特定的\cite{...}s,这样我就不必关心更新参考资料了)。

3) 在简历中,我显示了“准备中”、“已提交”、“已发布”、“图书贡献”、“图书”等类别。我使用以下过滤来获得这些信息:

\defbibfilter{inpreparation}{type=article and keyword=inpreparation}
\defbibfilter{submitted}{type=article and keyword=submitted}
\defbibfilter{published}{type=article and keyword=published}
\defbibfilter{bookcontrib}{type=incollection and ( keyword=inpreparation or keyword=submitted or keyword=published )}
\defbibfilter{book}{type=book and ( keyword=inpreparation or keyword=submitted or keyword=published )}

答案1

第一个解决方案mention 不起作用,因为您的参考书目是按关键字而不是按参考部分划分的。只要您使计数器特定于关键字,一般方法仍然适用。

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

这种格式有一些限制:

  • 它仅适用于关键字过滤,不适用于通过定义的更通用的过滤器\defbibfilter
  • 项目标签宽度对应于\labelnumberwidth。此长度会根据文件中的所有条目依次增加以容纳最大的标签数bbl。因此,如果关键字过滤掉许多条目,您可能会发现宽度太大。

如果您不打算在引文中使用标签编号(例如,只能通过 访问条目\nocite),那么解决上述限制的一个简单方法是修补\printbibligraphy。以下示例演示了这种方法。它还会以 样式打印条目authoryear

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

\defbibfilter{primary}{type=article and keyword=primary}
\defbibfilter{secondary}{keyword=secondary}
\defbibfilter{other}{not type=article and not type=manual and not keyword=secondary}

\makeatletter
\patchcmd{\blx@printbibliography}
  {\blx@bibliography\blx@tempa}
  {\setcounter{bibitemtotal}{0}%
   \setlength{\labelnumberwidth}{0pt}%
   \begingroup
   \def\do##1{\stepcounter{bibitemtotal}}%
   \dolistloop{\blx@tempa}%
   \endgroup
   \blx@setlabwidth{\labelnumberwidth}{%
     \csuse{abx@ffd@*@labelnumberwidth}{\arabic{bibitemtotal}}}%
   \blx@bibliography\blx@tempa}{}{}
\makeatother

\newcounter{bibitemtotal}
\newrobustcmd*{\mkbibdesc}[1]{%
  \number\numexpr\value{bibitemtotal}+1-#1\relax}
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}

\defbibenvironment{bibliography}
  {\list
     {\printtext[labelnumberwidth]{\printfield{labelnumber}}}
     {\setlength{\labelwidth}{\labelnumberwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{\hss##1}}
  {\endlist}
  {\item}

\begin{filecontents}{\jobname.bib}
@article{glashow,
  author = {Glashow, Sheldon},
  title = {Partial Symmetries of Weak Interactions},
  journaltitle = {Nucl.~Phys.},
  volume = {22},
  date = {1961},
  pages = {579--588},
  keywords = {stdmodel,primary}}
@article{weinberg,
  author = {Weinberg, Steven},
  title = {A Model of Leptons},
  journaltitle = {Phys.~Rev.~Lett.},
  volume = {19},
  date = {1967},
  pages = {1264--1266},
  keywords = {stdmodel,primary}}
@inproceedings{salam,
  author = {Salam, Abdus},
  editor = {Svartholm, Nils},
  title = {Weak and Electromagnetic Interactions},
  booktitle = {Elementary particle theory},
  booktitleaddon = {Proceedings of the Eighth Nobel Symposium},
  location = {Stockholm},
  date = {1968},
  pages = {367--377},
  keywords = {primary,stdmodel}}
@book{augustine,
  author = {Augustine, Robert L.},
  title = {Heterogeneous catalysis for the synthetic chemist},
  publisher = {Marcel Dekker},
  location = {New York},
  date = {1995},
  keywords = {secondary}}
@book{kullback,
  title = {Information Theory and Statistics},
  author = {Kullback, Solomon},
  year = {1959},
  publisher = {John Wiley \& Sons},
  location = {New York}}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{oberdiek-bundle.bib}

\begin{document}
\nocite{*}
\printbibliography[filter=primary,title={Primary articles}]
\printbibliography[filter=secondary,title={Secondary works},resetnumbers]
\printbibliography[filter=other,title={Other works},resetnumbers]
\end{document}

相关内容