如何在参考文献中打印 shortauthor?进一步的问题

如何在参考文献中打印 shortauthor?进一步的问题

这里lockstep 询问如何在参考书目中额外使用 shortauthor 字段。

然而,我想用 shortauthor 完全替换 author 字段。

代替

国际能源署(2005 年)。2005 年世界能源展望……

IEA - 国际能源署 (2005):2005 年世界能源展望....

我更喜欢

IEA(2005):国际能源署。2005 年世界能源展望……

示例代码

\documentclass[ngerman]{scrartcl}
\listfiles
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{iea,
author = {{International Energy Agency}},
title = {World Energy Outlook},
shortauthor = {IEA},
date = {2005}
}
\end{filecontents}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel,csquotes}

\usepackage[
    style=authoryear,
  backend=biber
]{biblatex}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}


\begin{document}
\cite{companion,iea}
\printbibliography
\end{document}

谢谢。

答案1

这里的解决方案必须稍微复杂一些。我们必须对author宏进行大量修改。

\makeatletter
\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\usebibmacro{bbx:savehash}%
        \ifnameundef{shortauthor}% <-------- this is new: prefer shortauthor
          {\printnames{author}}
          {\printnames{shortauthor}}
        \iffieldundef{authortype}
          {\setunit{\addspace}}
          {\setunit{\addcomma\space}}}%
     \iffieldundef{authortype}
       {}
       {\usebibmacro{authorstrg}%
        \setunit{\addspace}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addspace}}%
  \usebibmacro{date+extrayear}%
  \ifnameundef{shortauthor}% <-------- this is new: delay real author until after year
    {}
    {\setunit{\labelnamepunct}\newblock
     \printnames{author}%
     \printunit{\newunitpunct}\newblock}
  }
\makeatother

我们添加了两个\ifnameundef{shortauthor}块:一个用于在开始时优先选择,另一个用于在年份之后打印shortauthor(如果有)。authorauthorshortauthor

在 MWE 中,我们也editor以类似的方式修改了宏

\documentclass[ngerman]{scrartcl}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{iea,
author = {{International Energy Agency}},
title = {World Energy Outlook},
shortauthor = {IEA},
date = {2005}
}
\end{filecontents}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel,csquotes}

\usepackage[
    style=authoryear,
  backend=biber
]{biblatex}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\renewcommand*{\labelnamepunct}{\addcolon\space}

\makeatletter
\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\usebibmacro{bbx:savehash}%
        \ifnameundef{shortauthor}
          {\printnames{author}}
          {\printnames{shortauthor}}
        \iffieldundef{authortype}
          {\setunit{\addspace}}
          {\setunit{\addcomma\space}}}%
     \iffieldundef{authortype}
       {}
       {\usebibmacro{authorstrg}%
        \setunit{\addspace}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addspace}}%
  \usebibmacro{date+extrayear}%
  \ifnameundef{shortauthor}
    {}
    {\setunit{\labelnamepunct}\newblock
     \printnames{author}%
     \printunit{\newunitpunct}\newblock}}

\renewbibmacro*{bbx:editor}[1]{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\ifnameundef{shorteditor}
          {\printnames{editor}}
          {\printnames{shorteditor}}
        \setunit{\addcomma\space}%
        \usebibmacro{bbx:savehash}}%
     \usebibmacro{#1}%
     \clearname{editor}%
     \setunit{\addspace}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addspace}}%
  \usebibmacro{date+extrayear}%
  \ifnameundef{shorteditor}
    {}
    {\setunit{\labelnamepunct}\newblock
     \printnames{editor}%
     \printunit{\newunitpunct}\newblock}}
\makeatother


\begin{document}
\cite{companion,iea}
\printbibliography
\end{document}

MWE 显示:IEA (2005):国际能源署。世界能源展望。

相关内容