cite not working with 2 arguments

I want to include a reference with text before the citation in parentheses, like so: "(e.g., Brautigam & Bell, 1995)". I have to use the \cite command, because it's a journal template with strict rules, but it doesn't render correctly when using two arguments. I am using bibtex and it seems to be linked correctly.

In my latex file:

\cite [one][two]{brautigam1995crresele}


In the pdf:

In the Texshop console:

LaTeX Warning: Citation [' undefined on input line 228.


With just one argument it seems to be fine:

\cite [one]{brautigam1995crresele}


In the pdf:

But of course I need the second argument to make 'e.g.' appear before the reference. Adding { and } around the command does not help. Any ideas?

• What happens if you remove the space between cite and [? – gusbrs Mar 26 at 15:31
• Not all implementation of \cite support two optional arguments. The standard implementation from the LaTeX kernel only has one optional argument for the page number/postnote, but no argument for the prenote. natbib and biblatex support two optional arguments, some other citation packages (real packages loaded with \usepackage, not bibliography styles called with \bibliographstyle) may or may not define a prenote argument or a equivalent replacement. – moewe Mar 27 at 10:54

Edit

As mentionned in a comment by moewe, the natbib package provides the command \citep which accepts two optional arguments such that \citep[one]{brautigam1995crresele} will give the "normal" behavior of \cite, \citep[one][]{brautigam1995crresele} will use one as a prenote and nothing as a postnote and \citep[one][two]{brautigam1995crresele} will use one as a prenote and two as a postnote.

This implementation is cleaner that the one proposed in the original answer below.

The problem here is that we don't know what class file your editor is using and if it redefines the \cite command, allowing for the use of two optional arguments. Indeed, as far as I know, the \cite command only takes one optional argument and the label of the bibliographical entry as a mandatory argument.

Without this information, a solution (a bit overkill, I admit), would be to declare a new command having two optional arguments (requiring the use of xargs):

\documentclass{article}

\usepackage{xspace}
\usepackage{xargs}
\usepackage{xifthen}
\newcommandx{\mycite}[3][1 =, 2 =]{%
\ifthenelse{
\isempty{#1}{}
}{
\ifthenelse{
\isempty{#2}{}
}{
\cite{#3}
}{
\cite[#2]{#3}
}
}{
\ifthenelse{
\isempty{#2}{}
}{
#1,\xspace\cite{#3}
}{
#1,\xspace\cite[#2]{#3}
}
}
}

\usepackage{filecontents}
\begin{filecontents}{biblio.bib}
@article{olfati2004consensus,
title={Consensus problems in networks of agents with switching topology and time-delays},
author={Olfati-Saber, Reza and Murray, Richard M},
journal={IEEE Transactions on automatic control},
volume={49},
number={9},
pages={1520--1533},
year={2004}
}
\end{filecontents}

\begin{document}

\mycite[one][two]{olfati2004consensus}

\mycite[][two]{olfati2004consensus}

\mycite[one]{olfati2004consensus}

\mycite[one][]{olfati2004consensus}

\bibliographystyle{apalike}
\bibliography{biblio}

\end{document}


The above codes yields:

However, if your editor is really strict about defining new commands, you might have no other option than to write "e.g.," by hand before your \cite` command.

• I switched to the journal's template in Overleaf which (for some reason) uses citep instead, and your first suggestion worked. Thanks for your insight! – Alex Mar 29 at 10:01