![如何将文内引用设置为斜体?](https://linux22.com/image/437556/%E5%A6%82%E4%BD%95%E5%B0%86%E6%96%87%E5%86%85%E5%BC%95%E7%94%A8%E8%AE%BE%E7%BD%AE%E4%B8%BA%E6%96%9C%E4%BD%93%EF%BC%9F.png)
我使用 biblatex 的 authoryear-comp citestyle,希望文内引用中的作者和年份以斜体显示。经过一番研究,我找到了以下命令,但它只会将作者显示为斜体:
\renewcommand{\mkbibnamelast}[1]{\mkbibemph{#1}}
有谁知道如何根据以下示例将年份也变为斜体?
\documentclass{scrbook}
\usepackage[backend=biber, bibstyle=authoryear, citestyle=authoryear-comp,sorting=nyt]{biblatex}
\addbibresource{\jobname.bib}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{Knu86,
author = {Knuth, Donald E.},
year = {1986},
title = {The \TeX book},
}
\end{filecontents*}
非常感谢您看完这篇文章并致以最良好的祝愿,
答案1
使引用变为斜体的一种方法是将想要以斜体显示的相关命令\mkbibemph
的包装器代码注入其中。\DeclareCiteCommand
\...cite
您可以\DeclareCiteCommand
在<citestyle>.cbx
(就您的情况而言authoryear-comp.cbx
)中找到声明。请注意,这些定义在不同的样式之间可能有所不同,因此您需要确保获得了正确的定义。
在示例中,我们展示了如何使\cite
/\cite*
和\parencite
/\parencite*
变为斜体。原始定义可以在authoryear-comp.cbx
,v3.18b 中的第 160-190 行:因为\cite
我们只是添加\mkbibemph
包装器命令(因为\cite
没有包装器)。因为\parencite
我们\mkbibemph
与包装器结合(更改和\mkbibparens
的顺序以使括号也变为斜体)。\mkbibemph
\mkbibparens
\mkbibemphparens
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber, style=authoryear-comp]{biblatex}
\DeclareCiteCommand{\cite}[\mkbibemph]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}}
{}
{\usebibmacro{postnote}}
\DeclareCiteCommand*{\cite}[\mkbibemph]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{citeyear}}
{}
{\usebibmacro{postnote}}
\newcommand*{\mkbibemphparens}[1]{\mkbibparens{\mkbibemph{#1}}}
\DeclareCiteCommand{\parencite}[\mkbibemphparens]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}}
{}
{\usebibmacro{postnote}}
\DeclareCiteCommand*{\parencite}[\mkbibemphparens]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{citeyear}}
{}
{\usebibmacro{postnote}}
\addbibresource{biblatex-examples.bib}
\begin{document}
Lorem \autocite{sigfridsson}
ipsum \parencite{nussbaum}
dolor \cite{worman}
\printbibliography
\end{document}