使用全局标签来区分参考书目

使用全局标签来区分参考书目

我有几类书目条目,希望能够满足以下要求:

  1. 每个类别都属于我的“参考书目”部分的自己的子部分(例如,期刊文章、书籍等)。

  2. 我希望每个类别中的条目单独且反向编号,例如 [J10]-[J1]、[B3]-[B1] 等。

  3. 我的条目的不同类型不一定对应不同的bibtex类型(例如,@article条目可能分为两个类别)。我发现最简单的方法是将每个类别的条目保存在单独的.bib文件中。

  4. 对各个书目条目的引用可能会出现在文本的任何地方。

如果每个类别对应一个单独的refsection(见这里对于要求(2),只需在打印每个参考书目时添加选项即可prefixnumbers。不幸的是,refsections 似乎只产生本地标签,因此每个条目只能在其自己的 内引用refsection

如果上述内容正确,refsection则不能使用 s,而需要使用其他方式来分隔条目,例如通过关键字或使用biblatex 类别。但是我不知道如何应用 (2) 的解决方案,因为它似乎与refsections 相关。

有任何想法吗?

答案1

假设字段中指明了类别usera,以下文档演示了如何满足要求 1、2 和 4。

\documentclass{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[backend=biber,style=numeric,defernumbers,sorting=ydnt]{biblatex}
\usepackage{hyperref}

\makeatletter

% Store value passed to category option for \printbibliography
\apptocmd{\blx@key@category}{\edef\bbx@thecategory{\detokenize{#1}}}{}{}

% Initialize category counters
\def\bbx@initcategory#1{\csnumgdef{bbx@count@#1}{0}}
\forlistloop{\bbx@initcategory}{\blx@categories}

% Increment category counters
\def\bbx@countcategory#1{%
  \iffieldequalstr{usera}{#1}
    {\csnumgdef{bbx@count@#1}{\csuse{bbx@count@#1}+1}%
     \addtocategory{#1}{\thefield{entrykey}}%
     \listbreak}
    {}}
\AtDataInput{\forlistloop{\bbx@countcategory}{\blx@categories}}

% Print labelnumber as actual number, plus item total, minus one
\newrobustcmd*{\mkbibdesc}[1]{%
  \ifcitation
    {\number\numexpr\csuse{bbx@count@\thefield{usera}}+1-#1\relax}
    {\number\numexpr\csuse{bbx@count@\bbx@thecategory}+1-#1\relax}}

\makeatother

\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}

\begin{filecontents}{test.bib}
@Periodical{jcg,
  title = {Computers and Graphics},
  issuetitle = {Semantic {3D} Media and Content},
  volume = {35},
  number = {4},
  year = {2011},
  issn = {0097-8493}}
@Article{sarfraz,
  author = {M. Sarfraz and M. F. A. Razzak},
  title = {An algorithm for automatic capturing of the font outlines},
  journal = {Computers and Graphics},
  volume = {26},
  number = {5},
  pages = {795--804},
  year = {2002},
  issn = {0097-8493},
  doi = {10.1016/S0097-8493(02)00134-6}}
\end{filecontents}

\addbibresource{biblatex-examples.bib}
\addbibresource{test.bib}

\DeclareBibliographyCategory{primary}
\DeclareBibliographyCategory{secondary}

\defbibheading{bibliography}{\section*{Bibliography}}
\defbibheading{primary}{\subsection*{Primary references}}
\defbibheading{secondary}{\subsection*{Secondary references}}

\begin{document}
Filler text \parencite{companion,cms,sarfraz,nussbaum}.
\printbibheading
\printbibliography[heading=primary,category=primary,prefixnumbers={P}]
Filler text \parencite{ctan}.
\printbibliography[heading=secondary,category=secondary,prefixnumbers={S}]
Filler text \parencite{jcg}.\par\pagebreak
Filler text.
\end{document}

在此处输入图片描述

得益于上一个答案从 PLK 开始,biber 可以支持要求 3。以下sourcemap添加字段所需的数据usera。只需将其保存在名为 的单独文件中即可biber.conf

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <sourcemap>
    <maps datatype="bibtex" bmap_overwrite="1">
      <map>
        <per_datasource>biblatex-examples.bib</per_datasource>
        <map_step map_field_set="USERA" map_field_value="primary"/>
      </map>
      <map>
        <per_datasource>test.bib</per_datasource>
        <map_step map_field_set="USERA" map_field_value="secondary"/>
      </map>
    </maps>
  </sourcemap>
</config>

一些注意事项:

  • latex即使 biblatex 没有告诉您“重新运行 LaTeX”,新格式通常需要额外运行才能获得正确的标签编号。

  • sortcites=true新格式通常会使用或选项设置搞砸引文标签style=numeric-comp,除非所有引文列表都限制在单个类别中。例如,示例文档中的引文列表不符合此条件。

相关内容