Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question

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.

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

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
    "$" <> ToString[dollarWon], 
    If[dollarWon >= 0, Darker[Green], Red]
share|improve this answer

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