环境:scrartcl、带有 biber 后端的 biblatex、带有一些修改的 authortitle 样式
我的教育机构要求我用大写字母写下每个作者的姓氏。为此,我使用了 DeclareNameFormat 和\MakeUppercase
。
\DeclareNameFormat{author}{%
\nameparts{#1}%
\usebibmacro{name:family-given}
{\MakeUppercase{\namepartfamily}}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}%
}
这会产生副作用,即公司名称也会以大写形式书写,即使放在双花括号中也是如此。我该如何改变这种行为,让我可以只以大写形式书写“普通”作者姓名,而无需更改文档类别或参考书目样式?
书目条目示例:
@misc{rfc4025,
series = {Request for Comments},
number = 4025,
howpublished = {RFC 4025},
publisher = {RFC Editor},
doi = {10.17487/RFC4025},
url = {https://rfc-editor.org/rfc/rfc4025.txt},
author = {Michael Richardson},
title = {{A Method for Storing IPsec Keying Material in DNS}},
pagetotal = 12,
date = 2005,
month = mar,
urldate = {2021-09-29},
}
上面的代码运行并生成RICHARDSON, Michael: A Method for Storing IPsec Keying Material in DNS, [...]
@misc{corporate,
title = {A title},
author = {{The Company}},
url = {https://example.org},
urldate = {2021-10-01},
}
这会产生类似THE COMPANY: A title, [...]
答案1
您可以测试是否存在姓氏,但法人作者则不存在。
\begin{filecontents*}{\jobname.bib}
@misc{rfc4025,
series = {Request for Comments},
number = 4025,
howpublished = {RFC 4025},
publisher = {RFC Editor},
doi = {10.17487/RFC4025},
url = {https://rfc-editor.org/rfc/rfc4025.txt},
author = {Michael Richardson},
title = {{A Method for Storing IPsec Keying Material in DNS}},
pagetotal = 12,
date = 2005,
month = mar,
urldate = {2021-09-29},
}
@misc{corporate,
title = {A title},
author = {{The Company}},
url = {https://example.org},
urldate = {2021-10-01},
}
\end{filecontents*}
\documentclass{article}
\usepackage{biblatex}
\addbibresource{\jobname.bib}
\DeclareNameFormat{author}{%
\nameparts{#1}%
\usebibmacro{name:family-given}
{\expandafter\ifblank\expandafter{\namepartgiven}
{\namepartfamily}% no family name, don't uppercase
{\MakeUppercase{\namepartfamily}}%
}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}%
}
\begin{document}
\cite{rfc4025} and \cite{corporate}
\printbibliography
\end{document}
答案2
我认为将逻辑构建到实际格式化姓氏(\mkbibnamefamily
)的命令中比将实际名称部分传递给大写宏然后再将其发送给biblatex
格式化宏要自然一些。
\documentclass{article}
\usepackage{biblatex}
\renewcommand*{\mkbibnamefamily}[1]{%
\ifdefvoid{\namepartgiven}
{#1}
{\MakeUppercase{#1}}}
\DeclareNameAlias{author}{sortname}
\DeclareNameAlias{editor}{sortname}
\DeclareNameAlias{translator}{sortname}
\DeclareNameAlias{sortname}{family-given}
\begin{filecontents*}{\jobname.bib}
@misc{rfc4025,
series = {Request for Comments},
number = 4025,
howpublished = {RFC 4025},
publisher = {RFC Editor},
doi = {10.17487/RFC4025},
url = {https://rfc-editor.org/rfc/rfc4025.txt},
author = {Michael Richardson},
title = {A Method for Storing {IPsec} Keying Material in {DNS}},
pagetotal = 12,
date = 2005,
month = mar,
urldate = {2021-09-29},
}
@misc{corporate,
title = {A title},
author = {{The Company}},
url = {https://example.org},
urldate = {2021-10-01},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\cite{rfc4025} and \cite{corporate}
\printbibliography
\end{document}
严格来说,上面的定义有点不合常规,因为\mkbibnamefamily
理想情况下不应该引用\namepart...
宏。如果我们想避免这种情况,我们需要一些技巧,让代码“稍微”长一点。
\documentclass{article}
\usepackage{biblatex}
\newtoggle{bbx:nogivenname}
\renewbibmacro*{name:family-given}[4]{%
\ifdefvoid{#2}
{\toggletrue{bbx:nogivenname}}
{}%
\ifuseprefix
{\usebibmacro{name:delim}{#3#1}%
\usebibmacro{name:hook}{#3#1}%
\mkbibcompletenamefamilygiven{%
\ifdefvoid{#3}
{}
{\ifcapital
{\mkbibnameprefix{\MakeCapital{#3}}\isdot}
{\mkbibnameprefix{#3}\isdot}%
\ifprefchar{}{\bibnamedelimc}}%
\mkbibnamefamily{#1}\isdot
\ifdefvoid{#4}
{}
{\bibnamedelimd\mkbibnamesuffix{#4}\isdot}%
\ifdefvoid{#2}
{}
{\revsdnamepunct\bibnamedelimd\mkbibnamegiven{#2}\isdot}}}
{\usebibmacro{name:delim}{#1}%
\usebibmacro{name:hook}{#1}%
\mkbibcompletenamefamilygiven{%
\mkbibnamefamily{#1}\isdot
\ifdefvoid{#4}
{}
{\bibnamedelimd\mkbibnamesuffix{#4}\isdot}%
\ifboolexpe{%
test {\ifdefvoid{#2}}
and
test {\ifdefvoid{#3}}}
{}
{\revsdnamepunct}%
\ifdefvoid{#2}
{}
{\bibnamedelimd\mkbibnamegiven{#2}\isdot}%
\ifdefvoid{#3}
{}
{\bibnamedelimd\mkbibnameprefix{#3}\isdot}}}}
\renewcommand*{\mkbibnamefamily}[1]{%
\iftoggle{bbx:nogivenname}
{#1}
{\MakeUppercase{#1}}}
\DeclareNameAlias{author}{sortname}
\DeclareNameAlias{editor}{sortname}
\DeclareNameAlias{translator}{sortname}
\DeclareNameAlias{sortname}{family-given}
\begin{filecontents*}{\jobname.bib}
@misc{rfc4025,
series = {Request for Comments},
number = 4025,
howpublished = {RFC 4025},
publisher = {RFC Editor},
doi = {10.17487/RFC4025},
url = {https://rfc-editor.org/rfc/rfc4025.txt},
author = {Michael Richardson},
title = {A Method for Storing {IPsec} Keying Material in {DNS}},
pagetotal = 12,
date = 2005,
month = mar,
urldate = {2021-09-29},
}
@misc{corporate,
title = {A title},
author = {{The Company}},
url = {https://example.org},
urldate = {2021-10-01},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\cite{rfc4025} and \cite{corporate}
\printbibliography
\end{document}