Biblatex:如何使用 /textcite 和速记获取括号中的年份

Biblatex:如何使用 /textcite 和速记获取括号中的年份

我对一些引文使用了简写,通常使用 \textcite 来获取不带括号的作者和带括号的年份。我的问题是,对于使用简写的参考文献,\textcite 会将年份替换为第一个引文的简写。

我希望第一个引用的格式如下:作者(年份,“此后”简写)

以及以下内容:速记

梅威瑟:

\documentclass[british,a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{filecontents}
\usepackage[backend=biber,style=authoryear,citetracker=true,bibstyle=authoryear]{biblatex}
\DefineBibliographyStrings{english}{citedas = {hereafter}}

\begin{filecontents*}{\jobname.bib}
@article{jd14,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {Some Title},
  journal = {Some Journal},
  year    = {2014},
  shorthand = {JD14},
}
@article{jd13,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {No shorthand here},
  journal = {Some Other Journal},
  year    = {2013},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

\newbibmacro*{longcite}{%
  \ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
    {\usebibmacro{cite:label}%
     \setunit{\addspace}}
    {\printnames{labelname}%
     \setunit{\nameyeardelim}}%
  \usebibmacro{cite:labelyear+extrayear}}

\renewbibmacro*{cite}{%
  \ifciteseen
    {\iffieldundef{shorthand}
      {\usebibmacro{longcite}}
      {\usebibmacro{cite:shorthand}}}
    {\usebibmacro{longcite}
     \usebibmacro{shorthandintro}}}

\begin{document}
  \cite{jd14} again \cite{jd14}.

  Just for comparison \textcite{jd13}.

  \printbibliography
\end{document}

例子

答案1

我建议您采用textcite而不是cite,因为它看起来更像您想要的最终结果。以下内容产生指定的引用:

\documentclass[british,a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{filecontents}
\usepackage[backend=biber,style=authoryear,citetracker=true,bibstyle=authoryear]{biblatex}
\DefineBibliographyStrings{english}{citedas = {hereafter}}

\begin{filecontents*}{\jobname.bib}
@article{jd14,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {Some Title},
  journal = {Some Journal},
  year    = {2014},
  shorthand = {JD14},
}
@article{jd13,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {No shorthand here},
  journal = {Some Other Journal},
  year    = {2013},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

\renewbibmacro*{textcite}{%
    \ifnameundef{labelname}
    {\iffieldundef{shorthand}
        {\usebibmacro{cite:label}%
            \setunit{%
                \global\booltrue{cbx:parens}%
                \printdelim{nonameyeardelim}\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
            \usebibmacro{cite:labelyear+extrayear}}
        {\usebibmacro{cite:shorthand}}}
    {\iffieldundef{shorthand}
        {\printnames{labelname}%
            \setunit{%
                \global\booltrue{cbx:parens}%
                \printdelim{nameyeardelim}\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
            \usebibmacro{citeyear}}
        {\ifciteseen
            {\usebibmacro{cite:shorthand}}
            {\printnames{labelname}%
                \setunit{%
                    \global\booltrue{cbx:parens}%
                    \printdelim{nameyeardelim}\bibopenparen}%
                \ifnumequal{\value{citecount}}{1}
                {\usebibmacro{prenote}}
                {}%
                \iffieldundef{labelyear}
                {\usebibmacro{cite:label}
                    \setunit{\addcomma\addspace}%
                    \iffieldundef{shorthandintro}
                    {\printtext{\bibstring{citedas}}}
                    {\printtext{\printfield{shorthandintro}}}
                    \usebibmacro{cite:shorthand}}
                {\usebibmacro{cite:labelyear+extrayear}
                    \setunit{\addcomma\addspace}%
                    \iffieldundef{shorthandintro}
                    {\printtext{\bibstring{citedas}}}
                    {\printtext{\printfield{shorthandintro}}}
                    \usebibmacro{cite:shorthand}}}}}}

\begin{document}
  \textcite{jd14} again \textcite{jd14}.

  Just for comparison \textcite{jd13}.

  \printbibliography
\end{document}

这给了我们:

在此处输入图片描述

如果不需要处理原始样式中最初处理的所有缺失/存在字段的情况,textcite那么您可能可以简化这一点。authoryear

答案2

如果您想要标准的前后注位置,重新定义\cite而不是使用可能会很有益。\textcite

尝试

\documentclass[british,a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage[backend=biber, style=authoryear, citetracker=true]{biblatex}
\DefineBibliographyStrings{english}{citedas = {hereafter}}

\newbibmacro*{shorthandintro:noparen}{%
  \iffieldundef{shorthandintro}
    {\iffieldundef{shorthand}
       {}
       {\setunit{\addcomma\space}%
        \bibstring{citedas}\space
        \printfield{shorthand}}}
    {\setunit{\addcomma\space}%
     \printfield{shorthandintro}}}

\newbibmacro*{cite:normal}{%
  \ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
    {\usebibmacro{cite:label}%
     \setunit{\printdelim{nonameyeardelim}}}
    {\printnames{labelname}%
     \setunit{\printdelim{nameyeardelim}}}%
  \printtext{\bibopenparen}%
  \usebibmacro{cite:labeldate+extradate}}

\renewbibmacro*{cite}{%
  \ifciteseen
    {\iffieldundef{shorthand}
       {\usebibmacro{cite:normal}%
        \printtext{\bibcloseparen}}
       {\usebibmacro{cite:shorthand}}}
    {\usebibmacro{cite:normal}%
     \usebibmacro{shorthandintro:noparen}%
     \printtext{\bibcloseparen}}}

\begin{filecontents*}{\jobname.bib}
@article{jd14,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {Some Title},
  journal = {Some Journal},
  year    = {2014},
  shorthand = {JD14},
}
@article{jd13,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {No shorthand here},
  journal = {Some Other Journal},
  year    = {2013},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
  \cite{jd14} again \cite{jd14}.

  Just for comparison \textcite{jd13}.

  \printbibliography
\end{document}

Doe, Smith and Bar (2014,以下称为 JD14) 再次 JD14。仅供比较 Doe, Smith and Bar (2013)。

相关内容