添加第三个选项,用于将所有格插入 \textcite

添加第三个选项,用于将所有格插入 \textcite

因此,我使用biblatexAPA 格式进行引用。

我在叙述性引用中遇到的一个问题是,我经常必须使用作者的所有格。(例如爱因斯坦和玻尔 (1920) 的报告等等……)

\textcite[pre][post]{bibid}命令用于叙述引用,仅接受两个输入字符串,即引用之前和引用之后:

,爱因斯坦和玻尔(1920 年,邮政

我想要重新定义命令以包含第三个可选参数,用于在作者后面插入文本:

\textcite[pre][mid][post]{bibid}

我正在思考这样的事情:

\renewcommand{\textcite}[3][bibid]{#1, \citeauthor{bibid}#2 \citeyear[#3]{bibid}}

导致

、爱因斯坦和玻尔(1920年,邮政

那么,我怎样才能创建这样的命令,不会失去自动完成功能bibtex 密钥?当我开始在命令中输入密钥时,我仍然希望获取密钥列表。

由于我使用所有格的频率远高于前后文本,因此我希望命令采用插入为仅有的可选参数,没有前置和后置参数。

答案1

biblatex用's定义的引用命令\DeclareCiteCommand始终具有相同的参数结构

\<commandname>[<prenote>][<postnote>]{<keys>}

参数结构几乎是硬编码的\DeclareCiteCommand,无法更改。

当然,您不必使用<prenote>and<postnote>作为前置和后置注释,因此您可以将论点转换<prenote>为属格标记(见下文),但从根本上说,您无法更改论点结构。

有一个技巧可以解决这个问题:biblatex \cite 中另一个可选参数内的可选参数奥黛丽展示了一种将圆括号中的虚拟参数添加到postnote参数中的方法。

\textcite我们可以对预注做同样的事情。这样你就可以使用

\textcite[(mid)pre][post]{key}
\textcite[(mid)][post]{key}
\textcite[pre][post]{key}
\textcite[post]{key}
\textcite{key}

bibmacro的重新定义textcite是原来的(参见apa.cbx,ll. 215-261)有两行

        \csuse{cbx@prenote@genitivemarker}%
        \global\undef\cbx@prenote@genitivemarker

添加以在正确位置打印属格标记。我们还将新的 bibmacro 添加split:prenote\DeclareCiteCommand{\textcite}

\documentclass{article}
\usepackage[style=apa]{biblatex}
\usepackage[colorlinks]{hyperref}

\makeatletter
\newrobustcmd*{\splitroundarg}[3]{\splitroundarg@i{#1}{#2}#3&}

\def\splitroundarg@i#1#2{%
  \@ifnextchar(%)
    {\splitroundarg@ii{#1}{#2}}
    {\splitroundarg@ii{#1}{#2}()}}

\def\splitroundarg@ii#1#2(#3)#4&{%
  #1{#3}%
  #2{#4}}

\newrobustcmd*{\mkgenitivemarker}[1]{%
  \ifblank{#1}
    {\undef\cbx@prenote@genitivemarker}
    {\def\cbx@prenote@genitivemarker{#1}}}

\newrobustcmd*{\mkrealprenote}[1]{%
  \ifblank{#1}
    {\undef\abx@field@prenote}
    {\def\abx@field@prenote{#1}}}

\newcommand*{\splitgenmarkerrealprenote}{\splitroundarg{\mkgenitivemarker}{\mkrealprenote}}

\newbibmacro*{split:prenote}{%
  \iffieldundef{prenote}
    {}
    {\usefield{\splitgenmarkerrealprenote}{prenote}}}

\DeclareCiteCommand{\textcite}
  {\usebibmacro{cite:init}%
   \usebibmacro{split:prenote}%
   \usebibmacro{prenote}%
   \toggletrue{apa:intcite}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}%
   \usebibmacro{cite:post}%
   \togglefalse{apa:intcite}}
  {}
  {\usebibmacro{textcite:postnote}}


\renewbibmacro*{textcite}{%
  \iffieldequals{fullhash}{\cbx@lasthash}
% Compact cite - more than one thing for same author
    {\setunit{\compcitedelim}%
     \usebibmacro{cite:plabelyear+extradate}}
% New cite
    {%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
      \setunit{\compcitedelim}%
      \ifnameundef{labelname}
  % No author/editor
       {\iffieldundef{shorthand}%
    % Cite using title
         {\usebibmacro{cite:noname}%
          \setunit{\ifbool{cbx:np}%
                   {\printdelim{nameyeardelim}}%
                   {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
          \usebibmacro{cite:plabelyear+extradate}}
    % Cite using shorthand
         {\usebibmacro{cite:shorthand}}}
  % Normal cite with author/editor
  % Normal full cite
       {\ifnameundef{shortauthor}%
    % Normal full cite
         {\printnames{labelname}}
    % Cite using short author
         {\cbx@apa@ifnamesaved
           {\printnames{shortauthor}}
           {\ifnameundef{groupauthor}
             {\printnames[labelname]{author}}
             {\printnames[labelname]{groupauthor}}}}%
        \csuse{cbx@prenote@genitivemarker}%
        \global\undef\cbx@prenote@genitivemarker
  % Year
        \setunit{\ifbool{cbx:np}
                  {\printdelim{nameyeardelim}}
                  {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
  % Put the shortauthor inside the year brackets if necessary
        \ifnameundef{shortauthor}
         {}
         {\cbx@apa@ifnamesaved
           {}
           {\printnames{shortauthor}\setunit{\printdelim{nameyeardelim}}}}%
  % Actual year printing
        \usebibmacro{cite:plabelyear+extradate}%
  % Save name hash for checks later
        \savefield{fullhash}{\cbx@lasthash}}}}
\makeatother

\addbibresource{biblatex-examples.bib}
\begin{document}

\textcite[('s)][]{sigfridsson}

\textcite[('s)][380]{sigfridsson}

\textcite[cf.][380]{sigfridsson}

\textcite[380]{sigfridsson}

\textcite{sigfridsson}

\printbibliography
\end{document}

Sigfridsson 和 Ryde (1998)//Sigfridsson 和 Ryde (1998, 第 380 页)//参见 Sigfridsson 和 Ryde (1998, 第 380 页)//Sigfridsson 和 Ryde (1998, 第 380 页)//Sigfridsson 和 Ryde (1998)


如上所述,您还可以重新利用 prenote 参数\textcite。但您不能再使用普通的 prenotes。

\documentclass{article}
\usepackage[style=apa]{biblatex}
\usepackage[colorlinks]{hyperref}

\DeclareCiteCommand{\textcite}
  {\usebibmacro{cite:init}%
   \toggletrue{apa:intcite}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}%
   \usebibmacro{cite:post}%
   \togglefalse{apa:intcite}}
  {}
  {\usebibmacro{textcite:postnote}}

\makeatletter
\renewbibmacro*{textcite}{%
  \iffieldequals{fullhash}{\cbx@lasthash}
% Compact cite - more than one thing for same author
    {\setunit{\compcitedelim}%
     \usebibmacro{cite:plabelyear+extradate}}
% New cite
    {%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
      \setunit{\compcitedelim}%
      \ifnameundef{labelname}
  % No author/editor
       {\iffieldundef{shorthand}%
    % Cite using title
         {\usebibmacro{cite:noname}%
          \setunit{\ifbool{cbx:np}%
                   {\printdelim{nameyeardelim}}%
                   {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
          \usebibmacro{cite:plabelyear+extradate}}
    % Cite using shorthand
         {\usebibmacro{cite:shorthand}}}
  % Normal cite with author/editor
  % Normal full cite
       {\ifnameundef{shortauthor}%
    % Normal full cite
         {\printnames{labelname}}
    % Cite using short author
         {\cbx@apa@ifnamesaved
           {\printnames{shortauthor}}
           {\ifnameundef{groupauthor}
             {\printnames[labelname]{author}}
             {\printnames[labelname]{groupauthor}}}}%
        \ifnumequal{\value{citecount}}{1}
          {\thefield{prenote}}
          {}%
  % Year
        \setunit{\ifbool{cbx:np}
                  {\printdelim{nameyeardelim}}
                  {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
  % Put the shortauthor inside the year brackets if necessary
        \ifnameundef{shortauthor}
         {}
         {\cbx@apa@ifnamesaved
           {}
           {\printnames{shortauthor}\setunit{\printdelim{nameyeardelim}}}}%
  % Actual year printing
        \usebibmacro{cite:plabelyear+extradate}%
  % Save name hash for checks later
        \savefield{fullhash}{\cbx@lasthash}}}}
\makeatother

\addbibresource{biblatex-examples.bib}
\begin{document}
\textcite['s][]{sigfridsson}

\textcite['s][380]{sigfridsson}

\textcite[380]{sigfridsson}

\textcite{sigfridsson}

\printbibliography
\end{document}

或者你重新利用后记

\documentclass{article}
\usepackage[style=apa]{biblatex}
\usepackage[colorlinks]{hyperref}

\DeclareCiteCommand{\textcite}
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}%
   \toggletrue{apa:intcite}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}%
   \usebibmacro{cite:post}%
   \togglefalse{apa:intcite}}
  {}
  {\ifbool{cbx:parens}
    {\bibcloseparen\global\boolfalse{cbx:parens}}
    {}}

\makeatletter
\renewbibmacro*{textcite}{%
  \iffieldequals{fullhash}{\cbx@lasthash}
% Compact cite - more than one thing for same author
    {\setunit{\compcitedelim}%
     \usebibmacro{cite:plabelyear+extradate}}
% New cite
    {%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
      \setunit{\compcitedelim}%
      \ifnameundef{labelname}
  % No author/editor
       {\iffieldundef{shorthand}%
    % Cite using title
         {\usebibmacro{cite:noname}%
          \setunit{\ifbool{cbx:np}%
                   {\printdelim{nameyeardelim}}%
                   {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
          \usebibmacro{cite:plabelyear+extradate}}
    % Cite using shorthand
         {\usebibmacro{cite:shorthand}}}
  % Normal cite with author/editor
  % Normal full cite
       {\ifnameundef{shortauthor}%
    % Normal full cite
         {\printnames{labelname}}
    % Cite using short author
         {\cbx@apa@ifnamesaved
           {\printnames{shortauthor}}
           {\ifnameundef{groupauthor}
             {\printnames[labelname]{author}}
             {\printnames[labelname]{groupauthor}}}}%
        \ifnumequal{\value{citecount}}{1}
          {\thefield{postnote}}
          {}%
  % Year
        \setunit{\ifbool{cbx:np}
                  {\printdelim{nameyeardelim}}
                  {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
  % Put the shortauthor inside the year brackets if necessary
        \ifnameundef{shortauthor}
         {}
         {\cbx@apa@ifnamesaved
           {}
           {\printnames{shortauthor}\setunit{\printdelim{nameyeardelim}}}}%
  % Actual year printing
        \usebibmacro{cite:plabelyear+extradate}%
  % Save name hash for checks later
        \savefield{fullhash}{\cbx@lasthash}}}}
\makeatother

\addbibresource{biblatex-examples.bib}
\begin{document}
\textcite['s]{sigfridsson}

\textcite[cf.]['s]{sigfridsson}

\textcite{sigfridsson}

\printbibliography
\end{document}

所有上述解决方案都应保留编辑器的引用关键字自动完成功能。自动完成不是 LaTeX 的功能,而是编辑器的功能。通常编辑器都有硬编码的引用命令列表,它们将在其中提供引用关键字自动完成功能。

相关内容