0

I am writing my PhD dissertation, and I am trying to cite a reference as part of the sentence in such a way that the last name of author is followed by the year in parenthesis:

for single author

Author (year)

or for two authors

Author1 and Author2 (year)

or for more than two authors

Author et al. (year)

I tried to use \citet and it does not work with even using natbib. I get the following error

Package etoolbox Error: Boolean '\ifcbx:np' undefined.

I am using the package biblatex with natbib as follows:

\usepackage[
  style=authoryear,
  natbib=true,
  backend=biber,
  dashed=false,
  isbn = false,
  doi = false,
  url = false,
  language=auto,
  sorting=nyt,  
  maxbibnames=99,
  maxcitenames=2,
  uniquelist=false,
  uniquename=false]{biblatex}  

The following are the packages I am using

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{booktabs}
\usepackage{bm}
\usepackage{float}
\usepackage{subfig}
\usepackage{setspace}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[hyperfootnotes=false,english,colorlinks]{hyperref}
\usepackage{url}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{array}
\usepackage[normalem]{ulem}

An example I have now

 For the former, \cite{basu2017} invoked the notion of a metric..

Output:

Basu et al., 2017

Desired Output:

Basu et al. (2017)

I figured the error was coming from using this macro to link both author and year

% long syntax to link both author & year in in-text citation
\makeatletter
\newbibmacro{cite:plabelyear+extradate}{%
  \iffieldundef{labelyear}{}
    {\clearfield{labelmonth}% don't want months in citations
     \clearfield{labelday}% don't want days in citations
     \clearfield{labelendmonth}% don't want months in citations
     \clearfield{labelendday}% don't want days in citations
     \iffieldsequal{labelyear}{labelendyear}% Don't want no-op year ranges
       {\clearfield{labelendyear}}
       {}%
     \iffieldundef{origyear}
       {}
       {\printorigdate%
        \setunit*{\addslash}}%
     \iffieldundef{related}
       {}
       {\iffieldequalstr{relatedtype}{reprintfrom}
         {\entrydata*{\thefield{related}}{\printlabeldateextra}%
          \setunit*{\addslash}}
         {}}%
     \printlabeldateextra}}

\renewbibmacro*{cite}{%
  \iffieldequals{fullhash}{\cbx@lasthash}
   {\setunit{\compcitedelim}%
    \printtext[bibhyperref]{%
      \usebibmacro{cite:plabelyear+extradate}}}%
   {\printtext[bibhyperref]{%
      \ifnameundef{labelname}
       {\usebibmacro{cite:noname}%
         \setunit{\printdelim{nameyeardelim}}%
         \usebibmacro{cite:plabelyear+extradate}%
         \savefield{fullhash}{\cbx@lasthash}}
       {\ifnameundef{shortauthor}
         {\printnames{labelname}}%
         {\cbx@apa@ifnamesaved
           {\printnames{shortauthor}}
           {\ifnameundef{groupauthor}
             {\printnames[labelname]{author}}
             {\printnames[labelname]{groupauthor}}%
            \addspace\printnames[sabrackets]{shortauthor}}}%
         \setunit{\printdelim{nameyeardelim}}%
        \usebibmacro{cite:plabelyear+extradate}%
        \savefield{fullhash}{\cbx@lasthash}}}}%
   \setunit{\multicitedelim}}

\renewbibmacro*{textcite}{%
  \iffieldequals{fullhash}{\cbx@lasthash}
    {\setunit{\compcitedelim}%
     \printtext[bibhyperref]{%
       \usebibmacro{cite:plabelyear+extradate}}}
    {%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
      \setunit{\compcitedelim}%
      \ifnameundef{labelname}
       {\iffieldundef{shorthand}%
         {\printtext[bibhyperref]{%
            \usebibmacro{cite:noname}}%
          \setunit{\ifbool{cbx:np}%
                   {\printdelim{nameyeardelim}}%
                   {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
          \printtext[bibhyperref]{%
            \usebibmacro{cite:plabelyear+extradate}}}
         {\printtext[bibhyperref]{%
            \usebibmacro{cite:shorthand}}}}
       {\printtext[bibhyperref]{%
          \ifnameundef{shortauthor}%
           {\printnames{labelname}}
           {\cbx@apa@ifnamesaved
             {\printnames{shortauthor}}
             {\ifnameundef{groupauthor}
               {\printnames[labelname]{author}}
               {\printnames[labelname]{groupauthor}}}}}%
        \setunit{\ifbool{cbx:np}
                  {\printdelim{nameyeardelim}}
                  {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
        \printtext[bibhyperref]{%
          \ifnameundef{shortauthor}
           {}
           {\cbx@apa@ifnamesaved
             {}
             {\printnames{shortauthor}\setunit{\printdelim{nameyeardelim}}}}%
          \usebibmacro{cite:plabelyear+extradate}}%
        \savefield{fullhash}{\cbx@lasthash}}}}
\makeatother

How should I modify the above to make \citet work? (\citep works)

5
  • \citep works though
    – Shahmeer
    Commented Dec 24, 2022 at 22:36
  • 4
    don't show only snippets, always show a small but complete example so that we can test your issue. Commented Dec 24, 2022 at 22:49
  • 1
    If I combine the code you have shown so far into a simple example document I cannot reproduce the error: gist.github.com/moewew/2c6954ec63acd1dc3db8147f8789bc51. This suggests that something else is going on at your end. Presumably you have some additional code that causes the issue. Please post a compilable example document that reproduces the issue (see tex.meta.stackexchange.com/q/228/35864 and linked posts).
    – moewe
    Commented Dec 25, 2022 at 5:51
  • I added more info @moewe
    – Shahmeer
    Commented Dec 26, 2022 at 0:34
  • Thank you. I figured it out using another macro to link both author and year
    – Shahmeer
    Commented Dec 26, 2022 at 8:19

2 Answers 2

1

The additional code you have in your preamble to link more of the citation output is not compatible with the style you selected. (The code you have looks like it would work for - a possibly outdated version of - biblatex-apa.)

I would just accept that linked areas are a little smaller than with natbib and get on with it. But if you absolutely must have bigger link areas, then I would suggest you follow hyperlink name with biblatex authoryear (biblatex 1.4b) for style=authoryear,.

0

I figured that to link both author and year in citation when using this biblatex style with natbib=true without error coming for even all other natbib citation commands including \citet, we can use the following bib macro I used from @lockstep hyperlink name with biblatex authoryear

\DeclareCiteCommand{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{citeyear}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citep}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citep}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{citeyear}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcite}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
  \printtext[bibhyperref]{ \usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citet}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{textcite}}}
  {\ifbool{cbx:parens}
     {\bibcloseparen\global\boolfalse{cbx:parens}}
     {}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

You must log in to answer this question.

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