Say, I want to write a MMA script using StringTemplate
, so I can insert additional pieces of code / expressions wherever TemplateSlot
s appear. It is a bit unclear to me, however, how I should handle these slots. For example the template
tmp = StringTemplate[
ToString[
Unevaluated[
Pi/2 + "`a`" + 2
],
InputForm
]
]
gives
tmp[<|"a" -> 1|>]
(* Pi/2 + "1" + 2 *)
That is, it looks like the parameter 1
is substituted as a String
whereas it should be a number. This is not the case, however. What actually happens is, that 1
gets inserted, but the quotation marks in the template remain. So how should I declare TemplateSlot
s in my StringTemplate
? It should work with any MMA code inside the Unevaluated
.
OutputForm["`a`"]
instead of"`a`"
? $\endgroup$"a"->-1
. $\endgroup$-1
(after applyingToExpression
in the end). $\endgroup$"Pi/2 + - 1"
does not look well. $\endgroup$