I have a few commands that I have defined as follows:
\newcommand{\G}{
\ifmmode%
\mathcal{G}
\else$\mathcal{G}$\fi
}
Annoyingly, if I write This a graph \G such that it outputs the \G and the such together. I know it is because the space after \G is there to finish the command, and not to be a proper space.
So I tried:
\newcommand{\G}{
\ifmmode%
\mathcal{G}
\else
$\mathcal{G}$
\fi
}
And this leaves a space behind. But, if I write we have graph \G, which... it will leave a space between the \G and the ,.
Is there a way of saying "automatically leave a space, except if it is punctuation." ?
Thanks
.,,,:,;,',-,!,~,),]? And what if the next character is a backslash? Moreover, pretty much anything will work only in standard (English?) contexts ... – cfr Mar 14 '18 at 03:40\ensuremath{\mathcal{G}}? – cfr Mar 14 '18 at 03:43xspace, in questions like space-after-latex-commands, drawbacks-of-xspace, acceptable-use-cases-for-xspace-when-will-it-fail, etc. Basicallyxspaceis the state-of-the-art (as far as I can tell), but nothing is perfect and it may be better to get used to the standard ways. – ShreevatsaR Mar 14 '18 at 03:52\ensuremath, thanks for that – excalibur1491 Mar 14 '18 at 04:09\newcommand{\G}{\mathcal{G}}and typeThe graph $\G$ is interesting. – egreg Mar 14 '18 at 07:28$\G$as well as being simpler and more robust (try your definition in aarraycell) has the benefit of avoiding\xspace(which it really is best to avoid) as the space is not dropped after$– David Carlisle Mar 14 '18 at 07:48