1

I'm using biblatex with the authoryear-comp style. By default, the \cite command prints citations with no parentheses. I would like to keep this behavior while putting any postnote in parenthes following the citation, like this: See Author 2020 (postnote). For other citation commands I still want the regular punctuation (a comma, by default), e.g. \textcite should produce Author (2020, postnote) and \parencite should produce (Author 2020, postnote).

I have tried to achieve this by redefining \cite with \DeclareCiteCommand so that it doesn't call the postnote bibmacro (which inserts postnotedelim) but instead calls a new macro that wraps the argument in parenthese. But when I do this I get an undesired semicolon in front of my postnote. I can make this go away with \nopunct but I still get an undesired space, which does not go away even if I add \unspace. I don't understand where all this punctuation is coming from since I am not calling postnotedelim.

MWE:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
    @article{myarticle,
        author = {Doe, John},
        year = {2020},
        title = {The Title}}    
\end{filecontents*}

\usepackage[style=authoryear-comp]{biblatex}

\addbibresource{\jobname.bib}

\DeclareFieldFormat{plainpostnote}{#1}

\newbibmacro{parenpostnote}{%
  \iffieldundef{postnote}
    {}
    {\addspace\mkbibparens{%\nopunct\unspace
     \printfield[plainpostnote]{postnote}}}}

\DeclareCiteCommand{\cite} %
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}
  {\usebibmacro{parenpostnote}}

\begin{document}
    This is plain \cite[note]{myarticle} and this is text: \textcite[note]{myarticle} and this is parenthetical \parencite[note]{myarticle}.
\end{document}

Output:

enter image description here

Desired output: This is plain Doe 2020 (note) and this is text: Doe (2020, note) and this is parenthetical (Doe 2020, note).

1 Answer 1

1

Here is quick way to do that that uses that postnotedelim is context sensitive in new biblatex versions and introduces a context sensitive wrapper for the postnote field format as well.

\documentclass{article}

\usepackage[style=authoryear-comp]{biblatex}

\DeclareDelimFormat[cite]{postnotedelim}{\addspace}

% default postnote wrapper does nothing
\newcommand*{\postnotewrapper}[1]{#1}
% \cite postnote wrapper wraps argument in round brackets
\newcommand*{\postnotewrappercite}{\mkbibparens}

\makeatletter
% apply context-sensitive wrapper
\DeclareFieldFormat{postnote}{%
  \ifcsundef{postnotewrapper\blx@delimcontext}
    {\postnotewrapper}
    {\csuse{postnotewrapper\blx@delimcontext}}%
  {\mkpageprefix[pagination][\mknormrange]{#1}}%
}
\makeatother

\addbibresource{biblatex-examples.bib}

\begin{document}
  This is plain \cite[note]{sigfridsson}
  and this is text \textcite[note]{sigfridsson}
  and this is parenthetical \parencite[note]{sigfridsson}.
\end{document}

This is plain Sigfridsson and Ryde 1998 (note) and this is text Sigfridsson and Ryde (1998, note) and this is parenthetical (Sigfridsson and Ryde 1998, note).


The undesirable punctuation in the code from the question is caused by not using the biblatex punctuation tracker and by applying a formatting macro like \mkbibparens directly in a bibmacro. If you just write \addspace\mkbibparens{...} in a bibmacro, then the punctuation will not go via the punctuation tracker, it is printed directly. Since authoryear-comp heavily relies on the punctuation tracker you get weird results like this, because the punctuation tracker is not cleared and its contents are then printed inside the parentheses when you call \printfield.

1
  • Thank you - excellent solution and informative answer.
    – Cian
    Jan 9, 2021 at 4:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .