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

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

答案莫威针对这个问题Biblatex:两种具有不同风格和排序的书目几乎就是我想要实现的。由于我的文档中有大量条目,我更愿意使用样式numeric-comp而不是仅仅使用numeric。我怎样才能做到这一点?
扩展的 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,
}
@BOOK{BookB09,
    author    = {Author Jjj},
    title     = {Some Title},
    publisher = {Some Publisher},
    year      = 2002,
}
@BOOK{BookB10,
    author    = {Author Kkk},
    title     = {Some Title},
    publisher = {Some Publisher},
    year      = 2002,
}
@BOOK{BookB11,
    author    = {Author Lll},
    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},
}
@MISC{LinkD05,
    author  = {Author Eee},  
    title   = {Some Title},
    year    = 2004,
    url     = {www.test3.com/bild.jpg},
}
@MISC{LinkD06,
    author  = {Author Fff},
    title   = {Some Title},
    year    = 2001,
    url     = {www.test4.com/bild.jpg},
}
@MISC{LinkD07,
    author  = {Author Ggg},  
    title   = {Some Title},
    year    = 2004,
    url     = {www.test5.com/bild.jpg},
}
@MISC{LinkD08,
    author  = {Author Hhh},
    title   = {Some Title},
    year    = 2001,
    url     = {www.test6.com/bild.jpg},
}
\end{filecontents}

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

\usepackage{hyperref}

%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]
        }
    }
}

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


\defbibenvironment{bibliographyNUM}
{\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}

\assignrefcontextkeyws[sorting=none]{secondary}
\begin{document}

    The first two citations \cite{LinkD07,LinkC04} and \cite{BookB10,BookB11,BookB02,BookB09}. 
    The others are \cite{LinkD08,LinkD01,LinkD05,LinkD06} and \cite{BookA03}.

    \printbibliography[title=Bibliography, keyword=primary]

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

在此处输入图片描述

提前谢谢你的帮助。

答案1

我认为我设法基于numeric-comp并取得某些成果,然后尝试将labelalpha信息带到该shorthand领域,该领域由本身处理numeric-comp,因此您不需要重新定义cite宏/命令。

我最初尝试在源映射中执行此操作,但不知何故它不起作用,所以我最终使用\AtEveryCitekey它。

您可能仍需要调整排序。您还会注意到,主要和次要参考文献的混合引用不太理想(在这种情况下,我无法找出决定排序的因素)。但总体结果看起来还算合理。

\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,
}
@BOOK{BookB09,
    author    = {Author Jjj},
    title     = {Some Title},
    publisher = {Some Publisher},
    year      = 2002,
}
@BOOK{BookB10,
    author    = {Author Kkk},
    title     = {Some Title},
    publisher = {Some Publisher},
    year      = 2002,
}
@BOOK{BookB11,
    author    = {Author Lll},
    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},
}
@MISC{LinkD05,
    author  = {Author Eee},  
    title   = {Some Title},
    year    = 2004,
    url     = {www.test3.com/bild.jpg},
}
@MISC{LinkD06,
    author  = {Author Fff},
    title   = {Some Title},
    year    = 2001,
    url     = {www.test4.com/bild.jpg},
}
@MISC{LinkD07,
    author  = {Author Ggg},  
    title   = {Some Title},
    year    = 2004,
    url     = {www.test5.com/bild.jpg},
}
@MISC{LinkD08,
    author  = {Author Hhh},
    title   = {Some Title},
    year    = 2001,
    url     = {www.test6.com/bild.jpg},
}
\end{filecontents}

\usepackage[style = numeric-comp, labelalpha, defernumbers]{biblatex}
\addbibresource{biblatextest1.bib}
\addbibresource{biblatextest2.bib}

\usepackage{hyperref}

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

\makeatletter
\newcommand*{\labelalphatoshorthand}{\csdef{abx@field@shorthand}{\strfield{labelprefix}\strfield{labelalpha}\strfield{extraalpha}}}
\makeatother

\AtEveryCitekey{\ifkeyword{primary}{\labelalphatoshorthand}{}}

\DeclareFieldFormat{labelalphawidth}{\mkbibbrackets{#1}}

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

\begin{document}

The first two citations \cite{LinkD07,LinkC04} and
\cite{BookB10,BookB11,BookB02,BookB09}.

Mixing both primary and secondary
\cite{LinkD08,LinkD01,LinkD05,LinkD06,BookB10,BookB11,BookB02,BookB09}.

The others are \cite{LinkD08,LinkD01,LinkD05,LinkD06,LinkD07}
and \cite{BookA03}.

\printbibliography[env=bibliographyALPHA, title=Bibliography, keyword=primary]

\newrefcontext
\printbibliography[title=References, keyword=secondary, resetnumbers]

\end{document}

在此处输入图片描述

离题:请注意,我append从您的步骤中删除了您的说明DeclareSourcemap。附加的想法很好。但假设您有一个带有关键字的字段mykeyword,并将它附加primary到该字段。您将得到mykeywordprimary,它既不是mykeyword也不是primary,并且您基于关键字的用于分隔参考书目的机制将失败(实际上您将缺少参考书目条目)。因此,要做到这一点,您必须在关键字之间包含一个逗号,并处理字段为空或不为空的情况,依此类推。

相关内容