Biblatex:两种不同风格和排序的书目 II 第 3 部分

Biblatex:两种不同风格和排序的书目 II 第 3 部分

基于以下解决方案Biblatex:两种不同风格和排序的书目 IIBiblatex:两种不同风格和排序的书目 II 第二部分给出 古斯布斯 莫威分别我想将选项添加到具有以下行为的labelprefix样式中:numeric-comp

  1. labelprefix如果引用遵循自然数的整数序列,则从引用范围中删除第二个,例如,tech. 1-3而不是 tech. 1-tech.3
  2. labelprefix如果单个引文与范围引文相结合,或者引文范围不连续,也应删除,例如,tech. 1, 3-4代替tech. 1, tech. 3-4tech. 1-2, 4-6代替tech. 1-2, tech. 4-6

第一点可以通过重新定义cite:dump的宏来实现numeric.comp.cbx,即删除\printtext[labelprefix]{\cbx@lastprefix}

\renewbibmacro*{cite:dump}{%
\ifnumgreater{\value{cbx@tempcnta}}{0}
{\ifnumgreater{\value{cbx@tempcnta}}{1}
    {\bibrangedash}
{\multicitedelim}%
\bibhyperref[\cbx@lastkey]{%
    \ifdef\cbx@lastprefix
           %{\printtext[labelprefix]{\cbx@lastprefix}} %deleted
            {} % added
            {}%
    \printtext[labelnumber]{\cbx@lastnumber}
    }}
{}%
\setcounter{cbx@tempcnta}{0}%
\global\undef\cbx@lastprefix}

第二个怎么样?有什么想法吗?

梅威瑟:


\documentclass{article}

\usepackage{filecontents}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{filecontents}{biblatextest1.bib}
@BOOK{BookA03,
author    = {Author Ät{\"a}},
title     = {Some Title},
publisher = {Some Publisher},
year      = 2003,
}
@BOOK{BookB02,
author    = {Author Bb\"{a}},
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{LinkC01,
author  = {Author Ccc},  
title   = {Some Title},
year    = 2004,
url     = {www.test1.com/bild.jpg},
}
@MISC{LinkD04,
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},
}
@MISC{LinkD09,
    author  = {Author Iii},
    title   = {Some Title},
    year    = 2001,
    url     = {www.test6.com/bild.jpg},
}
\end{filecontents}

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

\usepackage[colorlinks=true,citecolor=blue,urlcolor=red]{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}{%
        \thefield{labelprefix}\thefield{labelalpha}\thefield{extraalpha}}}
%
\renewbibmacro*{cite:dump}{%
    \ifnumgreater{\value{cbx@tempcnta}}{0}
    {\ifnumgreater{\value{cbx@tempcnta}}{1}
        {\bibrangedash}
        {\multicitedelim}%
        \bibhyperref[\cbx@lastkey]{%
            \ifdef\cbx@lastprefix
            %           {\printtext[labelprefix]{\cbx@lastprefix}} %deleted
            {} % added
            {}%
            \printtext[labelnumber]{\cbx@lastnumber}
    }}
    {}%
    \setcounter{cbx@tempcnta}{0}%
    \global\undef\cbx@lastprefix} %
\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,LinkC01} and \cite{BookB10,BookB11,BookB09}.

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

The others are \cite{LinkC01,LinkD08,LinkD05,LinkD06,LinkD07} as well as \cite{LinkC01,LinkD04,LinkD05,LinkD07,LinkD08, LinkD09}
and \cite{BookA03}.

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

\newrefcontext[labelprefix=tech.\space]
\printbibliography[title=References, keyword=secondary, resetnumbers]

\end{document}

在此处输入图片描述

答案1

numeric-comp您可能想尝试以下解决方案。它需要对内部命令进行大量重写,但您想要的风格与通常的风格截然不同。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[backend=biber,
  style=numeric-comp,
  labelalpha, defernumbers,
  locallabelwidth]{biblatex}

\usepackage[colorlinks=true,citecolor=blue,urlcolor=red]{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]
    }
  }
}

\renewcommand*{\multicitedelim}{\addsemicolon\space}

\letbibmacro{cite:num:comp}{cite:comp}

\newbibmacro{cite:alpha}{%
  \printtext[bibhyperref]{%
    \printfield{labelprefix}%
    \printfield{labelalpha}%
    \printfield{extraalpha}%
    \ifbool{bbx:subentry}
      {\printfield{entrysetcount}}
      {}}}

\renewbibmacro*{cite:comp}{%
  \ifkeyword{primary}
    {\usebibmacro{cite:dump}%
     \ifnumgreater{\value{cbx@tempcntb}}{-1}
       {\multicitedelim}
       {\iffirstcitekey
          {}
          {\multicitedelim}}%
     \usebibmacro{cite:alpha}%
     \iflastcitekeylocal
       {}
       {\multicitedelim}%
     \setcounter{cbx@tempcnta}{0}%
     \setcounter{cbx@tempcntb}{-2}}
    {\usebibmacro{cite:num:comp}}}

\makeatletter
\newcommand*\iflastcitekeylocal{%
  \ifnumequal\c@citecount\c@citetotal}

\renewbibmacro*{cite:init}{%
  \global\boolfalse{cbx:parens}%
  \global\undef\cbx@lasthash
  \global\undef\cbx@lastnumber
  \global\undef\cbx@lastprefix
  \global\undef\cbx@secondtolastprefix
  \setcounter{cbx@tempcnta}{0}%
  \setcounter{cbx@tempcntb}{-2}}

\newcommand*{\ifsamelabelprefix}{%
  \iffieldundef{labelprefix}
    {\ifundef\cbx@lastprefix}
    {\iffieldequals{labelprefix}{\cbx@lastprefix}}}

\renewbibmacro*{cite:comp:comp}{%
  \renewcommand*{\multicitedelim}{\addcomma\space}%
  \ifsamelabelprefix
    {\ifnumequal{\thefield{labelnumber}}{\value{cbx@tempcntb}}
       {\savefield{entrykey}{\cbx@lastkey}%
        \savefield{labelnumber}{\cbx@lastnumber}%
        \addtocounter{cbx@tempcnta}{1}}
       {\ifnumequal{\thefield{labelnumber}}{\value{cbx@tempcntb}-1}
          {}
          {\usebibmacro{cite:dump}%
           \ifnumgreater{\value{cbx@tempcntb}}{-1}
             {\multicitedelim}
             {}%
           \printtext[bibhyperref]{%
             \iffieldequals{labelprefix}{\cbx@lastprefix}
               {}
               {\printfield{labelprefix}}%
             \printfield{labelnumber}}}}}
    {\usebibmacro{cite:comp:end}}%
  \setcounter{cbx@tempcntb}{\thefield{labelnumber}}%
  \global\let\cbx@secondtolastprefix\cbx@lastprefix
  \savefield{labelprefix}{\cbx@lastprefix}}

\renewbibmacro*{cite:dump}{%
  \ifnumgreater{\value{cbx@tempcnta}}{0}
    {\ifnumgreater{\value{cbx@tempcnta}}{1}
       {\bibrangedash}
       {\multicitedelim}%
     \bibhyperref[\cbx@lastkey]{%
       \ifdef\cbx@lastprefix
         {\ifdefequal\cbx@lastprefix\cbx@secondtolastprefix
            {}
            {\printtext[labelprefix]{\cbx@lastprefix}}}
         {}%
       \printtext[labelnumber]{\cbx@lastnumber}}}
    {}%
  \setcounter{cbx@tempcnta}{0}}
\makeatother

\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{filecontents}{biblatextest1.bib}
@BOOK{BookA03,
  author    = {Author Ät{\"a}},
  title     = {Some Title},
  publisher = {Some Publisher},
  year      = 2003,
}
@BOOK{BookB02,
  author    = {Author Bb\"{a}},
  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{LinkC01,
  author  = {Author Ccc},
  title   = {Some Title},
  year    = 2004,
  url     = {www.test1.com/bild.jpg},
}
@MISC{LinkD04,
  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},
}
@MISC{LinkD09,
  author  = {Author Iii},
  title   = {Some Title},
  year    = 2001,
  url     = {www.test6.com/bild.jpg},
}
\end{filecontents}
\addbibresource{biblatextest1.bib}
\addbibresource{biblatextest2.bib}


\begin{document}
The first two citations \autocite{LinkD07,LinkC01}
and \autocite{BookB10,BookB11,BookB09}.

Mixing both primary and secondary \autocite{LinkD08,LinkD04,LinkD05,BookB10,BookB11,BookB09}.

The others are \autocite{LinkC01,LinkD08,LinkD05,LinkD06,LinkD07}
as well as \autocite{LinkC01,LinkD04,LinkD05,LinkD07,LinkD08, LinkD09}
and \autocite{BookA03}.

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

\newrefcontext[labelprefix=tech\string\adddotspace]
\printbibliography[title=References, keyword=secondary, resetnumbers]
\end{document}

前两个引文 [tech. 1, 5] 和 [Jjj02, Kkk02, Lll02]。//混合主要和次要的 [tech. 2, 3, 6, Jjj02, Kkk02, Lll02]。//其他的是 [tech. 1, 3–6] 以及 [tech. 1–3, 5–7] 和 [Ätä03]。

相关内容