[Tex/LaTex] two styles in biblatex with textcite, author (year) and (author, year)

biblatex

I am using biblatex with the following commands, which produce Author (year) type citation using \textcite{} command. However, I have some places where I need (Author, year) type citation. How can I do this? Thanks.

\documentclass{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear,maxcitenames=2]{biblatex}

%This part is for citation style textcite
\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \ifboolexpr{ ( not test {\iffieldundef{prenote}} and
                  test {\ifnumequal{\value{citecount}}{1}} ) or
                ( not test {\iffieldundef{postnote}} and
                  test {\ifnumequal{\value{citecount}}{\value{citetotal}}} ) }
     {\usebibmacro{textcite}}
     {\printtext[bibhyperref]{% Apply citation link to bibmacro output
        \DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
        \usebibmacro{textcite}%
        \ifbool{cbx:parens}{\bibcloseparen\global\boolfalse{cbx:parens}}{}}}}
  {\ifbool{cbx:parens}{\bibcloseparen\global\boolfalse{cbx:parens}}{}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

Best Answer

Using the authoryear citation style, \parencite uses the macro \nameyeardelim to store what should go between the name and the year in the citation.

In authoryear.cbx, the cite command \parencite is defined in the following way:

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

And in biblatex.def, we find

\newcommand*{\nameyeardelim}{\addspace}

You could define your own cite command to put a comma between the author and the year and put everything in parantheses, e.g. by redefining \nameyeardelim:

\DeclareCiteCommand{\myparencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\def\nameyeardelim{\addcomma\addspace}%
   \usebibmacro{citeindex}%
   \usebibmacro{cite}%
   \def\nameyeardelim{\addspace}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

By changing \nameyeardelim back to simply \addspace after printing this citation, we avoid interference with other citations.

Using the filecontents package to produce a full example, this yields

\documentclass{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear]{biblatex}
\addbibresource{\jobname.bib}

%This part is for citation style textcite
\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \ifboolexpr{ ( not test {\iffieldundef{prenote}} and
                  test {\ifnumequal{\value{citecount}}{1}} ) or
                ( not test {\iffieldundef{postnote}} and
                  test {\ifnumequal{\value{citecount}}{\value{citetotal}}} ) }
     {\usebibmacro{textcite}}
     {\printtext[bibhyperref]{% Apply citation link to bibmacro output
        \DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
        \usebibmacro{textcite}%
        \ifbool{cbx:parens}{\bibcloseparen\global\boolfalse{cbx:parens}}{}}}}
  {\ifbool{cbx:parens}{\bibcloseparen\global\boolfalse{cbx:parens}}{}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

\DeclareCiteCommand{\myparencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\def\nameyeardelim{\addcomma\addspace}%
   \usebibmacro{citeindex}%
   \usebibmacro{cite}%
   \def\nameyeardelim{\addspace}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}

@article{test,
  title={something},
  author={someone},
  journal={some journal},
  year={2013}
}

\end{filecontents}

\begin{document}
\textcite{test}
\parencite{test}
\myparencite{test}
\textcite{test}
\end{document}

And this results in

compiled pdf

so \myparencite{test} puts a comma between the author and the year.