4
$\begingroup$

Writing:

"x =" <> ToString[1/2]

I get:

enter image description here

and even if I tried in the forum I could not find a way to get rid of this problem, namely to obtain:

enter image description here

or better still:

enter image description here

Thank you!


Last formatting problem. Writing:

"x =" TextForm[1/2 q (l - 2 \[Xi])]

I get:

enter image description here

where the outer bracket is completely useless. Is it possible to remove it?

$\endgroup$
  • $\begingroup$ What are you looking to get? $\endgroup$ – Vsevolod A. Feb 11 '18 at 10:12
  • $\begingroup$ @VsevolodA.: I modified the request, thank you! $\endgroup$ – TeM Feb 11 '18 at 10:15
  • $\begingroup$ Try "x =" TextForm[1/2] $\endgroup$ – Vsevolod A. Feb 11 '18 at 10:17
9
$\begingroup$
"x = " <> ToString[1 / 2, StandardForm]  (* or *)
Row[{"x = ", StandardForm[1/2]}]

enter image description here

"x =" <> ToString[1/2 q (l - 2 \[Xi]), StandardForm] (* or *)
Row[{"x =", StandardForm[1/2 q (l - 2 \[Xi])]}]

enter image description here

You can use TraditionalForm in place of StandardForm above to get similar outputs.

$\endgroup$
  • $\begingroup$ This strategy, in effect, solves all my problems above. Thank you! $\endgroup$ – TeM Feb 11 '18 at 10:56
  • $\begingroup$ @TeM, my pleasure. Thank you for the accept. $\endgroup$ – kglr Feb 11 '18 at 10:58
2
$\begingroup$

Something like ToString["x =" TextForm[1/2]] produces a 3 string with text formatted as necessary, if that's what you are looking for.

$\endgroup$
  • $\begingroup$ Please note that the output is text and it's poorly formatted i.e. division is made with "-" placed between strings with 1 and 2. $\endgroup$ – Vsevolod A. Feb 11 '18 at 10:22
  • $\begingroup$ Thanks to your help I managed to get what you wanted, i.e. copying what you wrote and placing "StandardForm" instead of "TextForm". I posed a last problem. Could you give us an eye, please? Thank you! $\endgroup$ – TeM Feb 11 '18 at 10:50

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.