# How to use the space for \def argument's separator

Assume there is a line including some single letter like A, b, C, etc. and the letters separate by only one white space, which ASCII code is 32, say,

D B g A


I want the content for a \def's arguments, For example,

\def\mydef#1 #2 #3 #4{\textbf{#1}\textit{#2}\textsc{#3}\textsl{#4}}


the

\mydef{D B g A}


output bold D, italic B, smallcap g, and slanted A. Other situations export a warning message. Note: the \r\n (ASCII code 13) or \n (ASCII code 10) be seen as ending of \mydef.

-
Actually, neither \r\n nor \n is what your \mydef sees, since TeX converts all the various system-dependent newline indicators into its internal one ^^M (which I believe is the same ASCII code as \n, however). –  Ryan Reich Apr 28 '11 at 13:57

\documentclass{article}
\def\mydef#1 #2 #3 #4{\textbf{#1}\textit{#2}\textsc{#3}\textsl{#4}}
\def\myDef#1{\expandafter\myDefi#1}
\def\myDefi#1 #2 #3 #4{\textbf{#1}\textit{#2}\textsc{#3}\textsl{#4}}
\begin{document}
\mydef A B C D foo

\myDef{A B C D} foo
\end{document}

-
Nice solution! Thanks. –  Stufazi Hoqckt Apr 28 '11 at 8:44
What's the \expandafter for? The #1 will be "expanded" before \myDefi anyway, by the macro substitution rules, so it looks like you want to expand argument #1 of \myDefi but not the others. –  Ryan Reich Apr 28 '11 at 13:59
in this case it has no meaning, but it doesn't hurt and I use it by default, because I do not really know what arguments users may have in mind. –  Herbert Apr 28 '11 at 14:55

\mydef{D B g A} is reading {D B g A} as first argument because of the { }. It then looks for the #2 #3 #4 part afterwards and raises an error if there is no such input. You need to either write directly \mydef D B G A or use a second macro like that inside \mydef, which is more often used.

\def\mydef#1{\mydefb#1}
\def\mydefb#1 #2 #3 #4{\textbf{#1}\textit{#2}\textsc{#3}\textsl{#4}}


You might want to add a trailing space to ensure that all input of \mydef is processed by \mydefb, otherwise if the last part is more than one letter the rest is just typeset after \mydefb:

\def\mydef#1{\mydefb#1 }
\def\mydefb#1 #2 #3 #4 {\textbf{#1}\textit{#2}\textsc{#3}\textsl{#4}}

-
Thanks your detailed explain. But Herbert is earier so I get tick to him. Too hard do the choice! –  Stufazi Hoqckt Apr 28 '11 at 8:51