8

In my bibliography, I need to abreviate first names keeping digraphs and trigraphs.

  • John should be abreviated as J.
  • Clare should be abreviated as Cl.
  • Charles should be abreviated as Ch.
  • Christine should be abreviated as Chr.
  • Philippe should be abreviated as Ph.
  • etc.

The solution is to modify the first name in the bibliographical data from

Charles

to

{\relax Ch}arles


The following example uses the \DeclareSourcemap customization macro in Biblatex to change Charles to {\relax Ch}arles but I'm looking for a more generic solution that would automatically modify all first names starting with two or three consonants.

\documentclass{article}
\usepackage{filecontents}
 \begin{filecontents}{\jobname.bib}
  @book{Book1,
  author = {Doe, Charles},
  title  = {An Important Book},
  publisher = {Publisher},
  date = {2012},
}
@book{Book2,
  author = {Doe, Charlotte},
  title  = {Another Important Book},
  publisher = {Publisher},
  date = {2014},
}
@book{Book3,
  author = {Smith, Theodore},
  title  = {A very Important Book},
  publisher = {Publisher},
  date = {2016},
}
\end{filecontents}
\usepackage[style=verbose,firstinits=true, backend=biber]{biblatex}
\DeclareSourcemap{
 \maps[datatype=bibtex]{
    \map{
    \step[fieldsource=author, 
            match={Charles},
            replace=\regexp{\{\\relax \x20Ch\}arles}]
  }
 }
}
\addbibresource{\jobname.bib}
\begin{document}

\cite{Book1}

\cite{Book2}

\cite{Book3}

\end{document}

Result

lockstep
  • 250,273

1 Answers1

5

A possible starting point would be to use the code Yves de Saint-Pern wrote in class droit-fr, which I am translating below.

EDIT : The regular expressions provided here catch last names as well, which may cause issues outside Biblatex, for instance in indexes done with imakeidx. A tentative solution to this problem is provided here.

You can use it in a biber.conf file or include it in your .bbx.

Some languages may require additional regex patterns for first names, but they are pretty straightforward to add.

\DeclareStyleSourcemap{%
  \maps[datatype=bibtex]{%
    \map{%
        % Author field
      \step[fieldsource=author,%
        match={\regexp{\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))(\S*,)}},%
        replace={\regexp{\{$1\}$3}}]% Protect last names (first last)
      \step[fieldsource=author,%
        match={\regexp{([^,]\s)\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))}},%
        replace={\regexp{$1\{$2\}}}]% Protect last names (last, first)
      \step[fieldsource=author,%
        match={\regexp{\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))([^\}])}},%
        replace={\regexp{\{\\relax\{\}$1\}$3}}]% Insert \relax after abbreviating
      % Editor field
      \step[fieldsource=editor,%
        match={\regexp{\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))(\S*,)}},%
        replace={\regexp{\{$1\}$3}}]% Protect last names (first last)
      \step[fieldsource=editor,%
        match={\regexp{([^,]\s)\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))}},%
        replace={\regexp{$1\{$2\}}}]% Protect last names (last, first)
      \step[fieldsource=editor,%
        match={\regexp{\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))([^\}])}},%
        replace={\regexp{\{\\relax\{\}$1\}$3}}]% Insert \relax after abbreviating
}}}%

As far as the regular expressions are concerned, I am no expert but I would hazard that the expression means this:

\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))(\S*,)

A word (\b) that starts with (\S* means: ends with any number of non-space characters): Chr (Chris) or Ch (Charles) or Th (Thomas) or Ph (Philippe), or any combination that starts with a consonant (the [B-DF-HJ-NP-TV-XZ part is a set of ranges: letters B to D, F to H, J to N, P to T, V to X, Z) followed by l or r (Bruno or Claire would fall within that category).

ienissei
  • 6,223
  • Thank you. I found https://github.com/ienissei/frenchlaw/ on your github how is that related to droit-fr, if you don't mind me asking? I'm not great with RegEx, so I would really appreciate an explanation if you can find the time. I would be especially interested in the [B-DF-HJ-NP-TV-XZ] bit. – moewe Feb 23 '16 at 14:57
  • Class droit-fr is meant for writing french dissertations in legal studies, and I am working on a very similar project (by coincidence more than by design, as I started with it before this class was published). It was updated lately and I saw the feature on the log. – ienissei Feb 23 '16 at 15:02
  • @moewe – Added the explanation – ienissei Feb 23 '16 at 15:12
  • 1
    Ahh, I see. Thank you also for the explanation, I now noticed I had failed to see the (l|r) after the [B-DF-HJ-NP-TV-XZ] bit. – moewe Feb 23 '16 at 15:14
  • @ienissei how can this only be applied to first names - and not to last names? see http://tex.stackexchange.com/q/330971/98739 – lukascbossert Sep 23 '16 at 14:20
  • @LukasCB Commenting under your question. – ienissei Sep 23 '16 at 16:53
  • How can I get it work only for Chr|Ch|Th|Ph|St ? – lukascbossert Sep 23 '16 at 17:51
  • @LukasCB Just remove the rest of the string. Change: (Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r)) to (Chr|Ch|Th|Ph|St) – ienissei Sep 23 '16 at 18:17
  • @ienissei thanks. I realized that ()(before (l|r) is important to keep, otherwise the first letter after Chr|Ch|Th|Ph|St will be omitted; correct:(Chr|Ch|Th|Ph|St)() – lukascbossert Sep 23 '16 at 18:19
  • @LukasCB Yes, because the replacement string looks for three groups, which are the text between (), so you could also change $3 to $2 for the same result. – ienissei Sep 23 '16 at 18:37