Hello,
I am trying to write a macro that uses another macro to determine the signature of the arguments but I cannot get it to work. I tried something like this:
\edef\fmt{\string#1}%
\def\tmp{\def\showval}%
\expandafter\tmp\fmt{Here is the argument: '#1'}%
but it throws the error "Illegal parameter number in definition of \showval" like if \fmt was not expanded before \tmp. I guess it is a catcode problem but I can't figure out how to fix it...
Thanks!
General ⇒ Macro with argument signature from another macro?
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Macro with argument signature from another macro?
There are a couple of solutions. First, you could use a token register (toks):
(A toks is a special kind of storage area, that can hold "#" tokens safely.)
The second approach is to use the e-TeX \unexpanded primitive:
This approach does let you put a "#" inside a macro, something you normally cannot do.
Code: Select all
\newtoks\mytoks
\mytoks{#1#2}
\expandafter\def\expandafter\temp\the\mytoks{code here}
The second approach is to use the e-TeX \unexpanded primitive:
Code: Select all
\edef\tempa{\unexpanded{#1}}
\expandafter\def\expandafter\temp\tempa{code here}
Joseph Wright