I want to define a command \mycommand so that \mycommand 1 and \mycommand1 work differently.
Here is my try based on \futurelet and \@sptoken, but it doesn't work:
\documentclass{article}
\makeatletter
\def\mycommand{\futurelet\@nexttoken\mycommand@}
\def\mycommand@{
\ifx\@nexttoken\@sptoken
space
\else
nospace
\fi
}%
\makeatother
\begin{document}
\mycommand 1
\mycommand1
\end{document}
Both of them give nospace 1
\mycommandexecutes, the space is already gone. You could define\csname mycommand1\endcsnameas a separate macro, but you would need to add\csnameevery time to execute it. – John Kormylo Jan 12 '24 at 02:17process_input_buffercallback and set up a Lua function that operates like a preprocessor on the input stream. The Lua function would use Lua's pattern matching to distinguish between\mycommand 1and\mycommand1and issue some replacement code based on which case holds. Once the preprocessor is done with its work, TeX will actually not "see" either\mycommand1or\mycommand 1; instead, it will "see" whatever replacement code the Lua function was told to insert. – Mico Jan 12 '24 at 03:03\myspacingversus\myspacing[1]) – user202729 Jan 12 '24 at 04:06\myspacing3is not so better than\myspacing[3], and the latter one will be easy to do, and understood by any LaTeX user down the line. The first syntax is calling for troubles. – Rmano Jan 12 '24 at 08:49\mycommand? – Ulrich Diez Jan 13 '24 at 21:05\mycommand, or an ecplicit space token by reading/tokenizing some characters from a line of .tex-input and appending that token to the token-stream, the reading-apparatus of TeX switches to state S(skipping blanks) which implies that subsequent characters of the line of .tex-input whose current category code is 10(space) just get discarded instead of triggering the appending of whatsoever token to the token stream. – Ulrich Diez Jan 13 '24 at 21:17