Biblatex:在引文中添加前缀

Biblatex:在引文中添加前缀

我希望参考书目中的条目在文本和参考书目中加上前缀,使得它们的形式为 [A1], [B1] 和 [C1]。

我读过的文件比布拉特克斯并找到了第 3.7.10 节。此外,我还找到了官方的 biblatex 示例文件,这似乎正是我需要的。但是,我不想调整 bib 文件,在这个例子中,他们使用了关键字。

实际上,我手头有一份使用 multibib 来解决这个问题的文档,现在我想使用 biblatex,但如果这对合著者来说更困难,这将不被接受。

\documentclass{report}
\usepackage[sorting=none, backend=biber]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{references.bib}
@book{knuth1986texbook,
  title={The texbook},
  author={Knuth, D.E. and Bibby, D.},
  volume={1993},
  year={1986},
  publisher={Addison-Wesley}
}
@article{knuth1977fast,
  title={Fast pattern matching in strings},
  author={Knuth, D.E. and Morris Jr, J.H. and Pratt, V.R.},
  journal={SIAM journal on computing},
  volume={6},
  number={2},
  pages={323--350},
  year={1977},
  publisher={SIAM}
}
@inproceedings{knuth1970simple,
  title={Simple word problems in universal algebras},
  author={Knuth, D.E. and Bendix, P.B.},
  booktitle={Computational problems in abstract algebra},
  volume={263},
  pages={297},
  year={1970}
}
\end{filecontents}
\addbibresource{references.bib}


\DeclareBibliographyCategory{catA}
\DeclareBibliographyCategory{catB}
\DeclareBibliographyCategory{catC}

\newcommand{\citeA}[1]{\addtocategory{catA}{#1}\cite{#1}}
\newcommand{\citeB}[1]{\addtocategory{catB}{#1}\cite{#1}}
\newcommand{\citeC}[1]{\addtocategory{catC}{#1}\cite{#1}}

\begin{document}
See \citeA{knuth1986texbook} and \citeB{knuth1977fast} and \citeC{knuth1970simple,knuth1977fast}.

\printbibliography[title={Category A},category=catA]
\printbibliography[title={Category B},category=catB]
\printbibliography[title={Category C},category=catC]
\end{document}

答案1

如果你的类别不相交,则以下内容有效

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

\DeclareBibliographyCategory{catA}
\DeclareBibliographyCategory{catB}
\DeclareBibliographyCategory{catC}

\newcommand*{\AddCiteToCategory}[1]{%
  \AtNextCite{\AtEachCitekey{\addtocategory{#1}{\thefield{entrykey}}}}}

\newcommand{\citeA}{\AddCiteToCategory{catA}\autocite}
\newcommand{\citeB}{\AddCiteToCategory{catB}\autocite}
\newcommand{\citeC}{\AddCiteToCategory{catC}\autocite}

\addbibresource{biblatex-examples.bib}

\begin{document}
See \citeA{worman} and \citeB{sigfridsson} and \citeC{nussbaum,geer}.

\newrefcontext[labelprefix=A]
\printbibliography[title={Category A},category=catA]
\newrefcontext[labelprefix=B]
\printbibliography[title={Category B},category=catB]
\newrefcontext[labelprefix=C]
\printbibliography[title={Category C},category=catC]
\end{document}

不需要显式地分配 refcontext,因为每个条目都会自动获取最后打印的 refcontext。

如果一个条目出现在多个上下文中,该方法也有效,但条目将始终使用打印它的最后一个上下文。因此 [B1] 引用将变成 [C1]。


在您的设置中,允许有重叠的上下文,但您仍然需要正在使用的 cite 命令的上下文,我们需要一种更复杂的方法。

我们通过使用 手动指向特定的 refcontext 来覆盖上次打印条目时biblatex通常会获取的refcontext 。\blx@getrefcontext\SetRefcontext

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

\DeclareBibliographyCategory{catA}
\DeclareBibliographyCategory{catB}
\DeclareBibliographyCategory{catC}

\makeatletter
% we want to be future proof
\providerobustcmd*{\blx@kv@setkeys}{\setkeys}

% this is basically what \assignrefcontextentries does
% but on a slightly different level
\newrobustcmd*{\SetRefcontext}[1][]{%
  \begingroup
  \edef\blx@tempa{\blx@sorting}%
  \def\blx@tempb{global}%
  \let\blx@tempc\@empty%
  \def\blx@tempd{global}%
  \def\blx@tempe{global}%
  \blx@kv@setkeys{blx@assignrefcontext}{#1}%
  \blx@edef@refcontext{\blx@tempa/\blx@tempb/\blx@tempc/\blx@tempd/\blx@tempe}%
  \edef\blx@tempa{\endgroup
    \noexpand\def\noexpand\blx@refcontext@context{\blx@refcontext@context}}%
  \blx@tempa}

% hard-set the refcontext
% make sure entries are added to category
\newcommand*{\MultibibCiteHelper}[1]{%
  \AtNextCite{%
    \def\blx@getrefcontext##1{%
      \let\blx@refcontext@context@saved\blx@refcontext@context
      \SetRefcontext[labelprefix=#1]}%
    \AtEachCitekey{%
      \addtocategory{cat#1}{\thefield{entrykey}}}}}
\makeatother


\newcommand{\citeA}{\MultibibCiteHelper{A}\autocite}
\newcommand{\citeB}{\MultibibCiteHelper{B}\autocite}
\newcommand{\citeC}{\MultibibCiteHelper{C}\autocite}

\addbibresource{biblatex-examples.bib}

\begin{document}
See \citeA{worman} and \citeB{sigfridsson} and \citeC{nussbaum,sigfridsson}.

\newrefcontext[labelprefix=A]
\printbibliography[title={Category A},category=catA]
\newrefcontext[labelprefix=B]
\printbibliography[title={Category B},category=catB]
\newrefcontext[labelprefix=C]
\printbibliography[title={Category C},category=catC]
\end{document}

参见[A1]和[B1]和[C2, C1]。

答案2

我自己解决了这个问题。但是,有些事情我还是不太清楚。

\documentclass{report}
\usepackage[sorting=none, backend=biber, defernumbers]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{references.bib}
@book{knuth1986texbook,
  title={The texbook},
  author={Knuth, D.E. and Bibby, D.},
  volume={1993},
  year={1986},
  publisher={Addison-Wesley}
}
@article{knuth1977fast,
  title={Fast pattern matching in strings},
  author={Knuth, D.E. and Morris Jr, J.H. and Pratt, V.R.},
  journal={SIAM journal on computing},
  volume={6},
  number={2},
  pages={323--350},
  year={1977},
  publisher={SIAM}
}
@inproceedings{knuth1970simple,
  title={Simple word problems in universal algebras},
  author={Knuth, D.E. and Bendix, P.B.},
  booktitle={Computational problems in abstract algebra},
  volume={263},
  pages={297},
  year={1970}
}
\end{filecontents}
\addbibresource{references.bib}


\DeclareBibliographyCategory{catA}
\DeclareBibliographyCategory{catB}
\DeclareBibliographyCategory{catC}
\DeclareRefcontext{labelprefix=A}{refcatA}
\DeclareRefcontext{labelprefix=B}{refcatB}
\DeclareRefcontext{labelprefix=C}{refcatC}

\newcommand{\citeA}[1]{%
    \begin{refcontext}[labelprefix=A]{refcatA}%
    \assignrefcontextentries[labelprefix=A]{#1}%
    \addtocategory{catA}{#1}%
    \cite{#1}%
    \end{refcontext}%
}
\newcommand{\citeB}[1]{%
    \begin{refcontext}[labelprefix=B]{refcatB}%
    \assignrefcontextentries[labelprefix=B]{#1}%
    \addtocategory{catB}{#1}%
    \cite{#1}%
    \end{refcontext}%
}
\newcommand{\citeC}[1]{%
    \begin{refcontext}[labelprefix=C]{refcatC}%
    \assignrefcontextentries[labelprefix=C]{#1}%
    \addtocategory{catC}{#1}%
    \cite{#1}%
    \end{refcontext}%
}

\begin{document}
See \citeA{knuth1986texbook} and \citeB{knuth1977fast} and \citeC{knuth1970simple,knuth1977fast}.
\begin{refcontext}[labelprefix=A]{refcatA}
\printbibliography[title={Category A},category=catA]
\end{refcontext}
\begin{refcontext}[labelprefix=B]{refcatB}
\printbibliography[title={Category B},category=catB]
\end{refcontext}
\begin{refcontext}[labelprefix=C]{refcatC}
\printbibliography[title={Category C},category=catC]
\end{refcontext}


\end{document}

相关内容