将 biblatex smartand 设置为小型大写

将 biblatex smartand 设置为小型大写

我想使用 BibLaTeX 将小写字母应用于最终的名称分隔符。我尝试了以下方法

\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{%
  \addspace\textsc{\bibstring{and}}\space}{\addspace\bibstring{and}\space}}
}

\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}

\addbibresource{\jobname.bib}

\nocite{*}

\begin{document}

\printbibliography

\end{document}

但由于我用西班牙语写作,所以这不起作用,可能是因为smartand使用了计数器。

编辑:查看 BibLaTeXspanish.lbx文件,我发现可以添加小型大写字母,更改其中的最后两个定义,使它们变成:

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

但是,我想从文档的序言部分执行此操作,而不是修改文件spanish.lbx本身。我尝试将上面的几行放在和之间\makeatother\makeatother但没有任何变化。那么我该如何从序言部分执行此操作呢?

答案1

第一个答案:

文件中提供的语言命令定义lbx在文档开头(之后)执行。这可以在第 227 页第 4-9 节\begin{document}的文档中找到:biblatex

所有本地化模块均按文档主体中的需求加载。

正如评论中所写,您必须更改\catcode特殊字符(如@或 )的&。根据此信息并在 David Carlisle 的帮助下,您必须在标题中添加以下定义:

\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

正如 egreg 指出的那样,这里不需要\gdef。简单的\def也可以。


第二个答案

根据要求,smartend 的更改应仅在参考书目中进行,并且仅针对作者进行。在我看来最简单的方法是定义一个新的作者姓名格式,该格式将通过钩子在参考书目中激活\AtBeginBibliography。通过新的定义\DeclareNameFormat不能以组的形式进行,因此您必须小心处理&和的 catcode @

将以下代码添加到您的序言中,它应该可以工作。结果如下所示,其中我使用了\fullcite一个新的编辑器条目。

\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

在此处输入图片描述

以下是完整的 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}

答案2

注意:自 2016 年 3 月 (biblatex 3.3) 起,您需要将 更改\mkbibnamefamily\mkbibnamelast。另请参阅Biblatex 3.3 名称格式

相关内容