This question already has an answer here:

Is it possible to define a command \MyCommand which does not swallow the next space (standard) but inserts a real space after itself only if the next symbol followed by it is a real space-symbol or CR? The command is supposed to have no arguments.

marked as duplicate by TeXnician, Troy, Torbjørn T., egreg macros May 6 '18 at 12:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What's wrong with \MyCommand{}? – gusbrs May 6 '18 at 11:56
  • You can try xspace, but I wouldn't do it, but use {} after the command. See also tex.stackexchange.com/questions/86565/drawbacks-of-xspace/… – Ulrike Fischer May 6 '18 at 11:57
  • Btw, while you wait for an answer here, you might well go back to your other questions which have received an answer and, if they have solved your problem, mark them as accepted. – gusbrs May 6 '18 at 12:02

No, because the following space has been swallowed by TeX's parser already before the command itself runs.

  • Do I right guess that an attempt to catch a space symbol after a command by construction\@ifnextchar ... \fi will not help? – maximav May 10 '18 at 12:20
  • @maximav The guess should not be about space symbols but about space tokens. (La)TeX' reading- and tokenizing-apparatus will not tokenize a space-character trailing something that was tokenized as a control word token. Besides this,the LaTeX2e-kernel-variant of \@ifnextchar cannot easily be used for checking for space-tokens. Internally it uses \let in a way where space-tokens will be treated as <one optional space> which will be discarded, leading to unpredictable results. This is rectified with some packages that redefine \@ifnextchar. – Ulrich Diez May 31 '18 at 17:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.