4
$\begingroup$

How to keep irrational number as their original form rather than approximation when using StringTemplate?

StringTemplate["`1`"][Sqrt[3]]

This will output approximation "1.73205" rather than $\sqrt{3}$. And outputs "Pi" rather than $\pi$.

$\endgroup$
4
$\begingroup$

Use the setting (ToString[#, StandardForm]&) for the option InsertionFunction:

StringTemplate["`1` and `2`", 
  InsertionFunction -> (ToString[#, StandardForm]&)][Sqrt[3], Pi]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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