2

I am using following commands and macros to create a new citation style citation \aytcite which give out citations as "Author et al (2018)". So can we modify it and make it do "Author et al (2018)[2]" with the same \aytcite command?

\usepackage[backend=biber,style=ieee,sorting=none,labeldateparts,maxbibnames=99,maxcitenames=2,mincitenames=1]{biblatex} 
\ExecuteBibliographyOptions{
    url=false
}

\urlstyle{same}
\addbibresource{Biblio.bib}


\providebool{cbx:parens}
\newbibmacro*{citeyear}{%
    \iffieldundef{shorthand}
    {\iffieldundef{labelyear}
        {\usebibmacro{cite:label}}
        {\usebibmacro{cite:labeldate+extradate}}}
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{aytcite}{%
    \ifnameundef{labelname}
    {\iffieldundef{shorthand}
        {\usebibmacro{cite:label}%
            \setunit{%
                \global\booltrue{cbx:parens}%
                \printdelim{nonameyeardelim}\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
            \usebibmacro{cite:labeldate+extradate}}
        {\usebibmacro{cite:shorthand}}}
    {\printnames{labelname}%
        \setunit{%
            \global\booltrue{cbx:parens}%
            \printdelim{nameyeardelim}\bibopenparen}%
        \ifnumequal{\value{citecount}}{1}
        {\usebibmacro{prenote}}
        {}%
        \usebibmacro{citeyear}}}

\newbibmacro*{cite:shorthand}{%
    \printtext[bibhyperref]{\printfield{shorthand}}}

\newbibmacro*{cite:label}{%
    \iffieldundef{label}
    {\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}
    {\printtext[bibhyperref]{\printfield{label}}}}

\newbibmacro*{cite:labeldate+extradate}{%
    \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{\printlabeldateextra}}}

\newbibmacro*{aytcite:postnote}{%
    \iffieldundef{postnote}
    {\ifbool{cbx:parens}
        {\bibcloseparen}
        {}}
    {\ifbool{cbx:parens}
        {\setunit{\postnotedelim}}
        {\setunit{\extpostnotedelim\bibopenparen}}%
        \printfield{postnote}\bibcloseparen}}

\DeclareCiteCommand{\aytcite}
{\boolfalse{cbx:parens}}
{\usebibmacro{citeindex}%
    \iffirstcitekey
    {\setcounter{textcitetotal}{1}}
    {\stepcounter{textcitetotal}%
        \textcitedelim}%
    \usebibmacro{aytcite}}
{\ifbool{cbx:parens}
    {\bibcloseparen\global\boolfalse{cbx:parens}}
    {}}
{\usebibmacro{aytcite:postnote}}
7
2

My answer to Biblatex style=numeric: would like \textcite) style "Author et al., year [#bibliography]" only needs a few little tweaks to work with style=ieee

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=ieee, labeldateparts, backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}

\makeatletter
\newbibmacro*{simple:cite}{%
  \printtext[bibhyperref]{%
    \printfield{labelprefix}%
    \printfield{labelnumber}%
    \ifbool{bbx:subentry}
      {\printfield{entrysetcount}}
      {}}}

\newbibmacro*{textcite:init}{%
  \ifnumless{\value{multicitecount}}{2}
    {\global\boolfalse{cbx:parens}}
    {}%
  \global\undef\cbx@lasthash
  \global\undef\cbx@lastyear}

\renewbibmacro*{textcite}{%
   \ifboolexpr{test {\iffieldequals{namehash}{\cbx@lasthash}}
               and test {\iffieldequals{labelyear}{\cbx@lastyear}}}
    {\setunit{\multicitedelim}}
    {\ifnameundef{labelname}
       {\printfield[citetitle]{labeltitle}}
       {\printnames{labelname}}%
     \setunit*{\printdelim{nameyeardelim}}%
     \printlabeldate
     \setunit{\printdelim{namelabeldelim}}%
     \printtext{\bibopenbracket}\global\booltrue{cbx:parens}%
     \stepcounter{textcitecount}}%
  \savefield{namehash}{\cbx@lasthash}%
  \savefield{labelyear}{\cbx@lastyear}%
  \ifnumequal{\value{citecount}}{1}
    {\usebibmacro{prenote}}
    {}%
  \usebibmacro{simple:cite}%
  \setunit{%
    \ifbool{cbx:parens}
      {\bibclosebracket\global\boolfalse{cbx:parens}}
      {}%
    \textcitedelim}}

\DeclareCiteCommand{\textcite}[\cbx@textcite@init\cbx@textcite]
  {\gdef\cbx@savedkeys{}%
   \citetrackerfalse%
   \pagetrackerfalse%
   \DeferNextCitekeyHook%
   \usebibmacro{textcite:init}}
  {\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}
     {\protected@xappto\cbx@savedcites{()(\thefield{multipostnote})}%
      \global\clearfield{multipostnote}}
     {}%
   \xappto\cbx@savedkeys{\thefield{entrykey},}%
   \ifboolexpr{test {\iffieldequals{namehash}{\cbx@lasthash}}
               and test {\iffieldequals{labelyear}{\cbx@lastyear}}}
     {}
     {\stepcounter{textcitetotal}}%
   \savefield{namehash}{\cbx@lasthash}%
   \savefield{labelyear}{\cbx@lastyear}}
  {}
  {\protected@xappto\cbx@savedcites{%
     [\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}
\makeatother

\begin{document}
\textcite{sigfridsson}

\textcite{knuth:ct:a,knuth:ct:b}

\textcite{knuth:ct:b,knuth:ct:c}

\printbibliography
\end{document}

enter image description here


Alternatively, an extension of Obtain author name and year with a single citation command with ieee style in Biblatex could look like

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=ieee, labeldateparts, sorting=nyvt, maxbibnames=99, maxcitenames=2, mincitenames=1]{biblatex}

\addbibresource{biblatex-examples.bib}

\DeclareFieldFormat{labeldate}{\mkbibparens{#1}}
\newbibmacro*{citenum}{%
  \printtext[labelnumberwidth]{%
    \printfield{labelprefix}%
    \printfield{labelnumber}%
    \ifbool{bbx:subentry}
      {\printfield{entrysetcount}}
      {}}}

\newbibmacro*{citeyear}{%
  \iffieldundef{shorthand}
    {\iffieldundef{labelyear}
       {\usebibmacro{cite:label}}
       {\usebibmacro{cite:labeldate+extradate}}}
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{aytcite}{%
  \ifnameundef{labelname}
    {\iffieldundef{shorthand}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}%
        \usebibmacro{cite:labeldate+extradate}}
       {\usebibmacro{cite:shorthand}}}
    {\printnames{labelname}%
     \setunit{\printdelim{nameyeardelim}}%
     \usebibmacro{citeyear}}%
  \setunit{\addspace}%
  \usebibmacro{citenum}}

\newbibmacro*{cite:shorthand}{%
  \printtext[bibhyperref]{\printfield{shorthand}}}

\newbibmacro*{cite:label}{%
  \iffieldundef{label}
    {\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}
    {\printtext[bibhyperref]{\printfield{label}}}}

\newbibmacro*{cite:labeldate+extradate}{%
  \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{\printlabeldateextra}}}

\DeclareCiteCommand{\aytcite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{aytcite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\begin{document}
\cite{sigfridsson} or \aytcite{sigfridsson}
\printbibliography
\end{document}

enter image description here

1

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.