I have spend a good time searching in references and forums for a answer to the question I'm raising here.
I would like to write a macro that gets a word as a parameter without needing to using braces informing this. It would be a smart macro that recognizes what should be a component of a parameter, constructing it token by token until finding a not proper candidate (that will be replaced intact after finishing the macro itself). For examples
\def\km#1{% definition: only accept numbers: writes the unit after the subsequent integer word (parameter)%}
\def\mathstyle#1{% definition: accept anything except point and space: put parameter in mathmode (assumes that is called in "text mode" for simplification)%}
% usage
The radius of the Earth is about \km 6300. %%
%% *\km 6300.* expands to 6300 $km$.
The distance between \mathstyle Point-A to \mathstyle Point-B is \km 20 assume that the Earth is plain.
%% puts Point-A and Point-B between math shifts
In short, in order to achieve this, supposedly, I need to check the characters one by one and recalling a handling macro until a not recognizable token is taken by it.
The problem is: in many cases TeX ignores spaces after a macro. So, I wasn't able to create a macro that handles with spaces (concatenating all words separated by spaces).
How can I fix? How to now destroy a space after a macro?



\ifcatexpands everything in the way and compares the next two unexpandable tokens, this can cause unexpected problems if\nexthad been some macro. – plante Sep 24 '21 at 13:53\letor\futurelet) are an exception. For example\if{\bgroup(where\bgroupis defined via\let\bgroup= {) is true . – plante Sep 24 '21 at 14:08