[Tex/LaTex] Abbreviations and full stop–how to avoid double dots

macrospunctuation

I have trouble with macros expanding to an abbreviated expression. Say I have \WHP which expands to "with high prob." (artificial example). I want to avoid the dot after the abbreviation colliding with full stops later on, like

"We concluded that hypothesis holds \WHP."

which should not expand to

"We concluded that hypothesis holds with high prob.."

but simply end with one full stop.

Best Answer

\documentclass{article}
\makeatletter
\def\WHP{with high prob\@ifnextchar.{}{.}}% test of next token 
\makeatother

\begin{document}
\WHP

\WHP.
\end{document}
Related Question