biblatex:同一文档中存在不同的 bibstyles 吗?

biblatex:同一文档中存在不同的 bibstyles 吗?

我用它biblatex来打印文档的参考书目,对结果非常满意。但是,我还想在文档的另一部分添加个人出版物列表。它与环境配合得很好refsection,但我想为这一部分使用另一种样式(例如,biblatex-publist)。

问:是否可以biblatex在单个文档的不同部分使用两种不同的样式?


例子:

为了一般的参考书目:

Thomas H. Cormen、Charles E. Leiserson、Ronald L. Rivest 和 Clifford Stein。《算法导论》,第三版。第 3 版。麻省理工学院出版社,2009 年

为了个人的出版清单:

1987 年(与 John Doe 和 Mary Hall 合著)。园艺有新趋势吗?在:园艺实践 24,第 10-15 页。


似乎只有在加载包时才能指定样式,这使得样式成为全局选项。有办法解决这个问题吗?

答案1

您无法自动执行此操作,但在某些情况下可以将文件拆分成几部分以提供您想要的内容。对于混合样式和风格bbx的情况,这非常简单。从以下 MWE 开始工作authoryearpublist

\documentclass{article}
\usepackage[labelnumber=true, bibstyle=authoryear]{biblatex}
% \usepackage[bibstyle=publist]{biblatex}
\addbibresource{biblatex-examples.bib}
% \input{\jobname Pre}
\makeatletter
\def\bpl@osurname{Baez}
\def\bpl@ofirstname{John C.}
\makeatother

\begin{document}
\nocite{baez/article}
\printbibliography

\input{\jobname Post}
\begin{refsection}
\nocite{baez/article}
\printbibliography
\end{refsection}
\end{document}

输出authoryear

在此处输入图片描述

输出publist

在此处输入图片描述

如果我们包含\jobname Pre\jobname Post文件,\usepackage[labelnumber=true, bibstyle=authoryear]{biblatex}我们得到

在此处输入图片描述

除“publist”样式条目开头的一个空白空格外,输出与两种样式都匹配。

“魔法”发生在\jobname Pre\jobname Post文件中。为了创建这些文件,我将导致错误或似乎属于序言的内容复制publist.bbx到 中,然后将其移动到 中。我删除了在 中时仍导致错误的任何内容。\jobname Post\jobname Pre\jobname Pre

这给了我\jobname Pre一个

\makeatletter

%
% The omitted name of the publication list author
\def\bpl@osurname{}
\def\bpl@ofirstname{}
\def\bpl@ovonpart{}
%
% Manual way to specify omitted name
\def\omitname{%
   \@ifnextchar[%
     {\omitname@i}
     {\omitname@i[]}%
}
\def\omitname@i[#1]{%
   \@ifnextchar[%
     {\omitname@ii{#1}}
     {\omitname@ii{#1}[]}%
}
\def\omitname@ii#1[#2]#3{%
  % Do stuff
  \def\bpl@osurname{#3}
  \ifx\@empty#1\else\def\bpl@ofirstname{#1}\fi
  \ifx\@empty#2\else\def\bpl@ovonpart{#2}\fi
}

%
% Formatting of year in margin par (if requested)
\providecommand*\plmarginyear[1]{%
  \raggedleft\small\textbf{#1}%
}

%
% Options
%

\DeclareBibliographyOption{omitname}{\def\bpl@osurname{#1}}

\DeclareBibliographyOption{omitfirstname}{\def\bpl@ofirstname{#1}}

\DeclareBibliographyOption{omitnameprefix}{\def\bpl@ovonpart{#1}}

\newif\if@marginyear\@marginyearfalse
\DeclareBibliographyOption{marginyear}[true]{%
    \ifstrequal{#1}{true}{\@marginyeartrue\reversemarginpar}{\@marginyearfalse}
}

\newif\if@unboldyear\@unboldyearfalse
\DeclareBibliographyOption{boldyear}[true]{%
    \ifstrequal{#1}{false}{\@unboldyeartrue}{\@unboldyearfalse}
}

%
% Bibliography filter
%
% Inspired by http://tex.stackexchange.com/a/28555/19291
\DeclareBibliographyCategory{filtered}

\DeclareIndexNameFormat{authorfiltered}{%
   \bpl@normalize{#1}{\bpl@tsurname}%
   \bpl@normalize{#3}{\bpl@tfirstname}%
   \bpl@normalize{#5}{\bpl@tvonpart}%
   \bpl@normalize{\bpl@osurname}{\bpl@esurname}%
   \bpl@normalize{\bpl@ofirstname}{\bpl@efirstname}%
   \bpl@normalize{\bpl@ovonpart}{\bpl@evonpart}%
   \ifboolexpr{
      test { \ifdefstrequal{\bpl@esurname}{\bpl@tsurname} }
      and
      ( test { \ifdefstrequal{\bpl@efirstname}{\bpl@tfirstname} } or test { \ifdefstring{\bpl@ofirstname}{} }) 
      and
      ( test { \ifdefstrequal{\bpl@evonpart}{\bpl@tvonpart} } or test { \ifdefstring{\bpl@ovonpart}{} }) }
    {\addtocategory{filtered}{\thefield{entrykey}}}
    {}}

\DeclareIndexNameFormat{editorfiltered}{%
   \edef\bpl@tsurname{#1}%
   \edef\bpl@tfirstname{#3}%
   \edef\bpl@tvonpart{#5}%
   \bpl@normalize{\bpl@osurname}{\bpl@esurname}%
   \bpl@normalize{\bpl@ofirstname}{\bpl@efirstname}%
   \bpl@normalize{\bpl@ovonpart}{\bpl@evonpart}%
   \ifboolexpr{
      test { \ifdefstrequal{\bpl@esurname}{\bpl@tsurname} }
      and
      ( test { \ifdefstrequal{\bpl@efirstname}{\bpl@tfirstname} } or test { \ifdefstring{\bpl@ofirstname}{} }) 
      and
      ( test { \ifdefstrequal{\bpl@evonpart}{\bpl@tvonpart} } or test { \ifdefstring{\bpl@ovonpart}{} }) }
    {\addtocategory{filtered}{\thefield{entrykey}}}
    {}}

\DeclareIndexNameFormat[inbook,inproceedings,incollection]{editorfiltered}{}%

% \AtDataInput{%
%   \indexnames[authorfiltered]{author}%
%   \indexnames[editorfiltered]{editor}%
% }

\defbibfilter{mine}{category=filtered}






\AtBeginDocument{%
\if@unboldyear
\renewbibmacro*{date:labelyear+extrayear}{%
   \usebibmacro{date:makedate}%
}
\fi
}


%
% l7n
%
\NewBibliographyString{with}
\NewBibliographyString{parttranslationof}
\DefineBibliographyStrings{english}{%
  parttranslationof   = {partial translation of},
  with                = {with}
}
\DefineBibliographyStrings{french}{%
  parttranslationof   = {traduction partielle de},
  with                = {avec}
}
\DefineBibliographyStrings{german}{%
  parttranslationof   = {Teil\"ubersetzung von},
  with                = {mit}
}


%
% New driver for reviews
%

\DeclareBibliographyDriver{review}{%
  \usebibmacro{rauthor/label}%
  \setunit*{\addcolon\space}%
  \usebibmacro{title}%
  \newunit\newblock
  \usebibmacro{in:}%
  \usebibmacro{journal+issuetitle}%
  \newunit\newblock
  \printfield{note}%
  \setunit{\addcomma\space}%
  \printfield{pages}
  \newunit\newblock
  \printfield{issn}%
  \newunit\newblock
  \printfield{doi}%
  \setunit{\addspace}
  \usebibmacro{addendum+pubstate}%
  \newunit\newblock
  \usebibmacro{url+urldate}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{related}%
  \usebibmacro{finentry}}

%
% Sorting schemes
%

% Consider the whole date (year-month-day)
% Sorting date (descending), name, title
\DeclareSortingScheme{ddnt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort[direction=descending]{
    \field[strside=left,strwidth=4]{sortyear}
    \field[strside=left,strwidth=4]{year}
    \literal{9999}
  }
  \sort[direction=descending]{
    \field[padside=left,padwidth=2,padchar=0]{month}
    \literal{00}
  }
  \sort[direction=descending]{
    \field[padside=left,padwidth=2,padchar=0]{day}
    \literal{00}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
}

% Sorting year (descending), month, day, name, title
\DeclareSortingScheme{ydmdnt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort[direction=descending]{
    \field[strside=left,strwidth=4]{sortyear}
    \field[strside=left,strwidth=4]{year}
    \literal{9999}
  }
  \sort{
    \field[padside=left,padwidth=2,padchar=0]{month}
    \literal{00}
  }
  \sort{
    \field[padside=left,padwidth=2,padchar=0]{day}
    \literal{00}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
}

% Sorting date (ascending), name, title
\DeclareSortingScheme{dnt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field[strside=left,strwidth=4]{sortyear}
    \field[strside=left,strwidth=4]{year}
    \literal{9999}
  }
  \sort{
    \field[padside=left,padwidth=2,padchar=0]{month}
    \literal{00}
  }
  \sort{
    \field[padside=left,padwidth=2,padchar=0]{day}
    \literal{00}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
}

\makeatother

以及\jobname Post

\makeatletter

%
% Field format definitions
%
\DeclareFieldFormat{bibentrysetcount}{\mkbibparens{\mknumalph{#1}}}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}
\DeclareFieldFormat{shorthandwidth}{\mkbibbrackets{#1}}
\DeclareFieldFormat{related:parttranslationof}{\mkbibbrackets{#1}}


%
% Deal with numbering (resume numbers in refsections)
%
\csnumgdef{bbx@itemtotal}{0}
\csnumgdef{bbx@currentitem}{0}
\csnumgdef{bbx@saverefsection}{0}
\newbool{newsection}

\preto\blx@refsection{\global\setbool{newsection}{true}}

\defbibenvironment{bibliography}
  {\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
   \ifnumgreater{\c@refsection}{\bbx@saverefsection}%
    {\csnumgdef{bbx@itemtotal}{\csuse{bbx@itemtotal}+\csuse{bbx@currentitem}}}{}%
   \csnumgdef{bbx@saverefsection}{\c@refsection}%
  }
  {\item}

\DeclareFieldFormat{labelnumber}{%
    \ifbool{newsection}{%
       % Fix start counter value
       \csnumgdef{bbx@itemtotal}{\csuse{bbx@itemtotal}-#1+1}%
       \global\setbool{newsection}{false}%
    }{}%
    \mkbibdesc{#1}%
    \csnumgdef{bbx@currentitem}{#1}%
}

% Print labelnumber as actual number, plus item total
\newrobustcmd{\mkbibdesc}[1]{%
  \number\numexpr\csuse{bbx@itemtotal}+#1\relax}

\newcommand*\decreasebbxnumbering[1]{\csnumgdef{bbx@itemtotal}{\csuse{bbx@itemtotal}-#1}}


%
% New environment for (foreign) reviews
%
\defbibenvironment{reviews}
  {\begin{enumerate}%
   \small\setlength\itemsep{0pt}}
  {\end{enumerate}}
  {\item}


%
% Helper function:
% Removing braces from names (courtesy of egreg at
% http://tex.stackexchange.com/a/79583/19291)
% and normalize spaces
\def\bpl@normalize#1#2{%
  \begingroup
  \def\bibnamedelima{ }%
  \def\bibnamedelimb{ }%
  \def\IeC##1{##1}%
  \protected@edef\@tempa{#1}%
  \gdef\@gtempa{}%
  \expandafter\bpl@@normalize\@tempa\@nil
  \endgroup
  \let#2\@gtempa
}
\def\bpl@@normalize#1{%
  \ifx#1\@nil\else
    \expandafter\gdef\expandafter\@gtempa\expandafter{\@gtempa#1}%
    \expandafter\bpl@@normalize
  \fi
}


%
% Remove omitted name from author and editor lists
%
\newtoggle{myselfprec}
\newtoggle{hadmyself}

\DeclareNameFormat{author}{%
   \ifthenelse{\value{listcount}=1}{\ifthenelse{\value{author}>1}{\bibopenparen\bibstring{with}\addspace}{}}{}%
   % Exclude omitted author
   \bpl@normalize{#1}{\bpl@tsurname}%
   \bpl@normalize{#3}{\bpl@tfirstname}%
   \bpl@normalize{#5}{\bpl@tvonpart}%
   \bpl@normalize{\bpl@osurname}{\bpl@esurname}%
   \bpl@normalize{\bpl@ofirstname}{\bpl@efirstname}%
   \bpl@normalize{\bpl@ovonpart}{\bpl@evonpart}%
   \ifboolexpr{
      test { \ifdefstrequal{\bpl@esurname}{\bpl@tsurname} }
      and
      ( test { \ifdefstrequal{\bpl@efirstname}{\bpl@tfirstname} } or test { \ifdefstring{\bpl@ofirstname}{} }) 
      and
      ( test { \ifdefstrequal{\bpl@evonpart}{\bpl@tvonpart} } or test { \ifdefstring{\bpl@ovonpart}{} }) }
          {\toggletrue{myselfprec}\toggletrue{hadmyself}%
           \ifthenelse{\value{listcount}=1\AND\value{liststop}=1}
                   {\stepcounter{liststop}}{}}
          {\ifthenelse{\value{listcount}=1}{\togglefalse{hadmyself}}{%
          \ifboolexpr{
              test { \iftoggle{myselfprec} }
              and
              test { \ifnumless{\value{listcount}}{3} } }
              {}{%
                 \ifnumless{\value{listcount}}{\value{liststop}-1}%
                    {\addcomma\addspace}%
                    {\iftoggle{hadmyself}{%
                        \ifnumless{\value{listcount}}{\value{liststop}}%
                           {\addcomma\addspace}%
                           {\addspace\bibstring{and}\addspace}}
                       {\addspace\bibstring{and}\addspace}}%
                }%
          }%
          \iffirstinits
             {\ifblank{#4}{}{#4\addspace}}%
             {\ifblank{#3}{}{#3\addspace}}%
          \ifblank{#5}{}{#5\addspace}%
          \togglefalse{myselfprec}%
          #1}%
          \usebibmacro{name:andothers}%
   \ifthenelse{\value{listcount}=\value{liststop}\AND\value{author}>1}{\unspace\bibcloseparen}{}%
}

\DeclareNameFormat{editor}{%
   \ifthenelse{\value{listcount}=1}{\ifthenelse{\value{editor}>1}{\bibopenparen\bibstring{with}\addspace}{}}{}%
   % Exclude omitted author
   \bpl@normalize{#1}{\bpl@tsurname}%
   \bpl@normalize{#3}{\bpl@tfirstname}%
   \bpl@normalize{\bpl@osurname}{\bpl@esurname}%
   \bpl@normalize{\bpl@ofirstname}{\bpl@efirstname}%
   \ifboolexpr{
      test { \ifdefstrequal{\bpl@esurname}{\bpl@tsurname} }
      and
      ( test { \ifdefstrequal{\bpl@efirstname}{\bpl@tfirstname} } or test { \ifdefstring{\bpl@ofirstname}{} }) 
      and
      ( test { \ifdefstrequal{\bpl@evonpart}{\bpl@tvonpart} } or test { \ifdefstring{\bpl@ovonpart}{} }) }
          {\toggletrue{myselfprec}\toggletrue{hadmyself}%
           \ifthenelse{\value{listcount}=1\AND\value{liststop}=1}
                   {\stepcounter{liststop}}{}}
          {\ifthenelse{\value{listcount}=1}{\togglefalse{hadmyself}}{%
            \ifboolexpr{
              test { \iftoggle{myselfprec} }
              and
              test { \ifnumless{\value{listcount}}{3} } }
              {}{%
                 \ifnumless{\value{listcount}}{\value{liststop}-1}%
                     {\addcomma\addspace}%
                     {\iftoggle{hadmyself}{%
                         \ifnumless{\value{listcount}}{\value{liststop}}%
                             {\addcomma\addspace}%
                             {\addspace\bibstring{and}\addspace}}
                        {\addspace\bibstring{and}\addspace}}%
                }%
          }%
          \iffirstinits
             {\ifblank{#4}{}{#4\addspace}}%
             {\ifblank{#3}{}{#3\addspace}}%
          \ifblank{#5}{}{#5\addspace}%
          \togglefalse{myselfprec}%
          #1}%
          \usebibmacro{name:andothers}%
   \ifthenelse{\value{listcount}=\value{liststop}\AND\value{editor}>1}{\unspace\bibcloseparen}{}%
}

\DeclareNameFormat{bookauthor}{%
  \ifblank{#5}{}{#5\addspace}%
  #1%
  \iffirstinits
      {\ifblank{#4}{}{\addcomma\space #4}}%
      {\ifblank{#3}{}{\addcomma\space #3}}%
  \ifthenelse{\value{listcount}<\value{liststop}}
    {\addslash}
    {}%
  \usebibmacro{name:andothers}}

\renewbibmacro*{name:andothers}{%
  \ifthenelse{\value{listcount}=\value{liststop}\AND
              \ifmorenames}
    {\ifnum\value{liststop}>1 \finalandcomma\fi
     \andothersdelim\biblcstring{andothers}}
    {}}

%
% Macros
%

\renewbibmacro*{author}{%
  \ifnameundef{author}
    {}
    {\usebibmacro{year+labelyear}\addspace%
     \printnames{author}%
     \setunit{\addspace}%
      \iffieldundef{nameaddon}
      {}
      {\mkbibbrackets{\bibstring{alias}%
       \addspace\printfield{nameaddon}}}}}

\renewbibmacro*{editor}{%
  \ifnameundef{editor}
    {}
    {\usebibmacro{year+labelyear}%
      \addspace%
      \printnames{editor}%
     \setunit{\addspace}%
     \usebibmacro{editorstrg}}}

\renewbibmacro*{editor+others}{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\usebibmacro{year+labelyear}%
     \addspace%
     \printnames{editor}%
     \setunit{\addcomma\space}%
     \usebibmacro{editor+othersstrg}%
     \clearname{editor}}
    {}}

\newbibmacro*{date:makedate}{%
  \printtext{%
     \iffieldundef{year}{%
       \iffieldundef{pubstate}{}{%
          \printfield{pubstate}%
        }%
      }{%
       \iffieldundef{month}{%
         \printdateextra}%
        {\printdate}%
      }%
     }%
}

\newbibmacro*{date:labelyear+extrayear}{%
   \mkbibbold{\usebibmacro{date:makedate}}%
}


\newbibmacro*{year+labelyear}{%
  \iffieldundef{year}{%
    \iffieldundef{pubstate}{\let\bbx@lasthash\undefined}{%
     \usebibmacro{date:labelyear+extrayear}%
     \if@marginyear%
     \iffieldequals{pubstate}{\bbx@lasthash}{}{%
      \printtext{\marginpar{\small\plmarginyear{\bibsentence\printfield{pubstate}}}}%
     }%
     \fi
      \savefield{pubstate}{\bbx@lasthash}%
      \clearfield{pubstate}%
     }
    }{%
     \usebibmacro{date:labelyear+extrayear}%
     \if@marginyear%
     \iffieldequals{labelyear}{\bbx@lasthash}{}{%
      \printtext{\marginpar{\small\plmarginyear{\printfield{labelyear}}}}%
     }%
     \fi
     \savefield{labelyear}{\bbx@lasthash}%
    }}

\newbibmacro*{rauthor/label}{%
  \ifnameundef{author}
    {\usebibmacro{label}}
    {\usebibmacro{rauthor}}
}

\newbibmacro*{rauthor}{%
  \ifnameundef{author}
    {\let\bbx@lasthash\undefined}
    {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\bibnamedash}
       {\savefield{namehash}{\bbx@lasthash}%
        \printnames{author}%
        \setunit{\addspace}}}%
    \iffieldundef{nameaddon}
    {}
    {\mkbibbrackets{\bibstring[\unspace]{alias}\addspace\printfield{nameaddon}}%
     \addspace}%
  \usebibmacro{ryear+labelyear}}

\newbibmacro*{ryear+labelyear}{%
  \iffieldundef{year}
    {}
    {\printtext[parens]{%
      \printfield{labelyear}%
      \printfield{extrayear}}}}
\makeatother

我猜排序完全搞砸了,但biblatex支持多种排序方案。同样,样式组合可能会导致重大冲突,因此这不是一个通用解决方案。不过,我认为,如果人们将bbxcbx样式编写为模块化,它暗示了一个通用解决方案。

答案2

结合风格有用吗?

答案:不,如果随机使用现有的 biblatex 样式并尝试合并它们(我尝试了 authordate 和 chicago-notes):棘手的部分是它们对 bibmacros 和布尔值使用相同的名称,但对它们执行不同的操作;或者它们导入基本代码(如 standard.bbx)并以不同的方式添加/修改。这就像通过合并两个不同型号的引擎来让汽车运行 - 有一些重叠,但有些东西就是不合适。(在样式级别,合并不会有帮助:日期是在之前还是之后?它不能同时完成。)

答案:是的,如果您从头开始构建样式(或元样式),以便处理逻辑在内部是一致且连贯的。然后,块的排序变得微不足道,因为书目驱动程序随后变成了调度程序:“如果是这个 bibentry/type/key,那么就是那个 bibmacro,否则就是另一个 bibmacro”。(不过,从视觉上看,同一文本块中的混合样式对读者没有帮助。)

或者,按关键字或类别或自定义条目类型拆分参考书目:让结构遵循信息。并且,如果样式被视为与 biblatex 样式分开,那么不同的“是”是可能的,因为本着保持形式和内容分离的精神,允许在 bib 字段格式和其他地方使用 Latex 代码。它不一定都是 {#1}。

子围兜

相关内容