# 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},
address   = {Knuth Place},
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},
address   = {Knuth Place},
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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9034911394119263, "perplexity": 2968.3215721931165}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-42/segments/1414119645573.31/warc/CC-MAIN-20141024030045-00283-ip-10-16-133-185.ec2.internal.warc.gz"}