作者和合作形式

作者和合作形式

我正在使用biblatex+biber来制作我的书目。现在我正在使用以下代码将一个collaboration字段包含到我的书目中。

\DeclareSourcemap{
  \maps[datatype=bibtex,overwrite=true]{
    \map{
      \step[fieldsource=Collaboration, final=true]
      \step[fieldset=usera, origfieldval, final=true]
    }
  }
}

\renewbibmacro*{author}{%
  \iffieldundef{usera}{%
    \printnames{author}%
  }{%
    \printnames{author} (\printfield{usera})%
  }
}

但是我并不满意,我希望获得以下格式:

  • 如果有合作领域和作者字段打印AUTHOR (COLLABORATION)
  • 如果有作者字段而没有协作字段打印AUTHOR
  • 如果有协作字段而没有作者字段打印COLLABORATION

此外,我希望该COLLABORATION字段的格式如下:

  • 用于collaboration = {NAME}打印The NAME collaboration
  • 用于collaboration = {NAME_1, NAME_2}打印The NAME_1 and NAME_2 collaborations
  • 用于collaboration = {NAME_1, NAME_2, ..., NAME_N}打印The NAME_1, NAME_2, ..., and NAME_N collaborations

::开始编辑:::
我已经解决了collaboration使用正则表达式工具格式化字段的问题。代码如下。我仍然没有解决如何在没有作者的情况下打印不带括号的协作字段。哦,请随意评论这个解决方案;指出你发现的任何问题/错误!

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    % Format the collaboration field
    \map{
      \step[fieldsource=Collaboration, match=\regexp{([^,]+), ([^,]+), (.+), ([^,]+)}, fieldset=usera, fieldvalue={The $1, $2, $3, and $4 collaborations}, final=true]
    }
    \map{
      \step[fieldsource=Collaboration, match=\regexp{([^,]+), ([^,]+), ([^,]+)}, fieldset=usera, fieldvalue={The $1, $2, and $3 collaborations}, final=true]
    }
    \map{
      \step[fieldsource=Collaboration, match=\regexp{([^,]+), ([^,]+)}, fieldset=usera, fieldvalue={The $1 and $2 collaborations}, final=true]
    }
    \map{
      \step[fieldsource=Collaboration, match=\regexp{([^,]+)}, fieldset=usera, fieldvalue={The $1 collaboration}, final=true]
    }
  }
}

:::结束编辑:::


这可能吗?如果可以,怎么做?

下面您可以找到用于测试解决方案的 MWE......

\documentclass{article}

\usepackage[
hyperref=true,
backend=biber,
style=numeric-comp,          % Sort and compress
backref=true,                % Print Backreferences
backrefstyle=three,          % start combining pages after third page
sorting=none,                % Do not sort!
firstinits=true,             % First and Middle names as initials
maxbibnames=3                % Maximum number of authors to print in Bibliography
]{biblatex}

\begin{filecontents}{\jobname.bib}
@article{key1,
  author = {Franck, James and Brown, Bob and Doe, John},
  collaboration = {COLLAB},
  title = {Authors and Collab}}
@article{key2,
  author = {Frank, James and Brown, Bob and Doe, John},
  collaboration = {COLLAB1, COLLAB2},
  title = {Authors and Collabs}}
@article{key3,
  author = {Frank, James and Brown, Bob and Doe, John},
  collaboration = {COLLAB1, COLLAB2, COLLAB3, COLLAB4},
  title = {Authors and Collabss}}
@article{key4,
  collaboration = {COLLAB1, COLLAB2, COLLAB3, COLLAB4},
  title = {Collabss}}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\cite{key1}
\cite{key2}
\cite{key3}
\cite{key4}
\printbibliography
\end{document}

答案1

如果您同意collaboration列表字段中的项目不是用,而是用分隔and,则可以尝试以下操作。

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{collab.dbx}
\DeclareDatamodelFields[type=list, datatype=literal]{collaboration}
\end{filecontents*}

\usepackage[
backend=biber,
datamodel=collab,
style=numeric-comp,
sorting=none,
giveninits=true,
maxbibnames=3,
maxitems=999,
]{biblatex}

\begin{filecontents}{\jobname.bib}
@article{key1,
  author = {Franck, James and Brown, Bob and Doe, John},
  collaboration = {COLLAB},
  title = {Authors and Collab}}
@article{key2,
  author = {Frank, James and Brown, Bob and Doe, John},
  collaboration = {COLLAB1 and COLLAB2},
  title = {Authors and Collabs}}
@article{key3,
  author = {Frank, James and Brown, Bob and Doe, John},
  collaboration = {COLLAB1 and COLLAB2 and COLLAB3 and COLLAB4},
  title = {Authors and Collabss}}
@article{key4,
  collaboration = {COLLAB1 and COLLAB2 and COLLAB3 and COLLAB4},
  title = {Collabss}}
\end{filecontents}
\addbibresource{\jobname.bib}

\NewBibliographyString{the}
\NewBibliographyString{collaborations}
\NewBibliographyString{collaboration}
\DefineBibliographyStrings{english}{
  the            = {the},
  collaboration  = {collaboration},
  collaborations = {collaborations},
}

\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\printnames{author}%
     \iffieldundef{authortype}
       {}
       {\setunit{\printdelim{authortypedelim}}%
        \usebibmacro{authorstrg}}%
     \iflistundef{collaboration}
       {}
       {\setunit{\addspace}%
        \printtext[parens]{%
          \bibsentence
          \bibstring{the}\addspace
          \printlist{collaboration}%
          \addspace
          \ifboolexpr{
            test {\ifnumgreater{\value{collaboration}}{1}}
            or
            test {\ifandothers{collaboration}}
          }
          {collaborations}
          {collaboration}}}}
    {}}

\begin{document}
\cite{key1}
\cite{key2}
\cite{key3}
\cite{key4}
\printbibliography
\end{document}

在此处输入图片描述

该解决方案定义了一个新的数据模型,使Bibercollaboration能够识别该列表biblatex。然后重新定义author宏只是为了正确打印列表。

相关内容