使用一个命令 BibLatex 引用作者(年份)

使用一个命令 BibLatex 引用作者(年份)

我正在使用以下命令和宏来创建新的引用样式引用,\aytcite该引用将引用显示为“Author et al (2018)”。那么我们可以修改它并使用相同的命令使其执行“Author et al (2018)[2]”\aytcite吗?

\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}}

答案1

我的回答Biblatex style=numeric: 类似于 \textcite) 样式“作者等,年份 [#bibliography]”只需进行一些小调整即可使用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}

在此处输入图片描述


或者,扩展使用 Biblatex 中采用 ieee 样式的单个引用命令获取作者姓名和年份看起来像

\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}

在此处输入图片描述

相关内容