In short, I want the following ...
\def\foo{??????????????}
\def\bar{bar}
A \foo-foo, a \foo, and a \foo came into a \foo. Says the \foo: Why the \foo?
\def\bar{baz.}
A \foo-foo, a \foo, and a \foo came into a \foo. Says the \foo: Why the \foo?
... to produce the following output:
A bar-foo, a bar, and a bar came into a bar. Says the bar: Why the bar?
A baz.-foo, a baz., and a baz. came into a baz. Says the baz.: Why the baz.?
That is, I want \foo to be equivalent to \bar but to prevent printing a double dot .. if \bar ends with .and the next character is also ..
So far, I manage to do this only with \bar doing some bookkeeping (e.g. \def\bar{bar\endswithpointfalse} vs.\def\bar{baz.\endswithpointtrue} (and \let\foo\bar, i.e., no further wrapping needed) and replacing \foo. with \foo\ifendswithpoint\else.\fi), but that is tedious in more complicated cases or impossible if \bar is third party. As there is apparently no such thing as \lastchar, I wonder if any other trick without such bookkeeping is possible?


\usepackage{xspace}and\def\foo{\bar\xspace}you should get the desired results. – Peter Grill Nov 17 '19 at 09:21