1

I have used Audrey's code to cite something of the form: \citet[p.~42]{smth}. This code is excelent if someone wants to have the parentheses affected as well. Now, I ask if it is possible to have the parentheses with another color. For example I would have preferred it to be black. A minimal script for replication and possible change is the following:

\documentclass[hidelinks,12pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{colortbl, tcolorbox}         
\usepackage[sectionbib, sort]{natbib} 
\usepackage{chapterbib}
\usepackage{etoolbox}

\definecolor{darkred}{rgb}{0.5,0,0}
\definecolor{darkgreen}{rgb}{0,0.5,0}
\definecolor{darkblue}{rgb}{0,0,0.5} 
\definecolor{dark-red}{rgb}{0.4,0.15,0.15}

\usepackage[hyperfootnotes = true]{hyperref} 
\hypersetup{colorlinks,                
 linkcolor=red,                               
 filecolor=darkgreen,
 urlcolor=darkred,
 citecolor=blue}

% Audrey's code starts
\makeatletter 

% include postnote and \citet closing bracket in hyperlink
\pretocmd{\NAT@citex}{%
  \let\NAT@hyper@\NAT@hyper@citex
  \def\NAT@postnote{#2}%
  \setcounter{NAT@total@cites}{0}%
  \setcounter{NAT@count@cites}{0}%
  \forcsvlist{\stepcounter{NAT@total@cites}\@gobble}{#3}}{}{}
\newcounter{NAT@total@cites}
\newcounter{NAT@count@cites}
\def\NAT@postnote{}

% include postnote and \citet closing bracket in hyperlink
\def\NAT@hyper@citex#1{%
  \stepcounter{NAT@count@cites}%
  \hyper@natlinkstart{\@citeb\@extra@b@citeb}#1%
  \ifnumequal{\value{NAT@count@cites}}{\value{NAT@total@cites}}
    {\ifNAT@swa\else\if*\NAT@postnote*\else%
     \NAT@cmt\NAT@postnote\global\def\NAT@postnote{}\fi\fi}{}%
  \ifNAT@swa\else\if\relax\NAT@date\relax
  \else\NAT@@close\global\let\NAT@nm\@empty\fi\fi% avoid compact citations
  \hyper@natlinkend}
\renewcommand\hyper@natlinkbreak[2]{#1}

% avoid extraneous postnotes, closing brackets
\patchcmd{\NAT@citex}
  {\ifNAT@swa\else\if*#2*\else\NAT@cmt#2\fi
   \if\relax\NAT@date\relax\else\NAT@@close\fi\fi}{}{}{}
\patchcmd{\NAT@citex}
  {\if\relax\NAT@date\relax\NAT@def@citea\else\NAT@def@citea@close\fi}
  {\if\relax\NAT@date\relax\NAT@def@citea\else\NAT@def@citea@space\fi}{}{}

\makeatother
% End of Audrey's code

\bibpunct{(}{)}{;}{a}{,}{,~}   

\title{My title}
\author{My name}
Pantelis Kazakis
  • 1,346
  • 1
  • 12
  • 29

0 Answers0