I am trying to define a bespoke citation command which mimics the behaviour of \citep[][]{} but for the case when I am using some citation alias, e.g. when the author is an institution and I want its acronym.
The problem I have is that, when there is no text after the citation, Latex is still displaying a space between the year and the closing parenthesis. I have tried defining a \checkEmpty command based on this post but to no avail.
My code is below:
\documentclass{article}
\usepackage[]{natbib}
\usepackage[colorlinks=true,allcolors=blue]{hyperref}
\defcitealias{BCBS2011}{BCBS}
\newcommand{\checkEmpty}[1]{
\if\relax\detokenize{#1}\relax{\ignorespaces}\else{#1}\fi
}
\newcommand{\mycitepalias}[3]{
\citepalias[#2][\citeyear{#1}\checkEmpty{#3}]{#1}
}
\begin{document}
\noindent%
\mycitepalias{BCBS2011}{}{}\
\mycitepalias{BCBS2011}{with text before}{}\
\mycitepalias{BCBS2011}{with text before}{and after}
\bibliography{bibliography.bib}
\end{document}
The output is displayed below. As you can see in the first and second line, there is an undesirable space.
PS: As a bonus, I would like to add a comma after the date in case there is text after the citation.


%... but at the wrong place that is after\relaxinstead of the very beginning of the command. Cheers. – Daneel Olivaw Feb 29 '24 at 11:51