I am trying to write Latex report generator for my standard data analysis. But there is an issue with formatting numbers I can not get around. I would like to make use of my own NumberFormat and StringTemplatess but the last reformats the numbers. Here is an example:

n = QuantityMagnitude@UnitConvert@Quantity["PlanckConstant"]


ScientificForm[n, 3, 
 ExponentFunction -> (If[-10 < # < 10, Null, #] &), 
 NumberFormat -> (If[#3 != "", Row[{#1, "e", #3}], #1] &)]


StringTemplate["A: ``"]@%

A: 0.00000000000000000000000000000000066260696

Is there a way to make StringTemplate output the numbers in a format I have specified? I guess the problem might have something to do with underlying TextString.


2 Answers 2


The default InsertionFunction for StringTemplate is TextString; use ToString instead:

SetOptions[StringTemplate, InsertionFunction -> ToString]

Looks like a bug, here is simple workaround:

StringTemplate["A: ``"]@ToString@%
"A: 6.63e-34" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.