First answer:
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 \gdef
here. A simple \def
works too.
Second answer
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{%
\addspace\textsc{\bibstring{and}}\space}{\addspace\bibstring{and}\space}}
}
\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}
\addbibresource{\jobname.bib}
\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}
\documentclass{...}
and ending with\end{document}
.&
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.