# Set biblatex smartand to small caps

I want to apply small caps to the final name delimiter using BibLaTeX. I tried the following

\documentclass{article}

\usepackage[spanish,es-minimal]{babel}
\usepackage[style=american]{csquotes}
\usepackage[style=authoryear-comp,backend=bibtex]{biblatex}

\AtBeginBibliography{%
\def\ifmknamesc{%
\ifboolexpr{ test {\ifcurrentname{labelname}}
or test {\ifcurrentname{author}}
or ( test {\ifnameundef{author}} and test {\ifcurrentname{editor}} ) }}

\renewcommand*{\mkbibnamefirst}[1]{\ifmknamesc{\textsc{#1}}{#1}}
\renewcommand*{\mkbibnamelast}[1]{\ifmknamesc{\textsc{#1}}{#1}}
\renewcommand*{\finalnamedelim}{\ifmknamesc{%
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@InCollection{BarFoo82,
author    = {Mark Bar and John Foo},
title     = {Testing smallcaps and smartand},
booktitle = {Biblatex configuration},
editor    = {Tom Barfoo},
publisher = {Latex},
year      = {1982}
}
\end{filecontents}

\nocite{*}

\begin{document}

\printbibliography

\end{document}


But since I'm writing in Spanish this is not working probably because the smartand counter is being used.

Edit: Looking into the BibLaTeX spanish.lbx file, I found that one can add small caps changing the last two definitions there so that they become:

\gdef\lbx@es@smartand@e#1&{\endgroup \textsc{e}\nobreakspace}
\gdef\lbx@es@smartand@y#1&{\endgroup \textsc{y}\nobreakspace}


However, I would like to do this from the preamble of my document rather than modifying the spanish.lbx file itself. I tried putting the above lines between \makeatother and \makeatother but nothing changed. So how can I do it from the preamble?

-
Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – lockstep Mar 23 '13 at 9:58
The issue is that there is a & in the definition of the commands. Thus you have to change the catcode. spanish.lbx sets \catcode\&=3. With that modification within a \begingroup/\endgroup should be enough to redefine the two auxiliary commands. – Guido Mar 31 '13 at 5:41
@Guido I tried doing what you suggested but I still cannot make it work as I want. Can you post a complete solution as an answer? – petobens Mar 31 '13 at 15:56

The definitions of language commands provided in the lbx files are executed at the beginning of the document (after \begin{document}). This can be found in the documentation of biblatex at page 227 section 4-9:

All localization modules are loaded on demand in the document body.

As written in the comment you have to change the \catcode of special characters like @ or &. Based on this information and with the help of David Carlisle you must add the following definition to your header:

\bgroup%
\catcode\&=3\relax%
\catcode\@11\relax%
\AtBeginDocument{%
\gdef\lbx@es@smartand@e#1&{\endgroup \textsc{e}\nobreakspace}%
\gdef\lbx@es@smartand@y#1&{\endgroup \textsc{y}\nobreakspace}%
}
\egroup


As egreg pointed out, you don't need a \gdefhere. A simple \def works too.

As required the changes of smartend should be done only in the bibliography and only for authors. In my opinion the easiest way is the definition of a new name format for authors which will be activated in the bibliography by the hook \AtBeginBibliography. The new definition via \DeclareNameFormat can't be done in group so you have to handle the catcodes of & and @ carefully.

At the following code to your preamble and it should work. The result is shown below whereby I used \fullcite and a new editor entry.

\catcode\&3\relax%
\catcode\@11\relax%
\DeclareNameFormat{last-first/first-last:smartend}{%
\def\lbx@es@smartand@e##1&{\endgroup \textsc{e}\nobreakspace}%
\def\lbx@es@smartand@y##1&{\endgroup \textsc{y}\nobreakspace}%
\ifnumequal{\value{listcount}}{1}
{\iffirstinits
{\usebibmacro{name:last-first}{#1}{#4}{#5}{#7}}
{\usebibmacro{name:last-first}{#1}{#3}{#5}{#7}}%
\ifblank{#3#5}
{}
{\usebibmacro{name:revsdelim}}}
{\iffirstinits
{\usebibmacro{name:first-last}{#1}{#4}{#5}{#7}}
{\usebibmacro{name:first-last}{#1}{#3}{#5}{#7}}}%
\usebibmacro{name:andothers}}
\AtBeginBibliography{%
\DeclareNameAlias{author}{last-first/first-last:smartend}%
}
\catcode\&4\relax%
\catcode\@12\relax


Here the complete MWE:

\documentclass{article}

\usepackage[spanish,es-minimal]{babel}
\usepackage[style=american]{csquotes}
\usepackage[style=authoryear-comp,backend=biber]{biblatex}

\AtBeginBibliography{%
\def\ifmknamesc{%
\ifboolexpr{ test {\ifcurrentname{labelname}}
or test {\ifcurrentname{author}}
or ( test {\ifnameundef{author}} and test {\ifcurrentname{editor}} ) }}

\renewcommand*{\mkbibnamefirst}[1]{\ifmknamesc{\textsc{#1}}{#1}}
\renewcommand*{\mkbibnamelast}[1]{\ifmknamesc{\textsc{#1}}{#1}}
\renewcommand*{\finalnamedelim}{\ifmknamesc{%
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@InCollection{BarFoo82,
author    = {Mark Bar and John Foo},
editor    = {Mark Foo and John Bar},
title     = {Testing smallcaps and smartand},
booktitle = {Biblatex configuration},
publisher = {Latex},
year      = {1982}
}
\end{filecontents}

\nocite{*}

\catcode\&3\relax%
\catcode\@11\relax%
\DeclareNameFormat{last-first/first-last:smartend}{%
\def\lbx@es@smartand@e##1&{\endgroup \textsc{e}\nobreakspace}%
\def\lbx@es@smartand@y##1&{\endgroup \textsc{y}\nobreakspace}%
\ifnumequal{\value{listcount}}{1}
{\iffirstinits
{\usebibmacro{name:last-first}{#1}{#4}{#5}{#7}}
{\usebibmacro{name:last-first}{#1}{#3}{#5}{#7}}%
\ifblank{#3#5}
{}
{\usebibmacro{name:revsdelim}}}
{\iffirstinits
{\usebibmacro{name:first-last}{#1}{#4}{#5}{#7}}
{\usebibmacro{name:first-last}{#1}{#3}{#5}{#7}}}%
\usebibmacro{name:andothers}}
\AtBeginBibliography{%
\DeclareNameAlias{author}{last-first/first-last:smartend}%
}
\catcode\&4\relax%
\catcode\@12\relax

\begin{document}
\verb+\fullcite{BarFoo82}+

\fullcite{BarFoo82}

\printbibliography

\end{document}

-
I need to have small caps in the smartand counter only in the bibliography (not in the intext citations) and just for authors (not with translators, editors, etc). How can you modify your answer so I can accept it? I guess you could use part of my code above (the \AtBeginBibliography and \ifmknamesc commands)? – petobens Mar 31 '13 at 21:46
@petobens: I edited my answer. – Marco Daniel Apr 1 '13 at 9:07
Works perfectly now – petobens Apr 1 '13 at 22:00
could you please adapt the answer to account for the new name formatting in Biblatex 3.3? Thanks!! – petobens Mar 28 at 2:04

Note: As of March 2016 (biblatex 3.3), you need to change \mkbibnamefamily instead of \mkbibnamelast`. See also Biblatex 3.3 name formatting.

-