5

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}}
3
  • 1
    You can just use \parencite instead of \cite. – Andrew Swann Aug 26 '13 at 19:53
  • That does not yield what I want. I want Author, year in some places and Author (year) in others. Sorry its not a matter of whole parenthesis, rather, a comma as separator, not parenthesis. – Rabeya Khatoon Aug 26 '13 at 20:14
  • You should update your question and clarify what you want. – lockstep Aug 26 '13 at 21:43
6

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.

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.