# How to use small caps for all biblatex (style=alpha) references with capital letters?

Is it possible to use small caps for all biblatex (style=alpha) references that consist out of capital letters?

The following MWE should demonstrate the goal:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{hammond,
author       = {Hammond, Christopher},
title        = {The basics of crystallography and diffraction},
date         = 1997,
publisher    = {International Union of Crystallography and Oxford
University Press},
location     = {Oxford},
langid       = {english},
langidopts   = {variant=british},
sorttitle    = {Basics of crystallography and diffraction},
indextitle   = {Basics of crystallography and diffraction, The},
shorttitle   = {Crystallography and diffraction},
annotation   = {A \texttt{book} entry. Note the \texttt{sorttitle} and
\texttt{indextitle} fields as well as the format of the
\texttt{publisher} field},
}

@article{sarfraz,
author       = {M. Sarfraz and M. F. A. Razzak},
title        = {Technical section: {An} algorithm for automatic
capturing of the font outlines},
year         = 2002,
volume       = 26,
number       = 5,
pages        = {795-804},
issn         = {0097-8493},
journal      = {Computers and Graphics},
annotation   = {An \texttt{article} entry with an \texttt{issn} field},
}

@book{companion,
author       = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
title        = {The {LaTeX} Companion},
date         = 1994,
edition      = 1,
pagetotal    = 528,
langid       = {english},
langidopts   = {variant=american},
sorttitle    = {LaTeX Companion},
indextitle   = {LaTeX Companion, The},
shorttitle   = {LaTeX Companion},
annotation   = {A book with three authors. Note the formatting of the
author list. By default, only the first name is reversed in the
bibliography},
}

@article{murray,
author       = {Hostetler, Michael J. and Wingate, Julia E. and Zhong,
Chuan-Jian and Harris, Jay E. and Vachet, Richard W. and
Clark, Michael R.  and Londono, J. David and Green, Stephen
J. and Stokes, Jennifer J.  and Wignall, George D. and Glish,
Gary L. and Porter, Marc D.  and Evans, Neal D. and Murray,
Royce W.},
title        = {Alkanethiolate gold cluster molecules with core
diameters from 1.5 to 5.2~{nm}},
journaltitle = {Langmuir},
date         = 1998,
subtitle     = {Core and monolayer properties as a function of core
size},
volume       = 14,
number       = 1,
pages        = {17-30},
langid       = {english},
langidopts   = {variant=american},
indextitle   = {Alkanethiolate gold cluster molecules},
shorttitle   = {Alkanethiolate gold cluster molecules},
annotation   = {An \texttt{article} entry with \arabic{author} authors.
By default, long author and editor lists are
automatically truncated. This is configurable},
}
\end{filecontents}

\usepackage[english]{babel}
\usepackage[style=alphabetic,sorting=none,backend=biber]{biblatex}

\begin{document}

Single Author \cite{hammond} ($\leftarrow$ leave untouched)

Two Authors \cite{sarfraz} ($\leftarrow$ use small caps)

Three Authors \cite{companion} ($\leftarrow$ use small caps)

Many Authors \cite{murray} ($\leftarrow$ leave untouched)

\bigskip

Preferred output (at least within the text and optionally also within the bibliography list):
[Ham97], \textsc{[Sr02], [Gms94]}, [Hos+98]

\printbibliography

\end{document}

• Do you really want \textsc{Sr} or do you want \textsc{sr}? (I'd find the former a bit confusing as it somehow puts more emphasis on the first name ...) – moewe Aug 24 '16 at 9:44
• @moewe I had exactly the same concerns. But the former is prefered. – lAtExFaN Aug 24 '16 at 9:54
• @moewe I thought about it again and replaced the word ideally in the MWE with "optionally". The idea behind this update: Typographically optimized output in the text - no differentiation (typographically induced ranking) in the bibliography list. The option is for those who think that the ref-labels [Xxx] should be identical between text and list – lAtExFaN Aug 25 '16 at 11:52

Well testing for capital letters is not so easy, but if as your example implies you want the change for two and three authors you could try to do it like this.

I didn't test what happens if there are Umlauts etc and if \MakeSentenceCase can handle them. Also I don't think that this a good style, I find it confusing.

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{hammond,
author       = {Hammond, Christopher},
title        = {The basics of crystallography and diffraction},
date         = 1997,
publisher    = {International Union of Crystallography and Oxford
University Press},
location     = {Oxford},
langid       = {english},
langidopts   = {variant=british},
sorttitle    = {Basics of crystallography and diffraction},
indextitle   = {Basics of crystallography and diffraction, The},
shorttitle   = {Crystallography and diffraction},
annotation   = {A \texttt{book} entry. Note the \texttt{sorttitle} and
\texttt{indextitle} fields as well as the format of the
\texttt{publisher} field},
}

@article{sarfraz,
author       = {M. Sarfraz and M. F. A. Razzak},
title        = {Technical section: {An} algorithm for automatic
capturing of the font outlines},
year         = 2002,
volume       = 26,
number       = 5,
pages        = {795-804},
issn         = {0097-8493},
journal      = {Computers and Graphics},
annotation   = {An \texttt{article} entry with an \texttt{issn} field},
}

@book{companion,
author       = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
title        = {The {LaTeX} Companion},
date         = 1994,
edition      = 1,
pagetotal    = 528,
langid       = {english},
langidopts   = {variant=american},
sorttitle    = {LaTeX Companion},
indextitle   = {LaTeX Companion, The},
shorttitle   = {LaTeX Companion},
annotation   = {A book with three authors. Note the formatting of the
author list. By default, only the first name is reversed in the
bibliography},
}

@article{murray,
author       = {Hostetler, Michael J. and Wingate, Julia E. and Zhong,
Chuan-Jian and Harris, Jay E. and Vachet, Richard W. and
Clark, Michael R.  and Londono, J. David and Green, Stephen
J. and Stokes, Jennifer J.  and Wignall, George D. and Glish,
Gary L. and Porter, Marc D.  and Evans, Neal D. and Murray,
Royce W.},
title        = {Alkanethiolate gold cluster molecules with core
diameters from 1.5 to 5.2~{nm}},
journaltitle = {Langmuir},
date         = 1998,
subtitle     = {Core and monolayer properties as a function of core
size},
volume       = 14,
number       = 1,
pages        = {17-30},
langid       = {english},
langidopts   = {variant=american},
indextitle   = {Alkanethiolate gold cluster molecules},
shorttitle   = {Alkanethiolate gold cluster molecules},
annotation   = {An \texttt{article} entry with \arabic{author} authors.
By default, long author and editor lists are
automatically truncated. This is configurable},
}
\end{filecontents}

\usepackage[english]{babel}
\usepackage[style=alphabetic,sorting=none,backend=biber]{biblatex}
\usepackage{xcolor}
\DeclareFieldFormat{labelalpha}{%
\ifboolexpr{
test {\ifnumcomp{\value{\thefield{labelnamesource}}}{=}{2}}
or
test {\ifnumcomp{\value{\thefield{labelnamesource}}}{=}{3}}
}
{\textsc{\MakeSentenceCase{#1}}}
{#1}%
}

\begin{document}

Single Author \cite{hammond} ($\leftarrow$ leave untouched)

Two Authors \cite{sarfraz} ($\leftarrow$ use small caps)

Three Authors \cite{companion} ($\leftarrow$ use small caps)

Many Authors \cite{murray} ($\leftarrow$ leave untouched)

\bigskip

Preferred output (at least within the text and optionally also within the bibliography list):
[Ham97], \textsc{[Sr02], [Gms94]}, [Hos+98]

\printbibliography

\end{document}


• Thank you for the answer. Since we explicitly ask for author here, this does not scale to well for entries where the label is taken from editor. Do you think it would be possible to check for the "labelalphaname" number instead? – moewe Sep 8 '16 at 12:04
• @moewe: I don't think that biber stores this number, but there is the field labelnamesource . I changed \value{author} to \value{\thefield{labelnamesource}}. Seems to work fine ... – Ulrike Fischer Sep 8 '16 at 12:11
• Brilliant. I'm thinking if one could avoid mentioning the 2 and 3 explicitly by testing against maxalphanames – moewe Sep 8 '16 at 12:16
• Thank you very much, moeve for the bounty and UlrikeFischer for the (very) acceptable answer - which seems to be at least a good starting point for further testing and investigation! – lAtExFaN Sep 8 '16 at 21:27