0

I have two new commands like

\def\test[#2]#1{
\test#1[#2]
}

\def\testOne[#2]{
#2 is given
}

if I use the following command \test[xy]{One}, it doesn't work, because \test#1[#2] expands to \test{#1}[#2]. So it expands to \test{One}[xy] instead of testOne[xy].

Is there any possibility, to make this work?

  • 6
    \def\test[#1]#2{\csname test#2\endcsname{#1}} – Ulrike Fischer Apr 8 '16 at 17:18
  • 1
    I think @UlrikeFischer actually meant \def\test[#1]#2{\csname test#2\endcsname[#1]}. But note that you must say \def\testOne[#1]{#1 is given}, because argument must be numbered in progression. May I ask why the square brackets? – GuM Apr 8 '16 at 17:46
  • @UlrikeFischer: That's exactly, what I was looking for, thanks. If you want to post it as an answer, go ahead, otherwise, I will post it as a solution. \csname was,what I was looking for. From now on, I can goolge the rest of it. @GustavoMezzetti: I used the correct numbering in my tex-document. I changed it here for readability, but thanks for this useful advice. – MaestroGlanz Apr 8 '16 at 18:49
0

UlrikeFischer and GustavoMezzetti answered the (actually simple) question. Thanks a lot.

The code must be

\def\test[#1]#2{\csname test#2\endcsname[#1]}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.