General ⇒ Macro with argument signature from another macro?
Macro with argument signature from another macro?
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!
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Macro with argument signature from another macro?
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}