How to peek and test whether the next character is a digit?
The format of the citation received is
\citename{Apple \& Orange, }9999
So it's a matter of redefining \citename
when necessary.
\begin{filecontents*}{\jobname.bib}
@article{test1,
title={Secret of the {U}niverse},
author={Angry Apple and Outraged Orange},
journal={nowhere},
year={9999}
}
\end{filecontents*}
\RequirePackage{amsmath}
\documentclass{jfp}
\usepackage{filecontents}
%\usepackage{jfphack}
\usepackage{xpatch}
\makeatletter
\newif\if@citet
\let\citet\cite
\xpretocmd{\cite}{\@citetfalse}{}{}
\xpretocmd{\citet}{\@citettrue}{}{}
\newcommand{\citetcitename}[1]{%
\citet@removecomma#1\@nil
\afterassignment\citet@year\count@
}
\def\citet@year{(\the\count@)}
\def\@cite#1#2{%
\if@tempswa
#2%
\else
\if@citet
\begingroup
\let\citename\citetcitename
#1%
\endgroup
\else
(#1)%
\fi
\fi
}
\def\citet@removecomma#1, \@nil{#1~}
\makeatother
\title{}
\author{}
\affil{}
\email{}
\begin{document}
\cite{test1} % want "Apple & Orange (9999)"
\citet{test1}
\bibliographystyle{jfp}
\bibliography{\jobname}
\end{document}
This assumes the year is present.
You can simplify the @ifnextdigit very much by using futurelet
\def\@ifnextdigit#1{\def\@doit{#1}\futurelet\next\@finish}
\def\@finish{\ifcat3\next\expandafter\@doit\fi}
To use it, you place whatever command is to be executed on finding a digit as the argument to @ifnextdigit. It is then stored in \@doit. Then we use futurelet to peek at the next token after this macro is expanded, and store it in \next. Then we use the ifcat test to check if it has the category code of a number, and if it does, execute \@doit.