I'd like to have a macro to split up another macro content, with field separator being a space. So:
\def\mytext{foo bar}
\def\secondof#1 #2{#2}
\secondof\mytext
What? What do you mean: "runaway argument"? Oh right, I guess \mytext counts as only one argument and you're expecting two. Ok, so
\expandafter\secondof\mytext
and indeed, the result is "bar", just as I was hoping for.
But alas, then comes something rather surprising:
\def\firstof#1 #2{#1}
\expandafter\firstof\mytext
"fooar"? You got to be kidding me! How on earth did you—dear and beloved TeX—ever come to such a ridiculous decision? You did so well with the \secondof, after all. What gives?
(just to make this a complete MWE, I'm going to add a \bye here)
\secondofworks as expected? – morbusg Nov 27 '11 at 19:53\def\secondof#1 #2([[#2]])and you'll see what is happening. – Aditya Nov 27 '11 at 20:03#2"bleed" into the#1? – morbusg Nov 27 '11 at 20:09\secondofdid not worked as expected.\expandafter\secondof\mytextgives you onlyb. Thearis left and will be typeset as ordinary text, so the end result will beb+ar. (The same way\firstofgave youfoo+ar=fooar.) Change\secondofto\def\secondof#1 #2{(#2)}and you'll see that only thebwill be typeset in parens. – Nov 27 '11 at 20:19