\nocite{} 在 bibresource 子集上

\nocite{} 在 bibresource 子集上

我想做类似的事情这个问题,但能够将 bibresource 的子集传递给\nocite{}。主要问题是\nocite{*}传递整个书目,然后反向编号方案使用 bibresource 中的参考文献总数,而不仅仅是被引用的参考文献。

因此,我要么需要一种新的方法来处理\nocite{}书目子集,要么需要一种方法来计算refsection

这是一份简历,我只是不想手动列出每个部分的引用,我宁愿这样做:“引用本节中的所有文章,并对其进行反向排序”。

下面的代码执行了相反的排序,但它考虑了所有\nocite{*}条目。所以我最终得到了类似这样的结果:

  • [17] 引用一篇文章
  • [16] 另一篇文章的引用
  • [15] 又一篇文章

而不是所需的 [3], [2], [1],同样,我不想通过手动输入每个键来提供整个列表(大于 3)。

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

% Count total number of entries in each refsection
\AtDataInput{%
  \csnumgdef{entrycount:\therefsection}{%
    \csuse{entrycount:\therefsection}+1}}

% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}    
\newrobustcmd*{\mkbibdesc}[1]{%
  \number\numexpr\csuse{entrycount:\therefsection}+1-#1\relax}

\newcommand{\printbibsection}[2]{%
  \begin{refsection}%
    \nocite{*}%
    \printbibliography[type={#1}, title={#2}, resetnumbers=true]%
  \end{refsection}}

\addbibresource{xampl.bib}

\begin{document}
    \printbibsection{article}{article in peer-reviewed journal} % Print all articles from the bibliography

    \printbibsection{book}{books} % Print all books from the bibliography
\end{document}

答案1

如果我理解了你的请求,看看你的 mwe,我认为没有refsection必要。

这是我的解决方案(由于您没有提供一些bibitem示例,所以我发明了它们):

\documentclass{article}
\usepackage[backend=biber,style=numeric,sorting=ydnt,defernumbers=true]{biblatex}

\newcounter{total}
\newcounter{totarticles}
\newcounter{totbooks}
\AtDataInput{%
    \ifentrytype{article}%
        {\stepcounter{totarticles}}%
        {}%
    \ifentrytype{book}%
        {\stepcounter{totbooks}}%
        {}%
    }%

% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}    
% Print labelnumber as actual number, plus item total, minus one
\newrobustcmd{\mkbibdesc}[1]{%
    \number\numexpr\thetotal+1-#1\relax}

\newcommand{\printbibsection}[2]{%
    \printbibliography[type={#1}, title={#2}, resetnumbers=true]%
    }%

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{article1,
  title={Title A},
  author={Author, Allegra},
  journal={Journal A},
  volume={1},
  pages={1},
  year={2001},
  publisher={Publisher A}
}
@article{article2,
  title={Title B},
  author={Buthor, Bee},
  journal={Journal B},
  volume={2},
  pages={2},
  year={2002},
  publisher={Publisher B}
}
@article{article3,
  title={Title C},
  author={Cuthor, Carla},
  journal={Journal C},
  volume={3},
  pages={3},
  year={2003},
  publisher={Publisher C}
}
@book{book1,
  title={Book A Title},
  author={Author, Allegra},
  year={2011},
  publisher={Book A Publisher}
}
@book{book2,
  title={Book B Title},
  author={Buthor, Bee},
  year={2012},
  publisher={Book B Publisher}
}
@article{article4,
  title={Title D},
  author={Duthor, Duck},
  journal={Journal D},
  volume={4},
  pages={4},
  year={2014},
  publisher={Publisher D}
}
@book{book3,
  title={Book C Title},
  author={Cuthor, Carla},
  year={2003},
  publisher={Book C Publisher}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
    \nocite{*}
    This document has \thetotbooks{} books and \thetotarticles{} articles. % I've added this line only to show the counters

    \setcounter{total}{\thetotarticles}
    \printbibsection{article}{article in peer-reviewed journal} % Print all articles from the bibliography

    \setcounter{total}{\thetotbooks}
    \printbibsection{book}{books} % Print all books from the bibliography
\end{document}  

在此处输入图片描述

如果您的选择标准不仅仅是基于类型,而是更为复杂,您可以创建特定的类别:

\documentclass{article}
\usepackage[backend=biber,style=numeric,sorting=ydnt,defernumbers=true]{biblatex}

\DeclareBibliographyCategory{article}
\DeclareBibliographyCategory{book}

\newcounter{total}
\newcounter{totarticles}
\newcounter{totbooks}
\AtDataInput{%
    \ifentrytype{article}% here you can put more complex selection criteria
        {\addtocategory{article}{\thefield{entrykey}}\stepcounter{totarticles}}%
        {}%
    \ifentrytype{book}%
        {\addtocategory{book}{\thefield{entrykey}}\stepcounter{totbooks}}%
        {}%
    }%

% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}    
%\makeatletter
% Print labelnumber as actual number, plus item total, minus one
\newrobustcmd{\mkbibdesc}[1]{%
    \number\numexpr\thetotal+1-#1\relax}

\newcommand{\printbibsection}[2]{%
    \printbibliography[category={#1}, title={#2}, resetnumbers=true]%
    }%

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{article1,
  title={Title A},
  author={Author, Allegra},
  journal={Journal A},
  volume={1},
  pages={1},
  year={2001},
  publisher={Publisher A}
}
@article{article2,
  title={Title B},
  author={Buthor, Bee},
  journal={Journal B},
  volume={2},
  pages={2},
  year={2002},
  publisher={Publisher B}
}
@article{article3,
  title={Title C},
  author={Cuthor, Carla},
  journal={Journal C},
  volume={3},
  pages={3},
  year={2003},
  publisher={Publisher C}
}
@book{book1,
  title={Book A Title},
  author={Author, Allegra},
  year={2011},
  publisher={Book A Publisher}
}
@book{book2,
  title={Book B Title},
  author={Buthor, Bee},
  year={2012},
  publisher={Book B Publisher}
}
@article{article4,
  title={Title D},
  author={Duthor, Duck},
  journal={Journal D},
  volume={4},
  pages={4},
  year={2014},
  publisher={Publisher D}
}
@book{book3,
  title={Book C Title},
  author={Cuthor, Carla},
  year={2003},
  publisher={Book C Publisher}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
    \nocite{*}

    \setcounter{total}{\thetotarticles}
    \printbibsection{article}{article in peer-reviewed journal} % Print all articles from the bibliography

    \setcounter{total}{\thetotbooks}
    \printbibsection{book}{books} % Print all books from the bibliography
\end{document}

相关内容