[Tex/LaTex] Custom Biblatex reference style

biblatex

I am trying to get my bibliography to show the references as [ABCD01], where:

  • ABCD are the first 4 letters of the first author's last name (with an underscore replacing the missing characters if the last name is shorter than 4 letters),

  • 01 are the last 2 digits of the year.

How can I do this?

PS: If ABCD could be in smallcaps, that would be even better but I don't know if this can be done.

Best Answer

You ask several things in the question. Here is my proposed solution, with an explanation following.

Sample output

\documentclass{article}

\usepackage{xstring}
\usepackage[style=alphabetic,maxbibnames=99]{biblatex}
\addbibresource{ref.bib}

\DeclareLabelalphaTemplate{
  \labelelement{
    \field[strwidth=4,strside=left,names=1,lowercase]{labelname}
    }
  \labelelement{
    \field[strwidth=2,strside=right]{year}
    }
}

\renewcommand{\labelalphaothers}{}

\DeclareFieldFormat{labelalpha}{\textsc{\padded{#1}}}
%\DeclareFieldFormat{extraalpha}{\textsc{\mknumalph{#1}}}

\newcommand{\padded}[1]{\begingroup%
\expandarg\StrGobbleRight{#1}{2}[\mystr]%
\StrLeft{\mystr \textunderscore\textunderscore\textunderscore\textunderscore}{4}%
\StrRight{#1}{2}%
\endgroup}

\begin{document}

\cite{one,oneo,two,three,four}
\printbibliography

\end{document}

with ref.bib given at the end of my answer.

Firstly, the alphabetic style is the closest to the one you request and is modifiable via the \DeclareLabelalphaTemplate. The code above pulls off up to four characters from the last name of the first author, adds to the two final digits of the year, and final a letter to disambiguate if necessary. We make the letters lowercase in preparation for makeing them small caps.

The command setting \labelalphaothers to null, ensures that no + sign is added when there are several authors.

The formatting of the labels as small caps is acheived via changing the field format of labelalpha. This is the part of the label up to and including the year digits, but not the disambiguation letter. If you want that in small caps then uncomment the line with extraalpha.

Now I use the xstring package to deal with the padding issue via a command \padded. We pull off the year, add on underscores and take just the first four characters. Then we put the year back on. The \expandarg command ensures that only \mystring gets expanded in the argument to \StrLeft, expanding the underscores would give problems.

@Article{one,
  author =   {Author, A. N. and Brother, K. and Style, D.},
  title =    {One article},
  journal =  {J. J.},
  year =     2003
}

@Article{oneo,
  author =   {Any, A. N. and Brother, K. and Stile, D.},
  title =    {One article},
  journal =  {J. J.},
  year =     2003
}

@Misc{three,
  author =   {Ma, A. and Many, B. and Many, C. and Many, D. and
                  Many, E.},
  title =    {One page},
  year =     2005
}

@Misc{four,
  author =   {Ma, A. and Many, B. and Many, C. and Many, D. and
                  Many, F.},
  title =    {One page},
  year =     2005
}

@Book{two,
  author =   {Weeks, P. and Days, X. and Years, R. and Months, S.},
  editor =   {May, X.},
  title =    {One book},
  publisher =    {U. Publ.},
  year =     2001
}