2

As title points, I want to color only author's name and date in my document, in which citations are made by using fullcite command. A MWE could be

\documentclass{article}

\usepackage[backend=biber,style=authoryear,uniquelist=false,maxcitenames=2]{biblatex}

\addbibresource{test.bib}

\begin{document}

\fullcite{test}

\end{document}

A solution could be to define a custom command, like

\newcommand{\colorfullcite}[1]{\textcolor{desired_color}{\fullcite{#1}}}

but such approach colors the whole text.

A workaround is to manually edit the .bib file (in this example the test.bib file):

@article{test,
  title={title_test},
  author={{\color{desired_color} author_test}},
  year={{\color{desired_color}2015}},
  publisher={test_publisher}
}

However, I would prefer a more "automatic" solution

David Purton
  • 25,884
Yorgos
  • 2,694
  • I think this can be done by editing the .bst file.... – Sango Sep 12 '19 at 14:38
  • 1
    @Sango, the OP is using biblatex, which uses a completely different way of formatting citations. – David Purton Sep 12 '19 at 15:12
  • You may want to look at this answer: https://tex.stackexchange.com/questions/73136/make-specific-author-bold-using-biblatex/304968#304968

    There is a general "annotations" feature for doing precisely such things if you are using biber

    – PLK Sep 14 '19 at 14:48

1 Answers1

3

I think this does what you want in a reasonably robust way:

We can declare some new formats to colour the sortname and date:

\DeclareNameWrapperFormat{coloursortname}{\textcolor{red}{#1}}
\DeclareFieldFormat{colourparens}{\textcolor{blue}{\mkbibparens{#1}}}

\DeclareNameWrapperFormat needs at least version 3.12 of biblatex.

If you don't want the parentheses around the date coloured, just swap the order of \textcolour{blue} and \mkbibparens in the colourparens format.

Then we can redefine \fullcite to use these new formats. Normal citations and the bibliography are not affected.

\DeclareCiteCommand{\fullcite}
  {\usebibmacro{prenote}}
  {\usedriver
     {\DeclareNameAlias{sortname}{default}%
      \DeclareNameWrapperAlias{sortname}{coloursortname}%
      \xpatchbibmacro{date+extradate}
        {\printtext[parens]}
        {\printtext[colourparens]}
        {}
        {}}
     {\thefield{entrytype}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

I use xpatch to patch the date+extradate macro, since this macro changes depending on the value of the mergedate option passed to biblatex.

MWE

\documentclass{article}

\usepackage{xpatch}
\usepackage{xcolor}
\usepackage[style=authoryear,uniquelist=false,maxcitenames=2]{biblatex}
\addbibresource{biblatex-examples.bib}

\DeclareNameWrapperFormat{coloursortname}{\textcolor{red}{#1}}
\DeclareFieldFormat{colourparens}{\textcolor{blue}{\mkbibparens{#1}}}

\DeclareCiteCommand{\fullcite}
  {\usebibmacro{prenote}}
  {\usedriver
     {\DeclareNameAlias{sortname}{default}%
      \DeclareNameWrapperAlias{sortname}{coloursortname}%
      \xpatchbibmacro{date+extradate}
        {\printtext[parens]}
        {\printtext[colourparens]}
        {}
        {}}
     {\thefield{entrytype}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\begin{document}
\verb|\autocite|: \autocite{baez/article}

\verb|\fullcite|: \fullcite{baez/article}

\printbibliography
\end{document}

MWE output

David Purton
  • 25,884