# \@ifnextchar breaks kerning when expanded

I've defined a macro for an initialism (abbreviation) with periods, making sure that an end-of-sentence period is not printed twice: \gp prints "G.P." and \gp. prints "G.P." Here's an M.W.E.:

\documentclass{article}
\makeatletter\def\gp{G.P\@ifnextchar.{}{.}}\makeatother
\begin{document}
\end{document}


However, this breaks the kerning between the final letter and the final period — see the attached screenshot. This is a pretty minor issue of course, but I find it kind of interesting. The lack of kerning is more pronounced with some other fonts, including Palatino (\usepackage{mathpazo}). Am I abusing \@ifnextchar or is there some other issue? (The same happens with ligatures, although I can't think of a useful application for the following: \makeatletter\def\doublef{f\@ifnextchar f{}{f}}\makeatother and ff --- \doublef f --- \doublef i --- ffi.)

• Any assignment between two characters breaks kerning. – egreg Dec 15 '15 at 18:19
• @egreg Not true in LuaTeX! – Joseph Wright Dec 15 '15 at 18:29
• \newcommand*\gp{\@ifnextchar.{G.P}{G.P.}} – cgnieder Dec 15 '15 at 18:32
• \def\gp{G.P.\@ifnextchar.{\@gobble}{}} – user2478 Dec 15 '15 at 18:52
• @tanh you can load \usepackage{ltxcmds} and then use \newcommand*{\fixdot}[1]{#1\ltx@ifnextchar@nospace.{\@gobble}{}} – cgnieder Dec 16 '15 at 9:50

\def\gp{G.P.\@ifnextchar.{\@gobble}{}}

\@gobble is defined in the latex kernel as \def\@gobble#1{}
• Thank you! Reading the definition of \@gobble also makes it clear wow it works. This can be generalized to take an argument using \ltx@ifnextchar@nospace from the ltxcmds package, as suggested by @clemens in their comment to my question. – tanh Dec 16 '15 at 15:51
• not relevant here but \@gobble is declared as \long\def\@gobble#1{}, thus with LaTeX syntax as \newcommand{\@gobble}[1]{}. – user4686 Dec 16 '15 at 16:56
• yes, because #1 can include paragraphs – user2478 Dec 17 '15 at 8:27