0
$\begingroup$
dollarWon := 100
"(" <> Style["$" <> ToString[dollarWon], If[dollarWon >= 0, Darker[Green], Red]] <> ")"

I am getting an error: String expected at position 2. Isn't it possible to use Style in the above expression?

Thanks.

$\endgroup$
0
5
$\begingroup$

Style[..] is not a string. Convert it to string by using StandardForm format to preserve style information:

dollarWon := 100
"(" <> ToString[
    Style["$" <> ToString[dollarWon], 
    If[dollarWon >= 0, Darker[Green], Red]], StandardForm] <> ")" 
$\endgroup$
3
$\begingroup$

I think you may be better of using Row in this case, which lets you show arbitrary objects in a row, like so:

dollarWon = 100
Row[{
  "(", 
  Style[
    "$" <> ToString[dollarWon], 
    If[dollarWon >= 0, Darker[Green], Red]
  ], 
  ")"
}]
$\endgroup$

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