Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

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.

share|improve this question
add comment

marked as duplicate by Mr.Wizard Apr 28 '13 at 14:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

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] <> ")" 
share|improve this answer
add comment

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]
  ], 
  ")"
}]
share|improve this answer
add comment

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