Biblatex-ext:ext-authoryear-comp 与 \textcite 简写简介冲突?

Biblatex-ext:ext-authoryear-comp 与 \textcite 简写简介冲突?

我尝试首先引入简写 \cite、\parencite 等和 \textcite,但之后只需将其用于所有后续引用。对于 \parencite 等,我遵循 moewe 的解决方案bibtex 中引用的自定义缩写 对于 \textcite,我遵循 gusbrs 的回答Biblatex:如何使用 /textcite 和速记获取括号中的年份在第一个 \textcite 中使用 intro 的简写。我还使用了 moewe 的 ext-authoryear-comp 样式。当我使用 \textcite 处理多个 bib 条目时,这会导致错误:

! Package biblatex Error: Unbalanced parentheses or brackets.

梅威瑟:

\documentclass[american]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage[backend=biber,style=ext-authoryear-comp,citetracker=true]{biblatex}
\DefineBibliographyStrings{english}{citedas = {hereafter}}

\begin{filecontents*}[overwrite]{\jobname.bib}
@article{jd14,
  author  = {Doe, J.},
  title   = {Some Title},
  journal = {Some Journal},
  year    = {2014},
  shorthand = {JD14},
}
@book{jd13,
  author  = {Smith, J.},
  title   = {Pro Contractiōnibus},
  year    = {2013},
  shorthand = {JD13},
}
@article{jd12,
  author  = {Bar, F.},
  title   = {No Shorthand},
  journal = {Yet Another Journal},
  year    = {2012},
}
@book{jd11,
author = {Nominatus, N.},
title={Adversus Contractiōnēs},
year={2011},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

% shorthandintro with first \cite, \parencite, etc, shorthand only after
\newbibmacro*{longcite}{%
  \ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
    {\usebibmacro{cite:label}%
     \setunit{\addspace}}
    {\printnames{labelname}%
     \setunit{\nameyeardelim}}%
  \usebibmacro{cite:labeldate+extradate}}

\renewbibmacro*{cite}{%
  \ifciteseen
    {\iffieldundef{shorthand}
      {\usebibmacro{longcite}}
      {\usebibmacro{cite:shorthand}}}
    {\usebibmacro{longcite}
     \usebibmacro{shorthandintro}}}
     
% shorthandintro with first \textcite, etc, shorthand only after
\renewbibmacro*{textcite}{%
    \ifnameundef{labelname}
    {\iffieldundef{shorthand}
        {\usebibmacro{cite:label}%
            \setunit{%
                \global\booltrue{cbx:parens}%
                \printdelim{nonameyeardelim}\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
            \usebibmacro{cite:labelyear+extrayear}}
        {\usebibmacro{cite:shorthand}}}
    {\iffieldundef{shorthand}
        {\printnames{labelname}%
            \setunit{%
                \global\booltrue{cbx:parens}%
                \printdelim{nameyeardelim}\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
            \usebibmacro{citeyear}}
        {\ifciteseen
            {\usebibmacro{cite:shorthand}}
            {\printnames{labelname}%
                \setunit{%
                    \global\booltrue{cbx:parens}%
                    \printdelim{nameyeardelim}\bibopenparen}%
                \ifnumequal{\value{citecount}}{1}
                {\usebibmacro{prenote}}
                {}%
                \iffieldundef{labelyear}
                {\usebibmacro{cite:label}
                    \setunit{\addcomma\addspace}%
                    \iffieldundef{shorthandintro}
                    {\printtext{\bibstring{citedas}}}
                    {\printtext{\printfield{shorthandintro}}}
                    \usebibmacro{cite:shorthand}}
                {\usebibmacro{cite:labelyear+extrayear}
                    \setunit{\addcomma\addspace}%
                    \iffieldundef{shorthandintro}
                    {\printtext{\bibstring{citedas}}}
                    {\printtext{\printfield{shorthandintro}}}
                    \usebibmacro{cite:shorthand}}}}}}

\begin{document}
\textcite{jd14} argued in favor of shorthands on the basis of \citetitle{jd13} \parencite{jd13}.

\textcite{jd11} and \textcite{jd12} %but alas \textcite{jd11,jd12} doesn't work
forcefully attacked \cite[17-18]{jd14} and \cite[19-20]{jd13}.

\printbibliography
\end{document}

这是我想要实现的输出:

期望结果

在 MWE 中我们可以看到,如果\textcite{jd11,jd12}使用 而不是\textcite{jd11} and \textcite{jd12},则会出现上面引用的错误。

gusbrs 确实建议查看 moewe 的答案,但在 moewe 编辑之前,该解决方案不会在第一次引用后打印速记。

在 moewe 修改该解决方案后,如果将上面的 gusbrs 代码替换为

\newbibmacro*{shorthandintro:noparen}{%
  \iffieldundef{shorthandintro}
    {\iffieldundef{shorthand}
       {}
       {\setunit{\addcomma\space}%
        \bibstring{citedas}\space
        \printfield{shorthand}}}
    {\setunit{\addcomma\space}%
     \printfield{shorthandintro}}}

\newbibmacro*{cite:normal}{%
  \ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
    {\usebibmacro{cite:label}%
     \setunit{\printdelim{nonameyeardelim}}}
    {\printnames{labelname}%
     \setunit{\printdelim{nameyeardelim}}}%
  \printtext{\bibopenparen}%
  \usebibmacro{cite:labeldate+extradate}}

\renewbibmacro*{cite}{%
  \ifciteseen
    {\iffieldundef{shorthand}
       {\usebibmacro{cite:normal}%
        \printtext{\bibcloseparen}}
       {\usebibmacro{cite:shorthand}}}
    {\usebibmacro{cite:normal}%
     \usebibmacro{shorthandintro:noparen}%
     \printtext{\bibcloseparen}}}

\textcite{jd11,jd12}按预期工作,但初始\textcite{jd14}不再产生速记介绍。

答案1

答案Biblatex:如何使用 /textcite 和速记获取括号中的年份authoryear是针对该问题中使用的风格编写的。authoryear-comp比 复杂得多,authoryearext-authoryear-comp在 之上添加了更多层authoryear-comp。因此,您真的不能指望这里的代码在不进行修改的情况下就能正常工作。

这里尝试使用 来实现接近所需输出的功能ext-authoryear-comp。大部分代码已经存在,但我们需要稍微改变一下逻辑才能达到现在的效果。

\documentclass[british,a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage[backend=biber, style=ext-authoryear-comp, citetracker=true]{biblatex}
\DefineBibliographyStrings{english}{citedas = {hereafter}}

\makeatletter
\newbibmacro*{shorthandintro:noparen}{%
  \iffieldundef{shorthandintro}
    {\iffieldundef{shorthand}
       {}
       {\setunit{\addcomma\space}%
        \bibstring{citedas}\space
        \printfield{shorthand}}}
    {\setunit{\addcomma\space}%
     \printfield{shorthandintro}}}

\newcommand*{\ifshorthandonlycite}{%
  \iffieldundef{shorthand}
    {\@secondoftwo}
    {\ifciteseen}}

\renewbibmacro*{cite}{%
  \ifshorthandonlycite
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}
    {\ifboolexpr{test {\ifnameundef{labelname}}
                 or test {\iffieldundef{labelyear}}}
       {\usebibmacro{cite:label}%
        \setunit{%
          \global\booltrue{cbx:parens}%
          \printdelim{nonameyeardelim}%
          \csuse{extblx@citedelim@\blx@delimcontext @inner@open}}%
        \usebibmacro{cite:labeldate+extradate}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\ifboolexpr{
             test {\iffieldequals{labelyear}{\cbx@lastyear}}
             and (   test {\ifnumequal{\value{multicitecount}}{0}}
                  or test {\iffieldundef{postnote}})
             and test {\iffieldundef{shorthand}}}
             {\setunit{\printdelim{extradateonlycompcitedelim}}%
              \usebibmacro{cite:extradate}}
             {\setunit{\compcitedelim}%
              \usebibmacro{cite:labeldate+extradate}%
              \savefield{labelyear}{\cbx@lastyear}}}
          {\printnames{labelname}%
           \setunit{%
             \global\booltrue{cbx:parens}%
             \printdelim{nameyeardelim}%
             \csuse{extblx@citedelim@\blx@delimcontext @inner@open}}%
           \usebibmacro{cite:labeldate+extradate}%
           \savefield{namehash}{\cbx@lasthash}%
           \savefield{labelyear}{\cbx@lastyear}}%
        \usebibmacro{shorthandintro:noparen}%
        \iffieldundef{shorthand}
          {}
          {\global\undef\cbx@lastyear}}}%
  \setunit{%
    \ifbool{cbx:parens}
      {\csuse{extblx@citedelim@\blx@delimcontext @inner@close}%
       \global\boolfalse{cbx:parens}}
      {}%
    \multicitedelim}}

\renewbibmacro*{textcite}{%
  \ifshorthandonlycite
    {\ifnumequal{\value{citecount}}{1}
       {\usebibmacro{prenote}}
       {}%
     \usebibmacro{cite:shorthand}%
     \global\undef\cbx@lastyear}
    {\iffieldequals{namehash}{\cbx@lasthash}
       {\ifboolexpr{test {\iffieldequals{labelyear}{\cbx@lastyear}}
                    and (test {\ifnumequal{\value{multicitecount}}{0}}
                         or test {\iffieldundef{postnote}})
                    and test {\iffieldundef{shorthand}}}
          {\setunit{\printdelim{extradateonlycompcitedelim}}%
           \usebibmacro{cite:extradate}}
          {\setunit{\compcitedelim}%
           \usebibmacro{cite:labeldate+extradate}%
           \usebibmacro{shorthandintro:noparen}%
           \iffieldundef{shorthand}
             {\savefield{labelyear}{\cbx@lastyear}}
             {\global\undef\cbx@lastyear}}}
       {\ifnameundef{labelname}
          {\usebibmacro{cite:label}%
           \setunit{%
             \global\booltrue{cbx:parens}%
             \printdelim{nonameyeardelim}%
             \csuse{extblx@citedelim@\blx@delimcontext @inner@open}}%
           \ifnumequal{\value{citecount}}{1}
             {\usebibmacro{prenote}}
             {}%
           \usebibmacro{cite:labeldate+extradate}%
           \usebibmacro{shorthandintro:noparen}}
          {\printnames{labelname}%
           \setunit{%
             \global\booltrue{cbx:parens}%
             \printdelim{nameyeardelim}%
             \csuse{extblx@citedelim@\blx@delimcontext @inner@open}}%
           \ifnumequal{\value{citecount}}{1}
             {\usebibmacro{prenote}}
             {}%
           \iffieldundef{labelyear}
             {\usebibmacro{cite:label}}
             {\usebibmacro{cite:labeldate+extradate}}%
           \usebibmacro{shorthandintro:noparen}%
           \iffieldundef{shorthand}
             {\savefield{labelyear}{\cbx@lastyear}}
             {\global\undef\cbx@lastyear}}%
        \stepcounter{textcitecount}%
        \savefield{namehash}{\cbx@lasthash}}}%
     \setunit{%
       \ifbool{cbx:parens}
         {\csuse{extblx@citedelim@\blx@delimcontext @inner@close}%
          \global\boolfalse{cbx:parens}}
         {}%
       \textcitedelim}}

\renewbibmacro*{textcite:postnote}{%
  \iffieldundef{postnote}
    {}
    {\ifbool{cbx:parens}
       {\setunit{\printdelim{postnotedelim}}}
       {\setunit{%
          \global\booltrue{cbx:parens}%
          \printdelim{nameyeardelim}%
          \csuse{extblx@citedelim@\blx@delimcontext @inner@open}}}%
     \printfield{postnote}}%
  \ifnumequal{\value{multicitecount}}{\value{multicitetotal}}
    {\setunit{}%
     \printtext{%
       \ifbool{cbx:parens}
         {\csuse{extblx@citedelim@\blx@delimcontext @inner@close}%
          \global\boolfalse{cbx:parens}}
         {}}}
    {\setunit{%
       \ifbool{cbx:parens}
         {\csuse{extblx@citedelim@\blx@delimcontext @inner@close}%
          \global\boolfalse{cbx:parens}}
         {}%
       \textcitedelim}}}

\DeclareCiteCommand{\textcite}[\cbx@textcite@init\cbx@textcite]
  {\gdef\cbx@savedkeys{}%
   \citetrackerfalse%
   \pagetrackerfalse%
   \DeferNextCitekeyHook%
   \usebibmacro{cite:init}}
  {\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}
     {\protected@xappto\cbx@savedcites{()(\thefield{multipostnote})}%
      \global\clearfield{multipostnote}}
     {}%
   \xappto\cbx@savedkeys{\thefield{entrykey},}%
   \iffieldundef{shorthand}
     {}
     {\booltrue{citetracker}%
      \ifciteseen
        {\gundef\cbx@lasthash}
        {}%
      \boolfalse{citetracker}}%
   \iffieldequals{namehash}{\cbx@lasthash}
     {}
     {\stepcounter{textcitetotal}%
      \savefield{namehash}{\cbx@lasthash}}}
  {}
  {\protected@xappto\cbx@savedcites{%
     [\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}
\makeatother

\begin{filecontents*}{\jobname.bib}
@article{jd14,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {Some Title},
  journal = {Some Journal},
  year    = {2014},
  shorthand = {JD14},
}
@article{jd15,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {Some Title},
  journal = {Some Journal},
  year    = {2015},
  shorthand = {JD15},
}
@article{jd13,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {No shorthand here},
  journal = {Some Other Journal},
  year    = {2013},
}
@article{b12,
  author  = {Bar, F.},
  title   = {Also No shorthand},
  journal = {Yet Another Journal},
  year    = {2012},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
  1 \textcite{jd14} again \textcite{jd14}.

  2 \textcite[see][45]{jd15} again \textcite[see][45]{jd15}.

  3 \textcite{jd14,jd15} again \textcite{jd14,jd15}.

  4 \textcite{jd13,jd15} again \textcite{jd13,jd15}.

  5 \textcite{b12,jd14} again \textcite{b12,jd14}.

  6 Just for comparison \textcite{jd13}. \textcite{b12,jd13} works

  7 \textcite[34-36]{jd13} again \textcite[see][34-36]{jd13}

\citereset

  1 \parencite{jd14} again \parencite{jd14}.

  2 \parencite[see][45]{jd15} again \parencite[see][45]{jd15}.

  3 \parencite{jd14,jd15} again \parencite{jd14,jd15}.

  4 \parencite{jd13,jd15} again \parencite{jd13,jd15}.

  5 \parencite{b12,jd14} again \parencite{b12,jd14}.

  6 Just for comparison \parencite{jd13}. \parencite{b12,jd13} works

  7 \parencite[34-36]{jd13} again \parencite[see][34-36]{jd13}

  \printbibliography
\end{document}

Doe,Smith 和 Bar(2014,以下简称 JD14)再次为 JD14。

相关内容