我正在使用\textcite
在某处找到的自定义宏。它工作得很好,只是它使“作者(年份)”的左括号成为链接的一部分(并将其着色为蓝色),这是不理想的。
这可能只是对宏定义的一个小改动,但解决方案却让我困惑(我完全不明白在哪里添加了左括号)。
开头的括号不应该是链接的一部分,也不应被涂上颜色。
我们:
\documentclass{scrartcl}
\usepackage{csquotes}
\usepackage[backend=biber,
bibencoding=utf8,
hyperref=true,
natbib=true,
minnames=1, %% prevent truncation to year-only
backref=true, %% TODO REMOVE before final
bibstyle=apa,
citestyle=authoryear,
]{biblatex}
\DeclareLanguageMapping{english}{english-apa}
\addbibresource{bib.bib}
\DeclareCiteCommand{\textcite}
{\boolfalse{cbx:parens}}
{\usebibmacro{citeindex}%
\printtext[bibhyperref]{\usebibmacro{textcite}}}
{\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\multicitedelim}
{\usebibmacro{textcite:postnote}}
\usepackage[table,svgnames]{xcolor}
\definecolor{solblue}{HTML}{268BD2}
\usepackage[pdftex]{hyperref}
\hypersetup{
pdfhighlight = /P,
colorlinks=true,
urlcolor=solblue,
filecolor=solblue,
linkcolor=solblue,
citecolor=solblue,
raiselinks=true,
breaklinks,
unicode
}
\begin{document}
foobar \textcite{thesis_pockrandt} foobar
\end{document}
bib.bib:
@phdthesis{thesis_pockrandt,
author = {Christopher Maximilian Pockrandt},
title = {{Approximate String Matching: Improving Data Structures and Algorithms}},
year = {2019}
}
答案1
在评论中讨论之后,我将回答这个问题style=authoryear,
(或者更准确地说citestyle=authoryear,
)。如果你对 APA 样式的解决方案感兴趣(当然,这同样citestyle=apa,
重要),请参阅BibLaTeX 颜色和链接仅显示年份,不显示其余引文。
获得更充分的链接的原理与BibLaTeX 颜色和链接仅显示年份,不显示其余引文只是调整为(更简单的)引用样式authoryear
。
再次强调,有很多方法可以获得更大的链接区域(超链接名称与 biblatex 作者年份 (biblatex 1.4b),超链接名称与 biblatex 作者年份,Biblatex、authoryear-comp 和超链接,citet 和 citep 的括号颜色不一致),但我觉得这个是最安全的(但肯定不是最短的)
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear, backend=biber]{biblatex}
\usepackage{xcolor}
\usepackage{hyperref}
\renewbibmacro*{cite}{%
\printtext[bibhyperref]{%
\iffieldundef{shorthand}
{\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
{\usebibmacro{cite:label}%
\setunit{\printdelim{nonameyeardelim}}}
{\printnames{labelname}%
\setunit{\printdelim{nameyeardelim}}}%
\usebibmacro{cite:labeldate+extradate}}
{\usebibmacro{cite:shorthand}}}}
\renewbibmacro*{citeyear}{%
\printtext[bibhyperref]{%
\iffieldundef{shorthand}
{\iffieldundef{labelyear}
{\usebibmacro{cite:label}}
{\usebibmacro{cite:labeldate+extradate}}}
{\usebibmacro{cite:shorthand}}}}
\renewbibmacro*{textcite}{%
\ifnameundef{labelname}
{\iffieldundef{shorthand}
{\printtext[bibhyperref]{%
\usebibmacro{cite:label}}%
\setunit{%
\global\booltrue{cbx:parens}%
\printdelim{nonameyeardelim}\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\printtext[bibhyperref]{\usebibmacro{cite:labeldate+extradate}}}
{\printtext[bibhyperref]{\usebibmacro{cite:shorthand}}}}
{\printtext[bibhyperref]{\printnames{labelname}}%
\setunit{%
\global\booltrue{cbx:parens}%
\printdelim{nameyeardelim}\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\usebibmacro{citeyear}}}
\renewbibmacro*{cite:shorthand}{%
\printfield{shorthand}}
\renewbibmacro*{cite:label}{%
\iffieldundef{label}
{\printfield[citetitle]{labeltitle}}
{\printfield{label}}}
\renewbibmacro*{cite:labeldate+extradate}{%
\printlabeldateextra}
\definecolor{solblue}{HTML}{268BD2}
\hypersetup{
pdfhighlight = /P,
colorlinks=true,
urlcolor=solblue,
filecolor=solblue,
linkcolor=solblue,
citecolor=solblue,
raiselinks=true,
breaklinks,
unicode,
}
\addbibresource{biblatex-examples.bib}
\begin{document}
lorem \textcite{sigfridsson} ipsum
dolor \autocite{sigfridsson} sit
\printbibliography
\end{document}