How to prevent \xspace from adding a full space after a period?

I have a little macro that I use for doing adding an e.g. in my writing:

\newcommand{\eg}{\emph{e.g.}\xspace}


The problem I have is that LaTeX is treating the g. as the end of a sentence and is spacing too much. Is there any way to disable this feature?

Add \@ to the definition of your custom macro. See When should I use intersentence spacing (\@')? for details.

\documentclass{article}

\usepackage{xspace}

\newcommand{\origeg}{\emph{e.g.}\xspace}
\newcommand{\eg}{\emph{e.g.}\@\xspace}

\begin{document}

Some text \origeg and some more

Some text \eg and some more

\end{document}
`