biblatex 群组字段过滤器

biblatex 群组字段过滤器

这个答案解释如何创建一个仅包含按其列出的参考书目条目的过滤\printbibliography字段==值是真的。

因此,为了检查某个条目是否属于 Group1,我将定义类似于以下内容的过滤器:

\defbibcheck{Group1}{ \iffieldequalstr{groups}{Group1}{}{\skipentry} }

但这显然行不通,因为我实际上应该检查 Group1 是否是列表组的一部分。

如何才能实现这一点呢?

这是一个 M(不是)WE:

% !TeX TXS-program:bibliography = txs:///biber
\documentclass{article}

\usepackage[style=authoryear,backend=biber]{biblatex}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
  groups = {Group1,Group2},
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
  groups = {Group1},
}
@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
  groups = {Group2},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}
\defbibcheck{Group1}{ \iffieldequalstr{groups}{Group1}{}{\skipentry} }
\printbibliography[check=Group1]

\end{document}

答案1

有两个主要原因导致它不能按预期工作。

  1. 正如所提到的保罗·斯坦利 在评论中该字段groups不是标准字段,因此 Biber 无法识别。这意味着该字段的内容groups不会写入文件.bbl,进而意味着biblatex无法访问其内容。

    你必须声明groups按照以下方式声明该字段将字段“tome”添加到 biblatex 条目

  2. 其次,更严重的是,\iffieldequalstr{<field>}{<string>}您只将字段的(整个)内容<field>与字符串进行比较<string>。这意味着\iffieldequalstr{groups}{Group1}当 groups 为 时, 会产生 false。Paul groups = {Group1,Group2},Stanley 的评论中也提到了这一点。

喜欢古斯布斯保罗·斯坦利我建议您查看一下,keywords因为该字段旨在将条目过滤到组中。

\documentclass{article}

\usepackage[style=authoryear,backend=biber]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
  author   = {Author, A.},
  year     = {2001},
  title    = {Alpha},
  keywords = {Group1,Group2},
}
@misc{B02,
  author   = {Buthor, B.},
  year     = {2002},
  title    = {Bravo},
  keywords = {Group1},
}
@misc{C03,
  author   = {Cuthor, C.},
  year     = {2003},
  title    = {Charlie},
  keywords = {Group2},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}

\printbibliography[keyword=Group1]
\end{document}

如果您已经用而groups不是填充了数百个条目,则keywords可以使用 Biber 重新映射字段。

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=groups, final]
      \step[fieldset=keywords, fieldvalue={,}, append]
      \step[fieldset=keywords, origfieldval, append]
      \step[fieldsource=keywords, match=\regexp{\A,}, replace={}]
    }
  }
}

编辑现在使用古斯布斯' 方法来自\DeclareSourceMap 不起作用以避免在没有项目的情况下使用前导逗号。


如果由于某种原因,您执着于某个groups字段的想法并且根本不想参与keywords,这里有一个粗略的测试实现,它循环遍历具有逗号分隔值的字段并检查是否Group1包含在该groups字段中的列表元素。

\documentclass{article}

\usepackage{filecontents}

% make the groups field known to biblatex
\begin{filecontents*}{groups.dbx}
\DeclareDatamodelFields[type=field,datatype=literal]{groups}
\DeclareDatamodelEntryfields{groups}
\end{filecontents*}
\usepackage[style=authoryear,backend=biber,datamodel=groups]{biblatex}

% traverse the groups field to find a match
\makeatletter
\newtoggle{bastianblx@isgroup}

\newcommand*{\bastianblx@ifmatch}[2]{%
  \ifstrequal{#1}{#2}
    {\toggletrue{bastianblx@isgroup}\listbreak}
    {}}

% switch the order of the arguments for easier \expandafter work
\newcommand*{\bastian@forcsvlist}[2]{%
  \forcsvlist{#2}{#1}}

\defbibcheck{Group1}{%
  \togglefalse{bastianblx@isgroup}%
  % 31 \expandafters for five levels of expansion
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter
  \bastian@forcsvlist
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\expandafter\expandafter
  \expandafter
  {\thefield{groups}}{\bastianblx@ifmatch{Group1}}%
  \iftoggle{bastianblx@isgroup}{}{\skipentry}%
}
\makeatother

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year   = {2001},
  title  = {Alpha},
  groups = {Group1,Group2},
}
@misc{B02,
  author = {Buthor, B.},
  year   = {2002},
  title  = {Bravo},
  groups = {Group1},
}
@misc{C03,
  author = {Cuthor, C.},
  year   = {2003},
  title  = {Charlie},
  groups = {Group2},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}

\printbibliography[check=Group1]
\end{document}

所有解决方案显示

包含两个项目的参考书目:<code>A01</code> 和 <code>B02</code>

相关内容