你好,我正在使用natbib
兼容模式biblatex
:
\usepackage[style=authoryear-comp, sorting=nyt, natbib,
uniquename=false, maxbibnames=99, dashed=false]{biblatex}
我经常使用作者(年份)的引用格式,即\citet
。
首先,我希望引用的所有部分都有链接——作者和年份(默认只有年份)。所以我遵循了以下解决方案:超链接名称与 biblatex 作者年份
\DeclareCiteCommand{\cite}
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\printtext[bibhyperref]{\usebibmacro{cite}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand*{\cite}
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\printtext[bibhyperref]{\usebibmacro{citeyear}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\parencite}[\mkbibparens]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\printtext[bibhyperref]{\usebibmacro{cite}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand*{\parencite}[\mkbibparens]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\printtext[bibhyperref]{\usebibmacro{citeyear}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\footcite}[\mkbibfootnote]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\printtext[bibhyperref]{\usebibmacro{cite}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\printtext[bibhyperref]{\usebibmacro{cite}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\textcite}
{\boolfalse{cbx:parens}}
{\usebibmacro{citeindex}%
\printtext[bibhyperref]{\usebibmacro{textcite}}}
{\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\multicitedelim}
{\usebibmacro{textcite:postnote}}
然后,我想将链接的颜色改为蓝色,所以我更改了超集中的设置:
\usepackage[hyperfootnotes=true,bookmarksopen]{hyperref}
\hypersetup{
pdffitwindow=false,
pdfstartview={XYZ null null 1.00},
pdfnewwindow=true,
colorlinks=true, % false: boxed links; true: colored links
linkcolor=darkblue, % Color of internal links
citecolor=darkblue, % Color of links to bibliography
urlcolor=darkblue} % Color of external links
但是,一旦我调用\citet
,比如说 XX(2000),XX(2000) 的颜色是深蓝色,但 ) 的颜色是黑色。
有没有什么办法可以将 ( 的颜色固定为黑色?
答案1
完整链接对于 来说很难biblatex
。因此,默认情况下只链接年份是有充分理由的。看看https://tex.stackexchange.com/a/27615/35864为 的全链接解决方案,为 的两个括号都着色\textcite
。
另外,我可以给你提供我曾经在 golatex.de 上给出的这个答案:https://golatex.de/biblatex-textcite-link-fehler-bei-einem-autor-t20366.html(至少我认为是我……)
\documentclass{article}
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage[backend=biber,
style=authoryear-comp,]{biblatex}
\usepackage{hyperref}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{AuthorA2000,
author = {AuthorA},
title = {TitleA},
year = {2000}
}
@article{AuthorB2001,
author = {AuthorB},
title = {TitleB},
year = {2001}
}
@article{AuthorC2002a,
author = {AuthorC},
title = {TitleCa},
year = {2002}
}
@article{AuthorC2002b,
author = {AuthorC},
title = {TitleCb},
year = {2002}
}
@article{AuthorC2002c,
author = {AuthorC},
title = {TitleCc},
year = {2002}
}
@article{AuthorC2003,
author = {AuthorC},
title = {TitleC3},
year = {2003}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\makeatletter
\newrobustcmd{\blx@imc@transparentprinttext}[2][]{%
\ifblank{#2}
{}
{\ifblank{#1}
{\let\blx@theformat\@firstofone}
{\blx@getformat\blx@theformat{ffd}{#1}{}}%
\ifdefvoid\blx@theformat
{}
{\blx@theformat{#2}}}}
\blx@regimcs{\transparentprinttext}
\DeclareCiteCommand{\textcite}[\cbx@textcite@init\cbx@textcite]
{\gdef\cbx@savedkeys{}%
\citetrackerfalse%
\pagetrackerfalse%
\DeferNextCitekeyHook%
\usebibmacro{cite:init}%
\global\undef\cbx@lasthash
\global\undef\cbx@lastyear}
{\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}
{\protected@xappto\cbx@savedcites{()(\thefield{multipostnote})}%
\global\clearfield{multipostnote}}
{}%
\xappto\cbx@savedkeys{\thefield{entrykey},}%
\iffieldequals{namehash}{\cbx@lasthash}
{\iffieldequals{labelyear}{\cbx@lastyear}
{\csnumgdef{cbx@textcite@state@\the\c@citecount}{2}}
{\csnumgdef{cbx@textcite@state@\the\c@citecount}{1}%
\savefield{labelyear}{\cbx@lastyear}}}
{\csnumgdef{cbx@textcite@state@\the\c@citecount}{0}%
\stepcounter{textcitetotal}%
\savefield{namehash}{\cbx@lasthash}}}
{}
{\protected@xappto\cbx@savedcites{%
[\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}
\DeclareFieldFormat{citehyperref}{%
\DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
\bibhyperref{#1}}
\DeclareFieldFormat{textcitehyperref}{%
\DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
\bibhyperref{%
#1%
\ifnumgreater{\value{citecount}+1}{\value{citetotal}}
{\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}}
{\ifnumequal{\csuse{cbx@textcite@state@\the\numexpr\c@citecount+1\relax}}{0}
{\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}}
{}}}}
\savebibmacro{cite}
\savebibmacro{textcite}
\renewbibmacro*{cite}{%
\printtext[citehyperref]{%
\restorebibmacro{cite}%
\usebibmacro{cite}}}
\renewbibmacro*{textcite}{%
\ifboolexpr{
( not test {\iffieldundef{prenote}} and
test {\ifnumequal{\value{citecount}}{1}} )
or
( not test {\iffieldundef{postnote}} and
test {\ifnumequal{\value{citecount}}{\value{citetotal}}} )
}
{\DeclareFieldAlias{textcitehyperref}{noformat}}
{}%
\transparentprinttext[textcitehyperref]{%
\restorebibmacro{textcite}%
\usebibmacro{textcite}}}
\makeatother
\begin{document}
First, single cites which are working: \textcite{AuthorA2000} and so on \textcite{AuthorB2001} and so on \textcite{AuthorC2002a} and so on \textcite{AuthorC2002b} and so on \textcite{AuthorC2002c}. This works!
\par
Now combined: Different Authors \\
Two: \textcite{AuthorA2000,AuthorB2001}\\
Three: \textcite{AuthorA2000,AuthorB2001,AuthorC2002a}\\
Works again! \par
Now combined, single author same year
The problem if linking is on: \textcite{AuthorC2002a,AuthorC2002b,AuthorC2002c} \par
Same Author, diff year: Same problem: \textcite{AuthorC2002a,AuthorC2003}
\parencite{knuth:ct:a,knuth:ct:b}
\printbibliography
\end{document}
这是一个永远不会链接(颜色)括号的解决方案。对于\cite
/\parencite
我们可以使用 Audrey 的方法超链接名称与 biblatex 作者年份 (biblatex 1.4b)。但是因为\textcite
只想额外链接名称,所以我们用 修补 bibmacrotextcite
来xpatch
链接标签名称。
\documentclass{article}
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage[backend=biber,
style=authoryear-comp,]{biblatex}
\usepackage{hyperref}
\DeclareFieldFormat{citehyperref}{%
\DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
\bibhyperref{#1}}
\savebibmacro{cite}
\renewbibmacro*{cite}{%
\printtext[citehyperref]{%
\restorebibmacro{cite}%
\usebibmacro{cite}}}
\usepackage{xpatch}
\xpatchbibmacro{textcite}
{\printnames{labelname}}
{\printtext[bibhyperref]{\printnames{labelname}}}
{}{}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{AuthorA2000,
author = {AuthorA},
title = {TitleA},
year = {2000}
}
@article{AuthorB2001,
author = {AuthorB},
title = {TitleB},
year = {2001}
}
@article{AuthorC2002a,
author = {AuthorC},
title = {TitleCa},
year = {2002}
}
@article{AuthorC2002b,
author = {AuthorC},
title = {TitleCb},
year = {2002}
}
@article{AuthorC2002c,
author = {AuthorC},
title = {TitleCc},
year = {2002}
}
@article{AuthorC2003,
author = {AuthorC},
title = {TitleC3},
year = {2003}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\begin{document}
First, single cites which are working: \textcite{AuthorA2000} and so on \textcite{AuthorB2001} and so on \textcite{AuthorC2002a} and so on \textcite{AuthorC2002b} and so on \textcite{AuthorC2002c}. This works!
\par
Now combined: Different Authors \\
Two: \textcite{AuthorA2000,AuthorB2001}\\
Three: \textcite{AuthorA2000,AuthorB2001,AuthorC2002a}\\
Works again! \par
Now combined, single author same year
The problem if linking is on: \textcite{AuthorC2002a,AuthorC2002b,AuthorC2002c} \par
Same Author, diff year: Same problem: \textcite{AuthorC2002a,AuthorC2003}
\parencite{knuth:ct:a,knuth:ct:b}
\printbibliography
\end{document}