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,並且基於關鍵字的分隔參考書目的機制將失敗(實際上您將丟失參考書目條目)。因此,要做到這一點,您必須在關鍵字之間添加逗號並處理欄位為空或非空的情況,等等。

相關內容