Macro TeX edef

I spent some time trying to write a helper macro to check the parameter for the new value, otherwise use the existing value - default values ​​exist for all parameter positions.

I wanted to write:

\foo{left}{nil}{}{20pt} 

so that the second parameter uses its current value, but the third value would be the empty string value. I wanted to use the notation:

 \edef\pA{\isnil{#1}{\pA){#1}} % one for each parameter 

I defined \ isnil as follows:

 \def\nil{nil} \def\isnil#1#2#3{% \edef\nilTest{#1}% \ifx\nilTest\nil#2\else#3\fi } 

but when I tried to run it, TeX complained that \ nilTest was an undefined escape sequence. Of course, this is true, but I want \ pA to save the value, not the recipe for the value, so it should be \ edef, which means that all macro tests will be expanded, but so far \ edef will not protect \ nilTest - this is the place to use \ noexpand - this doesn't seem to work for me.

EDIT: There are no digits in the names of \ cs (yes, I knew that.)

+4
source share
1 answer

Why is your solution not working? \edef\pA{\isnil{#1}{\pA){#1}} extends \isnil and gets \edef\nilTest{... Now \edef does not expand and falls into the sequence \ pA as the first element. Attempting to deploy the following \nilTest macro fails.

Use \setpar from the following code to change your parameter.

 \def\nil{nil} \def\setpar#1#2{% \edef\nilTest{#2}% \ifx\nilTest\nil\else\let#1\nilTest\fi} \def\first{old first} \def\second{old second} \setpar \first{nil} \setpar \second{new} first = ``\first'', second = ``\second'' 

PS Do not use numbers in a macro.

+3
source

All Articles