I'm trying to have shorthands introduced at first \cite, \parencite, etc., and \textcite, but then simply use for all further citations. For \parencite etc I follow moewe's solution from Custom abbreviation for citation in bibtex . For \textcite I follow gusbrs's answer Biblatex: How to get year in parenthesis with /textcite & shorthand to have shorthand with intro in first \textcite. I am also using moewe's ext-authoryear-comp style. This results in an error when I use \textcite with multiple bib entries:
! Package biblatex Error: Unbalanced parentheses or brackets.
MWE:
\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}
Here's the output I would like to achieve:
One can see in the MWE, that if \textcite{jd11,jd12} is used instead of \textcite{jd11} and \textcite{jd12}, then the error quoted above results.
gusbrs did suggest looking at moewe's answer, but prior to moewe's editing, that solution doesn't print shorthands after the first citation.
After moewe's revision of that solution, if gusbrs's code above is replaced with
\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} works as desired, but the initial \textcite{jd14} no longer yields the shorthand intro.


style=authoryear,style=authoryear-comp,already needs more intricate code, even more sostyle=ext-authoryear-comp,. I fixed a logic error in my answer to the linked question, but it will probably still not be applicable for you. Please explain exactly what you would like to see in the output (in particular if pre- and postnotes are involved, what you want to happen if you cite several entries from the same author one with shorthand one without, keep in mind that\texctcitealways mentions the author with shortand, do you want that?) – moewe Mar 18 '21 at 07:24\textcite{ref1,ref2}would be the correct way to cite here and that it should work. Relying on\textcite{ref1} and \textcite{ref2}instead is really a kludge. The code you have copied is simply not suitable for the style you are using, so errors or weird output are to be expected. I'll see what I can do, but I can't promise I will be able to come up with a solution tonight. You may want to have a look at the code I posted above and explain what output you would like to see in that example. It contains more test cases that are relevant here. – moewe Mar 18 '21 at 17:13\textcite{jd14} again \textcite[34]{jd14}to show. Do you want the second\textciteto show just "JD14" or "Doe (JD14)"? (Surprisingly the former is much harder to get right in the current\textciteframework). – moewe Mar 21 '21 at 07:13\textcite{jd14}in line 1 to yield "JD14", but the combined\textcite{jd13,jd15}"Doe, Smith and Bar (2013, JD15)"? If you want just "JD14" in the first line, I would have expected "Doe, Smith and Bar (2013) and JD15" for consistency. Note that standard behaviour of\textciteis to always print the labelname, so if you don't want it, then you have to actively work against that (and all the code that assumes it). – moewe Mar 21 '21 at 21:21