0

Hi I am using the natbib compatibility mode under biblatex:

\usepackage[style=authoryear-comp, sorting=nyt, natbib,
            uniquename=false, maxbibnames=99, dashed=false]{biblatex}

I frequently use the citation format of author (year), that is \citet.

First, I wanted to have link for all parts of the citation -- author and year (default is just year). So I followed the solution here: hyperlink name with biblatex authoryear

\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}}

Then, I wanted to change color of the links to be blue, so I changed the setting in hyperset:

\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

However, once I call \citet, say XX(2000), the color for XX(2000 is in darkblue but the color for ) is in black.

Is there anyway to fix the color of ( to be black?

  • 2
    Welcome to TeX.se. Instead of posting fragments of code, can you combine them into a compilable document that people can play with. – Alan Munn Jun 24 '18 at 4:44
  • Linking biblatex citations is hard, take a look at tex.stackexchange.com/a/27615/35864 – moewe Jun 24 '18 at 9:34
  • Note that copying the answer from tex.stackexchange.com/questions/1687/… which is for style=authoryear destroys some of the features of style=authoryear-comp which you are using. – moewe Jun 24 '18 at 9:44
  • I also tried "style=authoryear" and things seem to stay the same – James H Jun 24 '18 at 16:49
4

Full linking is hard for biblatex. So there is a good reason why only the year is linked by default. Have a look at https://tex.stackexchange.com/a/27615/35864 for a full-link solution that colours both parentheses for \textcite.

Alternatively, I could offer you this answer I once gave at golatex.de: https://golatex.de/biblatex-textcite-link-fehler-bei-einem-autor-t20366.html (at least I think it was me ...)

\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}

enter image description here


Here is a solution that never links (colours) the brackets. For \cite/\parencite we can use Audrey's approach from hyperlink name with biblatex authoryear (biblatex 1.4b). But for \textcite only want to additionally link the name, so we patch the textcite bibmacro with xpatch to link the labelname.

\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}

enter image description here

  • Hi, first thanks a lot! I read tex.stackexchange.com/a/27615/35864 and tried the solution. However, my latex cannot compile symbols like @ -- I am also very confused what they do... I just want to author and year in color and parentheses in black. – James H Jun 24 '18 at 16:46
  • Thanks! Now the codes compiled but nothing changed about the color... – James H Jun 24 '18 at 16:56
  • @JamesH Which code did you compile and what output did you get? The code will colour both parentheses in blue in most situations, I hoped that would be OK for you as well (because I assumed you were only worried about the inconsistency and not about the actual colour of the parentheses.) – moewe Jun 24 '18 at 16:58
  • I tried the codes posted by Marco Daniel. I am actually hoping to change the color of parentheses to black... – James H Jun 24 '18 at 22:04
  • @JamesH Ok, if you really want black parentheses, see the second code block in my edited answer above. – moewe Jun 25 '18 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.