With careful nesting of all three forms of quoting (single-quotes: '
, double-quotes: "
, and tripled double-quotes: """
), you can achieve the results you want with only one variable, like this:
<$let makeBtn="""<$button actions='<$macrocall $name=showPart id="$partpartnum$" origin:"$(host)$"/>'>see</$button>""">
Note the use of tripled double-quotes around the entire let
assignment value, single-quotes around the actions
parameter value, and regular double-quotes around the inner $macrocall
parameter values.
There is also a handy trick that lets you use that all three kinds of quotes when creating a variable by using the \define
pragma:
\define variablename() This value contains """tripled quotes""", and "double quotes" and 'single quotes'
and, you can do this within a macro definition to create local, private variables:
\define myMacro(someparam)
\define variablename() argle "bargle" """$someparam$""" 'mumble' frotz... gronk snork!
... rest of macro goes here ...
\end
This creates a macro named myMacro
that takes one parameter (someparam
), and then defines a local variable named variablename
that is “in scope” until the end of the containing myMacro
macro.
Note that the variablename definition must be a “one-liner”; i.e., you can’t use multple lines followed by a \end
, as this would prematurely terminate the containing myMacro
definition.
Also note that the \define variablename()
can’t declare any parameters of its own, since all parameter references within the variablename
definition (e.g., $something$
) will be processed when the containing myMacro
macro is invoked. However, you can use parameters from the containing myMacro
macro within the variablename
definition, as those values are processed and replaced with the values passed in to myMacro
.
As an example: suppose you have a macro, e.g., doFilter
, that takes a filter definition as a parameter. Normally, you might write something like this:
\define doFilter(filt)
...
<$list filter="$filt$">...</$list>
...
\end
The problem is that the filter might contain some double-quotes, in which case you might think to use tripled double-quotes around the $list
filter parameter, like this:
\define doFilter(filt)
...
<$list filter="""$filt$""">...</$list>
...
\end
This improves things a bit, but there’s still a problem if the value of filt
also can contain some tripled double-quotes. In this case, you can use the “local define” method described above as a work-around:
\define doFilter(filt)
\define filt() $filt$
...
<$list filter=<<filt>>>...</$list>
...
\end
Note that this can also be done using the <__param__>
“macro param-as-variable” syntax, like this:
\define doFilter(filt)
...
<$list filter=<__filt__>...</$list>
...
\end
So, you can see that, while it’s a bit tricky and subtle, “there are many ways to skin a cat” (the wierdest method is to poke a small hole in the end of their tail and then suck out the innards with a vacuum pump!
)
Conclusion: Jeremy is brilliant!
-e