[Tex/LaTex] Format of author and collaboration

biberbiblatex

I'm using biblatex + biber to produce my bibliography. Right now I'm using the following code to include a collaboration field into my bib.

\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})%
  }
}

However, I'm not satisfied. I would like to obtain the following format:

  • If there is a collaboration field and and author field print AUTHOR (COLLABORATION)
  • If there is an author field and no collaboration field print AUTHOR
  • If there is a collaboration field and no author field print COLLABORATION

Furthermore I would like the COLLABORATION field to be formatted as follows:

  • For collaboration = {NAME} print The NAME collaboration
  • For collaboration = {NAME_1, NAME_2} print The NAME_1 and NAME_2 collaborations
  • For collaboration = {NAME_1, NAME_2, ..., NAME_N} print The NAME_1, NAME_2, ..., and NAME_N collaborations

::BEGIN EDIT:::
I have solved formatting the collaboration field using the regexp facilities. The code is listed below. I still have not solved how to print the collaboration field without parens when there's no author. Oh, and feel free to comment on this solution; point out any problems / bugs you find!

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

:::END EDIT:::


Is this possible? If so, how?

Below you can find an MWE for testing a solution …

\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}

Best Answer

If you are OK with collaboration becoming a list field where items are not separated by , but rather with and, you can try the following.

\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}

enter image description here

The solution defines a new data model that makes the collaboration list known to biblatex and Biber. The redefinition of the author macro is then just about printing the list correctly.

Related Question