I had a similar problem as this one: Space after LaTeX commands
My first attempt was something like this:
\newcommand{\satip}{SAT\textgreater IP}
This leads to the known Problem, that spaces after the command are eaten up:
\satip is a cool Protocol. %Produces: SAT>IPis a cool Protocol.
space missing ^^^
I searched around and found the mentioned Question. The provided solutions helped a lot, but I wasn't completely happy with any of them. \satip/ just looks a little bit strange in a latex document, I like \satip{} much more. It's just, if I forget to put {} behind the command, the space is missing in output. Therefor I'd like to get an error if I use it wrong.
Possible Solution:
\def\satip#{SAT\textgreater IP}
%\satip is a cool Protocol. %doesn't compile, error
This way the open brace is enforced, but the braces can contain something:
\satip{is} a cool Protocol.
This compiles well, but as it doesn't make any sense, I'd like it to produce an error. My current way to handle the Problem is this:
\expandafter\def\csname satip{}\endcsname \relax{SAT\textgreater IP}
\def\satip#1{\csname satip{}\endcsname #1\relax}
%\satip{is} a cool Protocol. %Use of \satip{} doesn't match its definition.
%\satip is a cool Protocol. %Use of \satip{} doesn't match its definition.
\satip{} is a cool Protocol. %works
Now my Question:
This Macro needs a second expansion step. Could that cause any trouble? Are there other Problems? (As I haven't found this anywhere before.)
PS: Sorry for the bad title, I didn't came up with something better. Feel free to edit.
\satip\, and I don't see why\satip{is}should produce an error with that definition. – Paul Gessler Feb 14 '16 at 22:51\satip{} is a cool protocolwith your first definition\newcommand*\satip{SAT\textgreater IP}, no need to define it obscurely. – Manuel Feb 14 '16 at 22:51\satip\. If you really want an error,\def\satip/is a reasonable way to go, and surely easier to write than\satip{}. And of course in the right circumstances, the\xspacepackage may be an option, though it is not always the right choice (there's a question oncomp.text.texabout this). – jon Feb 14 '16 at 23:02\satip{ip}doesn't produce an error, but i want it to produce an error, since this usage doesn't make any sense. (i'm not good with english, how can i say it more clearly?) – T S Feb 14 '16 at 23:05ip(a brace-delimited group) is typeset immediately following the expansion of macro\satip. Whether that is what you want is another matter, but in terms of how (La)TeX works, it's perfectly valid usage. – Paul Gessler Feb 14 '16 at 23:12{}as a conceptual delimiter for the control sequence, any deviation from{}should raise an error.\satip{\relax}compiles just fine. Also, you have no way of knowing if you are overwriting an existing control sequence with the namesatipor (less likely)satip{}by using\def. – Guho Feb 14 '16 at 23:35\satip{\relax}thanks. In the final version I wanted to guard the definition with\@ifundefinedor similar... – T S Feb 14 '16 at 23:53#{. Might be of interest. – Guho Feb 15 '16 at 00:43