Biblatex:两种具有不同风格和排序的书目

Biblatex:两种具有不同风格和排序的书目

我遇到的问题的MWE:

\documentclass{article}

\usepackage{filecontents}

\begin{filecontents}{biblatextest1.bib}
@BOOK{BookA03,
    author    = {Author Aaa},
    title     = {Some Title},
    publisher = {Some Publisher},
    year      = 2003
}
@BOOK{BookB02,
     author    = {Author Bbb},
    title     = {Some Title},
    publisher = {Some Publisher},
    year      = 2002
}
    \end{filecontents}

\begin{filecontents}{biblatextest2.bib}
@MISC{LinkC04,
    author  = {Author Ccc},
    title   = {Some Title},
    year    = 2004,
    url     = www.test1.com/bild.jpg,
    }
@MISC{LinkD01,
    author  = {Author Ddd},
    title   = {Some Title},
    year    = 2001,
    url     = www.test2.com/bild.jpg
}
\end{filecontents}

\usepackage[backend = biber, defernumbers = true, style = alphabetic]{biblatex}
\addbibresource{biblatextest1.bib}
\addbibresource{biblatextest2.bib}

%Append keywords to identify different bibliography entries.
\DeclareSourcemap{
  \maps[datatype=bibtex, overwrite]{
    \map{
      \perdatasource{biblatextest1.bib}
      \step[fieldset=KEYWORDS, fieldvalue=primary, append]
    }
    \map{
      \perdatasource{biblatextest2.bib}
      \step[fieldset=KEYWORDS, fieldvalue=secondary, append]
    }
  }
}

%Declare new sorting scheme for refernence bibliography.
\DeclareSortingScheme{appearance}{
    \sort{\citeorder}
}

%Copied from numeric.cbx to imitate numerical citations.
\providebool{bbx:subentry}
\newbibmacro*{citenum}{%Note: the original macro was called "cite". I did not redefine "cite", but instead defined a new macro "citenum", because the author-year citations use the "cite" macro too. "\renewbibmacro*{cite}" would have caused all the author-year citations to become numeric too.
  \printtext[bibhyperref]{%If you ever want to use hyperref
    \printfield{prefixnumber}%
    \printfield{labelnumber}%
    \ifbool{bbx:subentry}
      {\printfield{entrysetcount}}
      {}}}

%Copied from numeric.cbx to define a new numeric citation command for @online entries.
\DeclareCiteCommand{\cnume}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citenum}}%Note: this was originally "cite" but I changed it to "citenum" to avoid clashes with the author-year style.
  {\multicitedelim}
  {\usebibmacro{postnote}}


\begin{document}

The first two citations \cnume{LinkD01} and \cite{BookB02}. 
The others are \cnume{LinkC04} and \cite{BookA03}.

\printbibliography[title=Bibliography, keyword=primary]

%Redefine the bibliography environment to imitate the numeric citation style
\defbibenvironment{bibliographyNUM}
    {\list
    {\printfield[labelnumberwidth]{labelnumber}}
    {\setlength{\labelwidth}{\labelnumberwidth}%
    \setlength{\leftmargin}{\labelwidth}%
    \setlength{\labelsep}{\biblabelsep}%
    \addtolength{\labelsep}{1em}
    \addtolength{\leftmargin}{\labelsep}%
    \setlength{\itemsep}{\bibitemsep}%
    \setlength{\parsep}{\bibparsep}}%
    \renewcommand*{\makelabel}[1]{\hss##1}}
    {\endlist}
    {\item}
    \DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}\hspace{-1.1em}}

\newrefcontext[sorting=none]
\printbibliography[env=bibliographyNUM,title=References, keyword=secondary, resetnumbers]
\end{document}

问题:我需要两个书目,第一个采用字母格式并按作者姓名排序。第二个采用数字格式并按引用顺序排序。两者没有共同的参考文献。不知何故我在 biblatex 中搜索了类似这样的内容:

\bibliographystyle{style = alphabetic}
\printbibliography{books.bib} 
\bibliographystyle{style = numerical, sorting = none}  
\printbibliography{links.bib}

我以为 biblatex 是专门为处理多个参考书目而编写的,但我没有找到除了 MWE 中显示的方法(这显然是一种 hack)之外的任何其他方法。实际上,它工作得很好,直到我想要另一种排序方式。当我使用

\newrefcontext[sorting=none]

引用数量变为零。

答案1

如果您将该选项传递labelnumber给,biblatex您甚至可以使用数字引用style=alphabetic

cite 命令可以根据关键字进行切换,因此\cite无论如何您都可以对所有条目使用keyword

对于数字书目,我们必须定义一个新的书目环境来打印数字引用。bibliographyNUM直接从中复制numeric.bbx。要设置书目的排序,只需说

\newrefcontext[sorting=none]
\printbibliography[env=bibliographyNUM, title=References, keyword=secondary, resetnumbers]

在数字书目之前。前一个书目将使用anyt适合字母样式书目的全局排序方案。如果有必要将排序方案分配保持在本地(因为数字书目位于字母书目之前),则可以使用

\begin{refcontext}[sorting=none]
\printbibliography[env=bibliographyNUM, title=References, keyword=secondary, resetnumbers]
\end{refcontext}

平均能量损失

\documentclass{article}
\usepackage[style=alphabetic, labelnumber, defernumbers=true,  backend=biber]{biblatex}
\usepackage{hyperref}

% Append keywords to identify different bibliography entries.
% appendstrict only appends if the field is nonempty,
% we use that to add a comma to avoid mushing together two keywords
\DeclareSourcemap{
  \maps[datatype=bibtex, overwrite]{
    \map{
      \perdatasource{biblatextest1.bib}
      \step[fieldset=KEYWORDS, fieldvalue={, }, appendstrict]
      \step[fieldset=KEYWORDS, fieldvalue=primary, append]
    }
    \map{
      \perdatasource{biblatextest2.bib}
      \step[fieldset=KEYWORDS, fieldvalue={, }, appendstrict]
      \step[fieldset=KEYWORDS, fieldvalue=secondary, append]
    }
  }
}

\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}
\renewbibmacro*{cite}{%
  \printtext[bibhyperref]{%
    \printfield{labelprefix}%
    \ifkeyword{secondary}
      {\printfield{labelnumber}}
      {\printfield{labelalpha}%
       \printfield{extraalpha}}}}

\defbibenvironment{bibliographyNUM}
  {\list
     {\printtext[labelnumberwidth]{%
        \printfield{labelprefix}%
        \printfield{labelnumber}}}
     {\setlength{\labelwidth}{\labelnumberwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{\hss##1}}
  {\endlist}
  {\item}

\begin{filecontents}{biblatextest1.bib}
@BOOK{BookA03,
  author    = {Author Aaa},
  title     = {Some Title},
  publisher = {Some Publisher},
  year      = 2003,
  keywords  = {hello},
}
@BOOK{BookB02,
  author    = {Author Bbb},
  title     = {Some Title},
  publisher = {Some Publisher},
  year      = 2002,
}
\end{filecontents}
\begin{filecontents}{biblatextest2.bib}
@MISC{LinkC04,
  author    = {Author Ccc},  
  title     = {Some Title},
  year      = 2004,
  url       = {www.test1.com/bild.jpg},
  keywords  = {bye},
}
@MISC{LinkD01,
  author  = {Author Ddd},
  title   = {Some Title},
  year    = 2001,
  url     = {www.test2.com/bild.jpg},
}
\end{filecontents}
\addbibresource{biblatextest1.bib}
\addbibresource{biblatextest2.bib}

\begin{document}
The first two citations \cite{LinkD01} and \cite{BookB02}. 
The others are \cite{LinkC04} and \cite{BookA03}.

\printbibliography[title=Bibliography, keyword=primary]

\newrefcontext[sorting=none]
\printbibliography[env=bibliographyNUM, title=References, keyword=secondary, resetnumbers]
\end{document}

示例输出

答案2

非常感谢。我想分享我对这个问题的改编版本。我通过定义不同的引用词将我的 Bib 分为几类。它是从 Driftnet 来源复制而来的,尤其是biblatex:按不同的 .bib 文件分类的多个参考书目所以这不是最佳实践,但它确实有效。希望 biblatex 将来能够原生支持混合参考书目样式。

\documentclass[fontsize=11pt,a4paper,bibliography=totoc]{scrbook}
\usepackage[style=alphabetic,backend=biber,defernumbers = true]{biblatex} 
\addbibresource{bib/references.bib}

\DeclareBibliographyCategory{pubA}
\DeclareBibliographyCategory{contA}
\DeclareBibliographyCategory{refs}
\DeclareBibliographyCategory{relT}

\defbibheading{pubA}{\section*{Publications of the Author}}
\defbibheading{contA}{\section*{Contributions of the Author}}
\defbibheading{refs}{\section*{References}}
\defbibheading{relT}{\section*{Related Theses}}

\newcommand*{\citeA}[2][]{\addtocategory{pubA}{#2}\cite[#1]{#2}}
\newcommand*{\citeC}[2][]{\addtocategory{contA}{#2}\cite[#1]{#2}}
\newcommand*{\citeR}[2][]{\addtocategory{refs}{#2}\cite[#1]{#2}}

\renewbibmacro*{cite}{%
\printtext[bibhyperref]{%
 \printfield{labelprefix}%
    \ifcategory{refs}
   {\printfield{labelnumber}}
   {\printfield{labelalpha}%
    \printfield{extraalpha}}}}

\newcommand*{\citeT}[2][]{\addtocategory{relT}{#2}\cite[#1]{#2}}

\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}} % important to get [] in bib
\defbibenvironment{refsEnv}
{\list
  {\printtext[labelnumberwidth]{%
    \printfield{prefixnumber}%
    \printfield{labelnumber}}}
  {\setlength{\labelwidth}{\labelnumberwidth}%
   \setlength{\leftmargin}{\labelwidth}%
   \setlength{\labelsep}{\biblabelsep}%
   \addtolength{\leftmargin}{\labelsep}%
   \setlength{\itemsep}{\bibitemsep}%
   \setlength{\parsep}{\bibparsep}}%
   \renewcommand*{\makelabel}[1]{\hss##1}}
{\endlist}
{\item}
\begin{document}

some text \citeR{<citekey>} \citeT{<citekey>}...


\printbibheading[heading=bibintoc]
\printbibliography[heading=subbibliography,title={Publications of the Author},category=pubA]
\printbibliography[heading=subbibliography,title={Contributions of the Author},category=contA]
\newrefcontext[sorting=none]
\printbibliography[heading=subbibliography,title={References},category=refs,env=refsEnv,resetnumbers]
\printbibliography[heading=subbibliography,title={Related Theses},category=relT]

\end{document}

答案3

按照@moewe 所说的使用数字引用style=alphabetic

对于不同的排序顺序,有一种更简单的方法,即refcontext环境,它采用排序选项。首先,使用 Biblatex 生成主要参考书目:

\printbibliography[title=Bibliography, keyword=primary]

refcontext然后,通过将其括在作为参数的文件中,创建具有不同排序、过滤器和样式的第二个文件。

\begin{refcontext}[sorting=ydnt]{} % sort chronologically
    \printbibliography[title=References, keyword=secondary, resetnumbers] 
\end{refcontext}

{}最后一个参数为空,refcontext可让您创建一个临时环境,而无需在其他地方声明任何内容。

当我的学校要求我在论文结尾处附上简历时,我就用了这个,因此除了论文中通常的 AZ 书目外,我还需要按时间倒序生成我的作品书目。它比我以前做的要干净得多。

相关内容