\textcite 的速记输出意外

\textcite 的速记输出意外

我想用shorthand它来缩写出版物的作者。不幸的是,\textcite它没有产生预期的输出。

梅威瑟:

\begin{filecontents}{myfile.bib}
@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}
\end{filecontents}

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage[backend=biber,citestyle=authoryear]{biblatex}
\addbibresource{myfile.bib}

\begin{document}

\cite{goossens93} \\
\parencite{goossens93} \\    
\textcite{goossens93}

\end{document}

正如预期的那样,给出以下输出:

Goossens, Mittelbach, and Samarin 1993
(Goossens, Mittelbach, and Samarin 1993)
Goossens, Mittelbach, and Samarin (1993)

当我添加shorthand = "GMS"到 BIB 条目时,输出变为

GMS
(GMS)
Goossens, Mittelbach, and Samarin (GMS)

但我希望\textcite输出类似的东西\cite

有没有办法来解决这个问题?

我不想重新定义\textcite 全球因为还有其他没有简写的参考文献,我不想破坏它们,也不想用它们来代替,\cite\textcite保留以后放弃简写的机会。

编辑: 回应 LaRiFaRi 的评论:我想要改变\textcite,但只针对围兜物品速记。

MWE2:

\begin{filecontents}{myfile.bib}
@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
%    shorthand = "GMS"
}

@book{else2015,
    author    = "Someone Else",
    title     = "Interesting thing.",
    year      = "2015"
}
\end{filecontents}

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage[backend=biber,citestyle=authoryear]{biblatex}
\addbibresource{myfile.bib}

\begin{document}

Some guys called \textcite{goossens93} wrote something about LaTeX and \textcite{else2015} also wrote something interesting. 

\end{document}

#1 输出:Some guys called Goossens, Mittelbach, and Samarin (1993) wrote something about LaTeX and Else (2015) also wrote something interesting.

#2 简写输出:Some guys called Goossens, Mittelbach, and Samarin (GMS) wrote something about LaTeX and Else (2015) also wrote something interesting.

#3 所需输出的简写形式:Some guys called GMS wrote something about LaTeX and Else (2015) also wrote something interesting.

为什么不对\textcite所有引用进行全局重新定义?因为我不想改变else2015引用方式。

为什么不使用\cite?因为我可能会改变主意并shorthand从 BIB 文件中删除该字段。然后我想要像 #1 中的输出 - 只有当我不使用\cite而不是 时我才会得到它\textcite

答案1

您可以使用

\AtEveryCitekey{\iffieldundef{shorthand}{}{\clearname{labelname}}}

答案2

下一个项目,仍然使用简写。Ulrike 的回答labelname完美地回答了这个问题,我会将其标记为已接受。然而,在实践中,该解决方案产生了一个新问题:清除每个带有 的 citekey 的字段shorthand使得完全不可能在需要的地方使用正常引用而不是简写。

因此,这是一个延伸的答案,借鉴了 Ulrike 的方法

  • \textcite修复有简写字段时的显示方式(我想看到GMS的不是Goossens, Mittelbach, and Samarin (GMS)
  • 保留避免速记的机会。

解决方案的关键是用来\AtNextCitekey清除labelname每个引用,而不是像 Ulrike 的答案那样全局执行此操作。

  • 为了产生正确的简写引用,我们需要\AtNextCitekey{\iffieldundef{shorthand}{}{\clearname{labelname}}}
  • 为了生成正确的“长”引文,我们需要shorthand按照后半部分的建议清除字段这个答案\AtNextCitekey{\clearfield{shorthand}}

为了默认生成简写引用,我重新定义了\textcite,并利用了xparse包中的功能,如下所述这里处理多个可选参数:

\usepackage{xparse}
\let\oldtextcite\textcite

\DeclareDocumentCommand{\textcite}{ O{} o m }{%
    \AtNextCitekey{\iffieldundef{shorthand}{}{\clearname{labelname}}}%
    \IfNoValueTF{#2}%
        {\oldtextcite[#1]{#3}}%
        {\oldtextcite[#1][#2]{#3}}}

为了避免用\AtNextCitekey{\clearfield{shorthand}}命令弄乱我的文档,我另外定义了\textciteLong

\DeclareDocumentCommand{\textciteLong}{ O{} o m}{%
    \AtNextCitekey{\clearfield{shorthand}}%
    \IfNoValueTF{#2}%
        {\oldtextcite[#1]{#3}}%
        {\oldtextcite[#1][#2]{#3}}}

我希望这能让使用简写authoryear更加实用。下面是一个完整的示例。


\begin{filecontents}{myfile.bib}
@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    shorthand = "GMS"
}

@book{else2015,
    author    = "Someone Else",
    title     = "Interesting thing.",
    year      = "2015"
}
\end{filecontents}

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage[backend=biber,citestyle=authoryear]{biblatex}
\addbibresource{myfile.bib}

\usepackage{xparse}
\let\oldtextcite\textcite

\DeclareDocumentCommand{\textcite}{ O{} o m }{%
    \AtNextCitekey{\iffieldundef{shorthand}{}{\clearname{labelname}}}%
    \IfNoValueTF{#2}%
        {\oldtextcite[#1]{#3}}%
        {\oldtextcite[#1][#2]{#3}}}
\DeclareDocumentCommand{\textciteLong}{ O{} o m}{%
    \AtNextCitekey{\clearfield{shorthand}}%
    \IfNoValueTF{#2}%
        {\oldtextcite[#1]{#3}}%
        {\oldtextcite[#1][#2]{#3}}}

\begin{document}

\begin{itemize}
    \item Entry without shorthand: \textcite{else2015}
    \item Entry with shorthand: \textcite{goossens93}
    \item Ignore the shorthand: \textciteLong{goossens93}
\end{itemize} 

\end{document}

输出:

• Entry without shorthand: Else (2015)
• Entry with shorthand: GMS
• Ignore the shorthand: Goossens, Mittelbach, and Samarin (1993)

相关内容