This question has been asked for several times, notably here. However, most solutions involved the package xspace which, as I heard, should be avoided.
I'm currently using the following definitions:
\newcommand{\ie}{\emph{i.e.}\@ifnextchar.{\!\@gobble}{}}
\newcommand{\eg}{\emph{e.g.}\@ifnextchar.{\!\@gobble}{}}
\newcommand{\etc}{etc\@ifnextchar.{}{.\@}}
which produce result like this:
However, since I'm not familiar with the TeX macros involved, I'm not sure if the spacing shall always be correct. Also, the post-spacing seems to vary with different fonts used (e.g., with Palatino Linotype as the main font, the spacing after i.e. seems larger, and I shall have to change \! to \!\!). And the main drawback of these definitions is that a simple \ie without . after it shall produce a large whitespace.
As this seems to be a very basic question, I think there should be some very mature solutions. Is there an existing package, or an existing set of macros that can do this perfectly?
Below is a MWE.
\documentclass{article}
\usepackage{newpxtext}
\makeatletter
\newcommand{\ie}{\emph{i.e.}@ifnextchar.{!@gobble}{}}
\newcommand{\eg}{\emph{e.g.}@ifnextchar.{!@gobble}{}}
\newcommand{\etc}{etc@ifnextchar.{}{.@}}
\makeatother
\begin{document}
Some text, \ie. some explanations.
Some text, \ie, some explanations.
Some text, \eg. some examples.
Some text, \eg, some examples.
Some text, \etc. Here is another sentence.
Some text, \etc, continuing.
\end{document}


etc.the macro doesn't really help at all. – David Carlisle Apr 02 '22 at 12:51etc., in fact what I mainly wished to know about wasi.e.because the spacing after it is a bit peculiar. – Jinwen Apr 02 '22 at 12:54\newcommand\ie{\textit{i.e.}is all you need. – David Carlisle Apr 02 '22 at 12:58\ie{} blah-blah. – Steven B. Segletes Apr 02 '22 at 13:08