0

I am using the code provided in this question regarding coloring citations.

The problem is that I don't know how to make (redefine) the cite command to add parentheses around the year

4

Here is a simple hack, defining a colortextcite command, based on \textcite:

\documentclass[presentation]{beamer}

\usepackage[backend=biber, uniquename=false, maxbibnames=99, maxcitenames=2, citestyle=authoryear, bibstyle=authoryear]{biblatex}

\addbibresource{references.bib}

\DeclareCiteCommand{\cite}
  {\color{red}\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkcolorbibparens]
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\makeatletter
\newrobustcmd{\mkcolorbibparens}[1]{%
  \begingroup
  \color{red}%
  \blx@blxinit
  \blx@setsfcodes
  \bibopenparen#1\bibcloseparen
  \endgroup}
\makeatother

\usepackage{filecontents}
\begin{filecontents}{references.bib}
@Book{bartolini-mair-1990,
  author = {Bartolini, Stefano AND Mair, Peter},
  title = {Identity, Competition and Electoral Availability. The Stabilization of European Electorates 1885-1985},
  publisher = {Cambridge University Press},
  year = 1990,
  address = {Cambridge},
}
\end{filecontents}

\newcommand{\colortextcite}[1]{\textcolor{red}{\textcite{#1}}}

\begin{document}

\begin{frame}
Text \cite{bartolini-mair-1990} text

Text \parencite{bartolini-mair-1990} text

Text \colortextcite{bartolini-mair-1990} text
\end{frame}

\begin{frame}
\printbibliography
\end{frame}

\end{document} 

enter image description here

  • i need to learn how to create my own command/macros...the problem is that i don't know where to start and i don't understand their syntax (e.g. in your hack i don't understand the purpose of [1] and #1 – Yorgos Feb 25 at 12:10
  • [1] is the number of arguments of the macro, and inside the definition of the macro, #1 denotes this argument (which here is replaced by the biblatex key). This being said, you can find lots of tutorials on tug.org. – Bernard Feb 25 at 12:24

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.