0

The following is a mwe:

% !TEX encoding = UTF-8 Unicode
% !TEX program = lualatex
% !BIB program = biber

\begin{filecontents}[overwrite]{\jobname.bib} @customa{a, type = {type1}, author = {Familyname, Givenname}, title = {Title}, date = {2000}, } @customa{b, type = {type2}, author = {Institution A}, title = {Title}, date = {3000}, } @customa{c, type = {type3}, author = {Institution B}, title = {Title}, date = {1000}, } \end{filecontents}

\documentclass{article} \usepackage[style=authortitle]{biblatex} \addbibresource{\jobname.bib}

\DeclareBibliographyDriver{customa}{% \usebibmacro{bibindex}% \usebibmacro{begentry}% \printnames{author}% \newunit\newblock \usebibmacro{title}% \newunit\newblock \printdate% \usebibmacro{finentry}}

\begin{document} \nocite{*} \printbibliography \end{document}

The author field contains both personal names (with first and last names) and institutions. For various reasons, I preferred to use the same field instead of separate fields (like author and institution).

Therefore, under certain conditions, author field must be wrapped in an extra pair of curly braces to prevent data parsing from treating them as personal names which are to be dissected into their components (see §2.3.3 of the biblatex Guide).

Since the value of the type field determines the "type" of the author (personal name or institution name), the "pseudo-conditions" regarding sourcemapping are as follows:

IF 
  entrytype = customa;
  field "type" is defined and its value <> "type1";
THEN
  wrap the field "author" in an extra pair of curly braces;
ELSE
  nothing

So, what are the \steps to be set in \DeclareSourcemap?

  • I really recommend using the correct markup from the start in your .bib file. Either use double curly braces or set stuff up to use a different field altogether. Trying to fix messy .bib data with a sourcemap is usually not the best idea. – moewe Jul 11 '23 at 19:50
  • Thanks for the suggestion, I will try to modify my approach. However, I would be curious how the sourcemapping elements should be set up. – matteo339 Jul 11 '23 at 22:05

1 Answers1

1

I really don't think this is a good idea since it makes for very inconsistent markup in the .bib file. "Corporate authors" (Using a 'corporate author' in the "author" field of a bibliographic entry (spelling out the name in full)) should always be protected an additional pair of curly braces in name fields. Either use curly braces correctly and consistently for all entry types or pick a different field if author does not fit the semantics.

That said, here is a sourcemap that uses RegExp replacement to add an additional pair of curly braces to author fields for @customa entries with a type field not equal to type1.

\documentclass{article}
\usepackage[style=authortitle]{biblatex}

\DeclareSourcemap{ \maps[datatype=bibtex]{ \map{ \pertype{customa} \step[fieldsource=type, final] \step[fieldsource=type, notmatch=\regexp{\Atype1\Z}, final] \step[fieldsource=author, match=\regexp{\A(.*)\Z}, replace=\regexp{{$1}}] } } }

\DeclareBibliographyDriver{customa}{% \usebibmacro{bibindex}% \usebibmacro{begentry}% \printnames{author}% \newunit\newblock \usebibmacro{title}% \newunit\newblock \printdate% \usebibmacro{finentry}}

\begin{filecontents}{\jobname.bib} @customa{a, type = {type1}, author = {Givenname Familyname}, title = {Title}, date = {2000}, } @customa{b, type = {type2}, author = {Institution A}, title = {Title}, date = {3000}, } @customa{c, type = {type3}, author = {Institution B}, title = {Title}, date = {1000}, } @customa{d, author = {Grivenname Flamilyname}, title = {Title}, date = {4000}, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} \nocite{*} \printbibliography \end{document}

Familyname, Givenname. Title. 2000.
Flamilyname, Grivenname. Title. 4000.
Institution A. Title. 3000.
Institution B. Title. 1000.

moewe
  • 175,683