缩写作者姓名 biblatex

缩写作者姓名 biblatex

在学术演讲中,引用自己的一篇论文时通常不写全名。

例如,在 John Smith 的 Beamer 演示中,引用此人及其合著者 Mary Taylor 撰写的一篇论文时,应显示为 (JS and Taylor 2016)。我正在寻找一种避免接触 .bib 文件的方法,因为该文件无论如何都是通过其他方式生成的。

这是一个 MWE;

\documentclass{beamer}

\usepackage{filecontents}
\begin{filecontents}{biblio.bib}
@article{publication1,
    author  = "John Smith and Mary Taylor",
    title   = "title",
    year    = "2016",
    journal = "some journal",
}  \end{filecontents}
\usepackage[backend=biber,citestyle=authoryear,bibstyle=authortitle]{biblatex}
\addbibresource{biblio.bib}
\begin{document}

\begin{frame}
Here is the citation; (\cite{publication1})

I would want instead that it shows automatically (JS and Taylor 2016)
\end{frame}

\end{document}

在此处输入图片描述

答案1

我们可以使用 的biblatex名称哈希来比较名称。您需要知道您名称的哈希。可以在文件中查找,.bbl如中所述使用 biblatex 突出显示参考书目中的作者,并允许使用参考书目样式对其进行格式化. 对于“John Smith”,我们5d0ddda3a367ceb26fbaeca02e391c22在 MWE 中有。

然后我们只需要修改labelname格式来检查“John Smith”。5d0ddda3a367ceb26fbaeca02e391c22用您的姓名的哈希和JS缩写替换。

\DeclareNameFormat{labelname}{%
  \iffieldequalstr{hash}{5d0ddda3a367ceb26fbaeca02e391c22}
    {JS}
    {\ifcase\value{uniquename}%
      \usebibmacro{name:family}
        {\namepartfamily}
        {\namepartgiven}
        {\namepartprefix}
        {\namepartsuffix}%
    \or
      \ifuseprefix
        {\usebibmacro{name:given-family}
          {\namepartfamily}
          {\namepartgiveni}
          {\namepartprefix}
          {\namepartsuffixi}}
        {\usebibmacro{name:given-family}
          {\namepartfamily}
          {\namepartgiveni}
          {\namepartprefixi}
          {\namepartsuffixi}}%
    \or
      \usebibmacro{name:given-family}
        {\namepartfamily}
        {\namepartgiven}
        {\namepartprefix}
        {\namepartsuffix}%
    \fi}
  \usebibmacro{name:andothers}}

平均能量损失

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{publication1,
    author  = "John Smith and Mary Taylor",
    title   = "title",
    year    = "2016",
    journal = "some journal",
}  \end{filecontents}
\usepackage[backend=biber,citestyle=authoryear,bibstyle=authortitle]{biblatex}
\addbibresource{\jobname.bib}


\DeclareNameFormat{labelname}{%
  \iffieldequalstr{hash}{5d0ddda3a367ceb26fbaeca02e391c22}
    {JS}
    {\ifcase\value{uniquename}%
      \usebibmacro{name:family}
        {\namepartfamily}
        {\namepartgiven}
        {\namepartprefix}
        {\namepartsuffix}%
    \or
      \ifuseprefix
        {\usebibmacro{name:given-family}
          {\namepartfamily}
          {\namepartgiveni}
          {\namepartprefix}
          {\namepartsuffixi}}
        {\usebibmacro{name:given-family}
          {\namepartfamily}
          {\namepartgiveni}
          {\namepartprefixi}
          {\namepartsuffixi}}%
    \or
      \usebibmacro{name:given-family}
        {\namepartfamily}
        {\namepartgiven}
        {\namepartprefix}
        {\namepartsuffix}%
    \fi}
  \usebibmacro{name:andothers}}

\begin{document}
\parencite{publication1} vs.\ (JS and Taylor 2016)
\end{document}

给出

(JS 和 Taylor 2016) vs. (JS 和 Taylor 2016)

答案2

以下是使用 biblatex 3.5/biber 2.6 的新数据注释功能(目前位于 Sourceforge 上的开发文件夹中)的解决方案。这是一个更通用的解决方案,因为它不需要知道任何内部信息(如哈希值),您只需在 .bib 中注释您的姓名即可启用该行为(也可以通过源映射自动执行):

\documentclass{article}
\usepackage[style=authoryear]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{publication1,
  author  = "John Smith and Mary Taylor",
  author+an  = "1=me",
  title   = "title",
  year    = "2016",
  journal = "some journal",
}
\end{filecontents}
\addbibresource{\jobname.bib}

\DeclareNameFormat{labelname}{%
  \ifcase\value{uniquename}%
    \ifitemannotation{me}
      {\def\bibnamedelimd{}%
       \usebibmacro{name:given-family}
        {\namepartfamily}
        {\namepartgiven}
        {\namepartprefix}
        {\namepartsuffix}}
      {\usebibmacro{name:family}
        {\namepartfamily}
        {\namepartgiven}
        {\namepartprefix}
        {\namepartsuffix}}%
  \or
    \ifuseprefix
      {\usebibmacro{name:given-family}
        {\namepartfamily}
        {\namepartgiveni}
        {\namepartprefix}
        {\namepartsuffixi}}
      {\usebibmacro{name:given-family}
        {\namepartfamily}
        {\namepartgiveni}
        {\namepartprefixi}
        {\namepartsuffixi}}%
  \or
    \usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}%
  \fi
  \usebibmacro{name:andothers}}

\renewcommand*{\mkbibnamegiven}[1]{%
  \ifitemannotation{me}
    {\StrLeft{#1}{1}}
    {#1}}

\renewcommand*{\mkbibnamefamily}[1]{%
  \ifitemannotation{me}
    {\StrLeft{#1}{1}}
    {#1}}

\begin{document}

\cite{publication1} = JS and Taylor 2016

\end{document}

相关内容