Abbreviate resolved abbreviations in authors' first names in biblatex

I like to resolve abbreviated first names in my .bib file. For example, if the author of a book is given as Paul G. J. Smith, I will resolve the abbreviations as Paul G[eorge] J[ohn] Smith in my .bib file.

Some journals, however, specifically want the names of the authors to be printed as they appear in the cited work. The entry for Smith, therefore, should appear as Smith, Paul G. J. in the printed bibliography.

What do I need to do in biblatex in order to tell it to replace a sequence beginning with [ and ending with ] with a dot .? Please suggest a command I can put in the preamble of my .tex file. I have a long list of biblatex tweaks in my preambles, and I would prefer to keep them all there, if possible.

A MWE:

\documentclass{article}
\usepackage{csquotes}
\usepackage[
bibstyle = authoryear,
citestyle = authoryear-comp,
sorting = nyt,
language = american,
abbreviate = false,
backend = biber]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{smith2006,
AUTHOR = "Paul G[eorge] J[ohn] Smith",
TITLE = "My life with the Beatles",
YEAR = "2006"}
\end{filecontents}
\begin{document}
\noindent
Text \parencite{smith2006}.
\printbibliography
\end{document}


-
Biblatex knows a firstinits=true option that unfortunately abbreviates all first names. It looks like you are searching for some "conditional" firstinits setting, that abbreviates all but the first first name. I didn't have a look at the biblatex style source code yet but maybe it is possible to build a macro that only abbreviates the n>1 first names. –  Benedikt Bauer Jan 25 '13 at 14:01
@BenediktBauer But that is not what I am trying to accomplish. If the author's name is given as Paul George Smith, then I don't want to abbreviate anything. What I need is a command that searches the author entry for sequences beginning with [ and ending with ], and replaces that sequence with .. I believe this should be quite easy once you know your way around things like that. I'm just not such a person. –  Sverre Jan 25 '13 at 14:19
OK, then I just misunderstood your intentions. –  Benedikt Bauer Jan 25 '13 at 15:04

The built-in way to do such things is with the biblatex \DeclareSourcemap macro. To use this, you have to be using biber. This method is preferable as it has semantic access to biblatex native objects. Try adding this to the preamble of your example above:

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=author,
match=\regexp{$[^]]+$},
replace=.]
}
}
}


There are many other things you can do with this, see section 4.5.2 of the current biblatex manual. This is completely style independent, it alters the data stream from the .bib before biblatex even sees it.

-
Works like a charm! –  Sverre Jan 25 '13 at 19:58

I'm not sure if this is the right way, but it seems to work (part of the code is from this answer by Marco Daniel), particularly in the usage of \DeclareNameFormat and \DeclareNameAlias. Maybe experts in biblatex can improve it.

The following method uses l3regex to get rid of the bracketed parts:

\documentclass{article}
\usepackage{csquotes}
\usepackage[
bibstyle = authoryear,
citestyle = authoryear-comp,
sorting = nyt,
language = american,
abbreviate = false,
backend = biber]{biblatex}

\DeclareNameAlias{sortname}{last-first} % for styles where names are sorted last-first
\DeclareNameFormat{last-first}{%
\usebibmacro{name:last-first}{#1}{\removebrackets{#3}}{#5}{#7}%
\usebibmacro{name:andothers}}

\DeclareNameAlias{sortname}{first-last} % for styles where names are sorted first-last
\DeclareNameFormat{first-last}{%
\usebibmacro{name:first-last}{#1}{\removebrackets{#3}}{#5}{#7}%
\usebibmacro{name:andothers}}

\usepackage{xparse,l3regex}
\ExplSyntaxOn
\NewDocumentCommand{\removebrackets}{m}
{
\sverre_remove_brackets:n { #1 }
}
\cs_new_protected:Npn \sverre_remove_brackets:n #1
{
\tl_set:Nn \l__sverre_input_tl { #1 }
\regex_replace_all:nnN { $.*?$ } { \. } \l__sverre_input_tl
\tl_use:N \l__sverre_input_tl
}
\tl_new:N \l__sverre_input_tl
\ExplSyntaxOff

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{smith2006,
AUTHOR = "Paul G[eorge] J[ohn] Smith",
TITLE = "My life with the Beatles",
YEAR = "2006"}
@BOOK{smith2006x,
AUTHOR = "Paul G[eorge] J[ohn] Smith and Knuth, Donald E[rving]",
TITLE = "My life with the Beatles",
YEAR = "2006"}
@BOOK{smith2006y,
AUTHOR = "Paul G[eorge] J[ohn] Smith and X, Y and A, B and C, D and E, F and G, H",
TITLE = "My life with the Beatles",
YEAR = "2006"}
\end{filecontents}
\begin{document}
\noindent
Text \parencite{smith2006}.

\parencite{smith2006x}
\parencite{smith2006y}
\printbibliography
\end{document}


-
This solution, seems, however, to be tied to the specific style used. If you use the default style numeric instead of authoryear, then this solution doesn't change anything. It would be nice to have a solution that wasn't tied to a specific style like this. –  Sverre Jan 25 '13 at 18:09
@Sverre I guess it depends on the bib macros used with the chosen style. –  egreg Jan 25 '13 at 18:11
I'm not sure what you mean by that. But I think you'll see too that if you just comment out the first three options of the \usepackage[]{biblatex} command (such that it resorts to the default numeric), it will print Smith, Paul G[eorge] J[ohn]. –  Sverre Jan 25 '13 at 18:16
@Sverre It depends on what method is used for typesetting the bibliography, which in turn depends on the options. I just don't know what to change here. –  egreg Jan 25 '13 at 18:24
Given that the numeric style orders the names first-last, I just changed your last-first to first-last, and that did the trick. I'm updating your answer to show this. –  Sverre Jan 25 '13 at 18:49
show 1 more comment
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8281325697898865, "perplexity": 2194.4150153322853}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-23/segments/1405997888210.96/warc/CC-MAIN-20140722025808-00081-ip-10-33-131-23.ec2.internal.warc.gz"}