I’ve noticed that macros have been deprecated. I know they won’t be going away any time soon, but I thought - as a learning exercise - I’d convert a macro of mine to a procedure. Sounds simple, but I’ve spent probably hours now unsuccessfully trying to get it to work as smoothly as the macro.
My macro has several parameters, and depending on what I’m doing I’ll either pass in a string to be output as-is, or I need to set a variable to the result of a filter and pass that in. For my use case at least, procedures appear to be a retrograde step.
I have created a simplified test case below:
\define dtest(arg) $arg$
\procedure ptest1(arg) <<arg>>
\procedure ptest2() <<arg>>
* Macro:
** <<dtest pass>>
** <$let test={{{[[]addsuffix[ss]addprefix[pa]]}}}><<dtest $(test)$>></$let>
* Procedure1 (with parameter, called same as macro)
** <<ptest1 pass>>
** <$let test={{{[[]addsuffix[ss]addprefix[pa]]}}}><<ptest1 $(test)$>></$let>
* Procedure1 (with parameter, variable named as parameter)
** <$let arg=pass><<ptest1>></$let>
** <$let arg={{{ [[]addsuffix[ss]addprefix[pa]] }}}><<ptest1>></$let>
* Procedure2 (no parameter, called same as macro)
** <<ptest2 pass>>
** <$let arg={{{[[]addsuffix[ss]addprefix[pa]]}}}><<ptest2>></$let>
* Procedure2 (no parameter, calls adjusted to work)
** <$let arg=pass><<ptest2>></$let>
** <$let arg={{{[[]addsuffix[ss]addprefix[pa]]}}}><<ptest2>></$let>
Which renders as:
- Macro:
-
- pass
-
- pass
- Procedure1 (with parameter, called same as macro)
-
- pass
-
- $(test)$
- Procedure1 (with parameter, variable named as parameter)
-
-
- Procedure2 (no parameter, called same as macro)
-
-
- pass
- Procedure2 (no parameter, calls adjusted to work)
-
- pass
-
- pass
The $let syntax isn’t too bad, but that implies to me that parameters to procedures are of no use to me - I’m better off just setting variables as needed prior to using the procedure.
After all that, the end result appears to be extra typing for no benefit, meaning I’m better off forgetting procedures and sticking with macros.
Am I doing procedures wrong? Is there something I’ve missed?
Addendum: I was just about to hit “Post”, when I made the mistake of trying out the last example of $let+procedure with my actual macro and absolutely everything broke! Something is up with quotes inside the procedure. I’ll have to spend another hour or so experimenting and creating a new example. I am finding “\procedure” completely frustrating, while “\define” “just works”.