Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\addbibresource{\jobname.bib}
\begin{document}
\noindent
Text \parencite{smith2006}.
\printbibliography
\end{document}

enter image description here

share|improve this question
    
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
add comment

2 Answers 2

up vote 8 down vote accepted

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.

share|improve this answer
    
Works like a charm! –  Sverre Jan 25 '13 at 19:58
add comment

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}
\addbibresource{\jobname.bib}
\begin{document}
\noindent
Text \parencite{smith2006}.

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

enter image description here

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.