The alphabetic label gets produced by Biber and is passed on to biblatex
in the .bbl
file. biblatex
doesn't really have a sense of what the label is composed of and only sees the complete label, so the formatting has to be shoehorned in at label creation.
We can modify the label format with \DeclareLabelalphaTemplate
and apply formatting there. But we have to take into account that the label definitions are written to the .bcf
file, which makes it tricky to add macros to the definition, since they usually get expanded when writing to files. That's definitely not what we want here. To avoid expansion we need a fair bit of \string
in the definition, the braces for the arguments are even trickier, they need \@charlb
and \@charrb
(see Writing { and } to a file with LaTeX). We can avoid some headaches for more complex macros if we define two helper macros to format the label parts.
With
\documentclass{article}
\usepackage[style=alphabetic]{biblatex}
\addbibresource{biblatex-examples.bib}
% Using colors to clarify
\usepackage{xcolor}
\newcommand*{\mklabelalphaname}[1]{\color{green}{\textsc{#1}}}
\newcommand*{\mklabelalphayear}[1]{\textcolor{red}{\oldstylenums{#1}}}
\makeatletter
\DeclareLabelalphaTemplate{
\labelelement{
\literal{\string\mklabelalphaname\@charlb}
}
\labelelement{
\field[final]{shorthand}
\field{label}
\field[strwidth=3,strside=left,ifnames=1,lowercase=true]{labelname}
\field[strwidth=1,strside=left,lowercase=true]{labelname}
}
\labelelement{
\literal{\@charrb\string\mklabelalphayear\@charlb}
}
\labelelement{
\field[strwidth=2,strside=right]{year}
}
\labelelement{
\literal{\@charrb}
}
}
\makeatother
\begin{document}
Desired: [\textcolor{green}{\textsc{sr}}\oldstylenums{\textcolor{red}{98}}]
Current: \cite{sigfridsson}
\printbibliography
\end{document}
the .bbl
contains
\field{labelalpha}{\mklabelalphaname{sr}\mklabelalphayear{98}}
and together with the definitions of \mklabelalphaname
and \mklabelalphayear
produces
