使用 Biblatex 3.3 命名约定仅显示作者名字的首字母

使用 Biblatex 3.3 命名约定仅显示作者名字的首字母

我试图在引文中仅显示作者名字的首字母。因此,我应该得到以下格式:(J. Kennedy et al., 2023),而不是 (John Fitzgerald Kennedy et al., 2023)。

在 LaTeX 中可以使用 Biblatex 来解决这个问题。但是,代码(来自这里)用于解决这个问题是旧的,并且不使用Biblatex 3.3 命名约定

当我运行以下 MWE 时,出现以下错误:

Illegal parameter number in definition of \blx@defformat@d.

<to be read again> 
4
l.23 \usebibmacro{name:first-last}{#1}{#4
                                       }{#5}{#7}%

Here is how much of LuaTeX's memory you used:
 6844 strings out of 481315
 125171,662416 words of node,token memory allocated
 430 words of node memory still in use:
   2 hlist, 1 rule, 1 dir, 3 kern, 1 glyph, 3 attribute, 59 glue_spec, 3 attribute_list, 1 write nodes
   avail lists: 2:18,3:3,4:3,5:1,7:2,9:3
 23963 multiletter control sequences out of 65536+600000
 25 fonts using 3258707 bytes
 36i,0n,33p,816b,67s stack positions out of 5000i,500n,10000p,200000b,100000s
!  ==> Fatal error occurred, no output PDF file produced!

对此的传统解决方案是:

\documentclass[]{article}

\usepackage{filecontents}
\begin{filecontents*}{bib.bib}
@article{jdoe,
    author       = {John Paul Peter Julian Doe},
    journal  = {Journal},
    title        = {Title},
    year      = 2014,
    pages = 111--222,
}
\end{filecontents*}

\usepackage[style=authoryear]{biblatex}
\addbibresource{bib.bib}

% Helper function to get initial letter
\def\firstinit#1{\justfirst#1\relax}
\def\justfirst#1#2\relax{#1}

% Format for FirstInitials - LastName (standard implementation)
\DeclareNameFormat{firstinits-last}{%
\usebibmacro{name:first-last}{#1}{#4}{#5}{#7}%
\usebibmacro{name:andothers}}

% Format for VeryFirstInitial - LastName
\DeclareNameFormat{firstfirstinit-last}{%
\usebibmacro{name:first-last}{#1}{\firstinit{#4}\adddot}{#5}{#7}%
\usebibmacro{name:andothers}}

% Set format for sortname (bibliography) and labelname (citation)
\DeclareNameAlias{sortname}{firstinits-last}
\DeclareNameAlias{labelname}{firstfirstinit-last}

\begin{document}

\noindent Citation: \cite{jdoe}.

\printbibliography[]

\end{document}

有人能帮助我使用新的代码来调整这个遗留代码吗?Biblatex 3.3命名约定?

答案1

如今,我将使用 的biblatex扩展名称格式(例如,参见仅使用姓氏作为 namepartfamily,而不是前缀后的所有内容如何输入有姓氏和初级部分但没有名字的作者姓名?Bibtex/Biber:如何使用埃塞俄比亚惯例引用作者?)并明确给出首字母

\documentclass{article}

\usepackage[style=authoryear, giveninits=true,]{biblatex}

\DeclareNameAlias{labelname}{given-family}

\begin{filecontents*}{\jobname.bib}
@article{jdoe,
  author  = {family=Doe, given={John Paul Peter Julian}, given-i={J}},
  journal = {Journal},
  title   = {Title},
  year    = 2014,
  pages   = {111--222},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
\noindent Citation: \cite{jdoe}.

\printbibliography
\end{document}

引文:J. Doe 2014.//Doe, J. (2014). “标题”。刊于:期刊,第 111-222 页。


如果你想坚持使用宏解决方案(对于非 ASCII 字符和其他输入,它可能会严重失效),请尝试

\documentclass{article}

\usepackage[style=authoryear]{biblatex}

\def\firstinit#1{\justfirst#1\relax}
\def\justfirst#1#2\relax{#1}

\renewcommand*{\mkbibnamegiven}[1]{%
  \expandafter\firstinit\expandafter{#1}\bibinitperiod}

\DeclareNameAlias{labelname}{given-family}

\begin{filecontents*}{\jobname.bib}
@article{jdoe,
  author  = {John Paul Peter Julian Doe},
  journal = {Journal},
  title   = {Title},
  year    = 2014,
  pages   = {111--222},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
\noindent Citation: \cite{jdoe}.

\printbibliography
\end{document}

在 MWE 中得到相同的结果。

相关内容