是否可以使用 Biblatex/Biber 并在文档代码内根据关键字向参考书目添加条目?

是否可以使用 Biblatex/Biber 并在文档代码内根据关键字向参考书目添加条目?

我想打印一份包含具有特定关键字的所有条目(可能还有一些附加条目)的参考书目。

我知道当我使用以下方法打印参考书目时,我可以通过关键字进行过滤

\printbibliography[keyword=<keyword>]

但这只会打印我引用的条目。当然,我可以使用

\nocite{*}

将所有条目添加到参考书目中,然后只打印我想要的条目。

.bbl然而,由于我的数据库非常庞大,这会使我的文件变得非常大。

另一种可能性是使用 Biber 或其他工具准备一个.bib仅包含带有关键字的条目的文档特定文件。但是,如果将带有关键字的其他条目添加到我的主要数据库文件中,则需要重新创建该文件。

这是一个可以使用的 MWE,带有注释以表明我希望它工作的方式;)以及它(几乎)工作方式的缺点。

排除明确引用的条目的问题对我来说不是什么大问题。我真正想解决的问题是将整个数据库内容添加到.bbl

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{new-stuff,
    author          =   {Watt, Brian},
    title           =   {Happy Times with Penguins},
    publisher       =   {Harvard University Press},
    address         =   {Cambridge, MA},
    year            =   1995,
    pagination      =   {section},
    keywords        =   {happy}}
@book{den-coll,
  author                =   {Till, Jr., Dennis E.},
    booktitle           =   {Penguin Land and Further North: Human Influence},
    title               =   {Penguin Land and Further North: Human Influence},
    publisher           =   {Oxford University Press},
    year                =   2008,
    address             =   {Oxford and New York},
    keywords            =   {penguin, human}}
@book{old-stuff,
  author                =   {Harvey, Jr., Dennis E.},
    booktitle           =   {Penguin Land and Further North: Human Influence},
    title               =   {Penguin Land and Further North: Human Influence},
    publisher           =   {Someone \& Daughters},
    year                =   1567,
    address             =   {Oxford},
    bookpagination      =   {paragraph},
    keywords            =   {penguin}}
\end{filecontents}
\documentclass{article}
\usepackage[defernumbers=true]{biblatex}
\bibliography{\jobname}
\begin{document}

\cite{old-stuff}

% what I would like to work
% \nocite[keyword=happy]
% \printbibliography

% what does work - except that \cite{old-stuff} is ignored and, more importantly, den-coll is added to the .bbl
\nocite{*}
\printbibliography[keyword=happy]

\end{document}

答案1

更新:现在可以使用 biber 2.14/biblatex 3.14 来实现,它们都位于 github 上的各自开发文件夹中[1][2]

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{new-stuff,
    author          =   {Watt, Brian},
    title           =   {Happy Times with Penguins},
    publisher       =   {Harvard University Press},
    address         =   {Cambridge, MA},
    year            =   1995,
    pagination      =   {section},
    keywords        =   {happy}}
@book{den-coll,
  author                =   {Till, Jr., Dennis E.},
    booktitle           =   {Penguin Land and Further North: Human Influence},
    title               =   {Penguin Land and Further North: Human Influence},
    publisher           =   {Oxford University Press},
    year                =   2008,
    address             =   {Oxford and New York},
    keywords            =   {penguin, human}}
@book{old-stuff,
  author                =   {Harvey, Jr., Dennis E.},
    booktitle           =   {Penguin Land and Further North: Human Influence},
    title               =   {Penguin Land and Further North: Human Influence},
    publisher           =   {Someone \& Daughters},
    year                =   1567,
    address             =   {Oxford},
    bookpagination      =   {paragraph},
    keywords            =   {penguin}}
\end{filecontents*}

\usepackage[defernumbers=true]{biblatex}
\addbibresource{\jobname.bib}
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[nocited, final]
      \step[fieldsource=keywords, notmatch=happy, final]
      \step[entrynull]
    }
  }
}

\begin{document}

\cite{old-stuff}

\nocite{*}
\printbibliography

\end{document}

这会在解析数据源时删除已删除\nocite或没有关键字的条目。

在此处输入图片描述

答案2

这是一个老问题,似乎没有真正令人满意的答案。但这里有一个解决方案,涉及一个perl脚本,只是为了好玩。

记得用 来运行它pdflatex --enable-write18

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{allentries.bib}
@book{new-stuff,
    author          =   {Watt, Brian},
    title           =   {Happy Times with Penguins},
    publisher       =   {Harvard University Press},
    address         =   {Cambridge, MA},
    year            =   1995,
    pagination      =   {section},
    keywords        =   {happy}}
@book{den-coll,
  author                =   {Till, Jr., Dennis E.},
    booktitle           =   {Penguin Land and Further North: Human Influence},
    title               =   {Penguin Land and Further North: Human Influence},
    publisher           =   {Oxford University Press},
    year                =   2008,
    address             =   {Oxford and New York},
    keywords            =   {penguin, human}}
@book{old-stuff,
  author                =   {Harvey, Jr., Dennis E.},
    booktitle           =   {Penguin Land and Further North: Human Influence},
    title               =   {Penguin Land and Further North: Human Influence},
    publisher           =   {Someone \& Daughters},
    year                =   1567,
    address             =   {Oxford},
    bookpagination      =   {paragraph},
    keywords            =   {penguin}}
\end{filecontents*}
\begin{filecontents*}{citekeyword.pl}
use strict;
use warnings;
use Text::BibTeX;
my $keyword = "happy"; # set keyword here
my $bibfile = Text::BibTeX::File->new("allentries.bib");
my $keywordcitefile = "keywordcites.tex";
open(my $fh, '>', $keywordcitefile) or
    die "Could not open file '$keywordcitefile' $!";
my $keywords;
my $entry;
while ($entry = Text::BibTeX::Entry->new($bibfile)) {
    next unless $entry->parse_ok;
    if ($entry->get("keywords")) {
        $keywords = "," . $entry->get("keywords") . ",";
        if ($keywords =~ /,$keyword,/) {
            print $fh "\\nocite{" . $entry->key . "}\n";
        }
    }
}
close $fh;
\end{filecontents*}
\immediate\write18{/usr/bin/perl citekeyword.pl}
\usepackage[defernumbers=true]{biblatex}
\addbibresource{allentries.bib}
\pagestyle{empty}
\begin{document}
\input{keywordcites.tex}
\cite{old-stuff}
\printbibliography
\end{document}

在此处输入图片描述

相关内容