So I proposed to do like this (minimal example)
[code]
\documentclass[12pt]{article}
\usepackage{color,ifthen}
\newcommand*\mchar{\fontfamily{ptm}\fontsize{24}{24}\selectfont\color
{red}}
\newcounter{cname}\setcounter{cname}{0}
\makeatletter
\newcommand\createcommands[1]{%
\@for\@myarg:=#1\do{
\stepcounter{cname}
\ifthenelse{\arabic{cname}=1}{\newcommand\chupleft{\mchar \@myarg}}
{}
\ifthenelse{\arabic{cname}=2}{\newcommand\chupcenter{\mchar \@myarg}}
{}
\ifthenelse{\arabic{cname}=3}{\newcommand\chupright{\mchar \@myarg}}
{}
\ifthenelse{\arabic{cname}=4}{\newcommand\chleft{\mchar \@myarg}}{}
\ifthenelse{\arabic{cname}=5}{\newcommand\chright{\mchar \@myarg}}{}
\ifthenelse{\arabic{cname}=6}{\newcommand\chlowerleft{\mchar
\@myarg}}{}
\ifthenelse{\arabic{cname}=7}{\newcommand\chlowercenter{\mchar
\@myarg}}{}
\ifthenelse{\arabic{cname}=8}{\newcommand\chlowerright{\mchar
\@myarg}}{}
}
}
\makeatother
\begin{document}
\createcommands{1,2,3,4,5,6,7,8}
% 1,2,3,4,5,6,7,8 are in fact eight border characters to make a framed
text box, so they can be anything, 'a,b,c,d,e,f,g,h', etc. That's why
I set up a counter `cname' and did silly ifthenelse comparisons.
\chupleft
\end{document}
[/code]
Once compile, I got \chupleft as undefined sequence.
[quote][color=#FF0000]
! Undefined control sequence.
\@myarg ->\@nil
l.24 \chupleft
?
[/color][/quote]
So apparently the \chupleft is defined but then seemingly goes out of
scope, how can I have them preserved and use after \begin{document}?
Thanks.
BTW, I've used another approach with package `tokenizer' and had
similar result. I've read about some topics on variable expansion
(\expandafter, \csname, \endcsname) without success.
Please instruct, thanks!
[color=#CCCCCC]Tagged_by_kmc : latex command nested[/color]
Search comp.text.tex for the following discussion:
"Is it possible to use a for loop in LaTeX/TeX to define a sequence of
new commands"
Nothing goes out of scope.
The \@for-loop defines the token \@myarg to expand
to the item of the current iteration, that is
iteration 1: -> \@myarg will expand to 1
iteration 2: -> \@myarg will expand to 2
iteration 3: -> \@myarg will expand to 3
iteration 4: -> \@myarg will expand to 4
iteration 5: -> \@myarg will expand to 5
iteration 6: -> \@myarg will expand to 6
iteration 7: -> \@myarg will expand to 7
iteration 8: -> \@myarg will expand to 8
End of loop -> \@myarg will expand to \@nil
(which in turn is undefined).
Your macro \createcommands puts the token \@myarg
into the replacement-texts of the definitions of the macros
\chupleft, \chupcenter, \chupright, \chleft, \chright,
\chlowerleft, \chlowercenter and \chlowerright.
Thus expanding those macros delivers the token \@myarg.
Expanding \@myarg delivers \@nil. \@nil is undefined
and you get an error-message.
You don't really want that. Instead of the token \@myarg
You want to get the _expansion_ of \@myarg into these
replacement-texts.
Besides this: Curly braces are character-tokens.
Spaces and line-endings do count as spaces after
character-tokens. Terminate your lines correctly.
If you don't want a line-ending to deliver a space, either
end the line by % (comment-char) or by a control-word.
Ulrich
Thanks Pluto, problem resolved, I've opted to use \forcsvloop.