[OS X TeX] Getting full expansion from recursive macros?
Paul Hagstrom
hagstrom at bu.edu
Sat Apr 19 03:47:43 EDT 2008
Greetings, OS X TeX list. This is really a more general (La)TeX
question, but let me ask what I hope is a very long question with a
very short and simple answer.
The most basic version of the problem is something like this. I have
a macro \SinR that takes a word X and returns what I've defined as
macroX.
\newcommand{\SinR}[1]{\csname macro#1\endcsname}
I have a macro that takes a set of words and performs this operation
on them in sequence. I ensure that the set of words ends in \\.
\def\singllr#1 #2\\%
{\def\more{#2}\ifx\more\empty\let\more=\singlldone\else\let\more=
\singllr\fi
\SinR{#1} \more#2\\%
}
\def\singlldone#1\\{}
So far, this seems to work. If \macroX is A, \macroY is B and \macroZ
is C, \singllr X Y Z \\ will give me A B C.
What I want to do with this, however, is feed it to the cgloss4e
package, which allows you to line up the words in two lines. This is
what I tried (where the \singllg macro is basically identical to the
\singllr macro except it calls \SinG instead of \SinR to do a
different transform):
\newcommand{\SinDBEXglldef}[3]{%
\def\TopLine{\singllr#2 \\}
\def\MidLine{\singllg#2 \\}
\expandafter\def\csname DBEXFormat#1\endcsname
{\gll \TopLine \\ \MidLine \\ \glt #3}
}
What the cgloss4e package does is defines \gll as \gll#1\\ #2\\ (more
or less, it's actually a subsequently invoked macro), so it is looking
for things delimited by \\s, and it will then take each one and break
it into words at the spaces using the very same technique I used in
\singllr above.
The problem is (I believe): \TopLine and \MidLine in my \SinDBEXglldef
macro are each being treated as a single unit -- none of the spaces
inside are noticed, and so nothing gets lined up (or, rather, each
entire line's left edge is aligned, rather than the left edge of each
word in the lines).
If I have diagnosed the problem correctly, I think that \TopLine and
\MidLine are not getting expanded at the right time. I'd expect this
behavior if, at the point where \gll is looking at it, \TopLine is
still an unexpanded token, only getting expanded after \gll is
finished. That is, I think I must be executing something like
\gll {{A} {{B} {{C}}}} \\ {{X} {{Y} {{Z}}}} \\ glt ...
when what I need is really
\gll A B C \\ X Y Z \\ glt ...
I have tried all kinds of intermediate definitions, and sprinkling
\expandafters and \noexpands in almost every conceivable combinations
of places, but I just can't seem to get it to work. Incidentally, the
following macro *does* work -- when I invoke it like \DBEXgldef{name}
{string of words}{line me up}{paraphrase}, the result winds up being
just as I would have gotten if I'd defined \DBEXFormatname directly as
{\gll string of words \\ line me up \\ paraphrase}, and if I feed that
to cgloss4e, everything's fine.
\newcommand{\DBEXgldef}[4]{%
\expandafter\def\csname DBEXFormat#1\endcsname
{\gll #2 \\ #3 \\ \glt #4}
}
Having spent much time now digging around on the web and reading as
much as I can find, I thought I might just try posing it as a question
on the list. Is there any way to get my \TopLine token to be fully
expanded before the assignment happens? Or have I misdiagnosed the
problem? Any help at all (even just "RTFM", particularly if you tell
where I might locate the manual) would be very much appreciated..
-Paul
More information about the MacOSX-TeX
mailing list