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

Does anyone know whether it is possible to combine\join two styled strings?

That is, while the following code works fine:

omega = "text";

when I try to join my omegas into one string but having different colors like this


mma returns this error:

StringJoin::string: String expected at position 1

It's clear to me that the objects I'm trying to join have head Style not String, but may be there is a way to produce a string that has its parts painted in different colors?

share|improve this question
Related: – Mr.Wizard Sep 23 '12 at 22:01
up vote 29 down vote accepted

Use Row to join them:

Omega = "text";
joined = Row[{Style[Omega, Lighter[Blue, .1]], Style[Omega, Darker[LightBlue, .1]]}];
share|improve this answer

Given two styled items:

omega = "text"

items = { Style[omega,Lighter[Blue,.1]], Style[omega,Darker[LightBlue,.1]] }

We can produce a single string with both stylings if we convert each item into a StandardForm string prior to joining them:

Apply[StringJoin, ToString[#, StandardForm] & /@ items]

The following screenshot shows the results:

styled concatenation session

share|improve this answer
Nice. Also Row@items ~ToString~ StandardForm though the format is not as clean. – Mr.Wizard Sep 23 '12 at 22:11

If you evaluate or print the following string you get what you want:

"\!\(\*StyleBox[\"text\",FontColor->RGBColor[1, 0, 0]]\) \!\(\*StyleBox[\"text\",FontColor->RGBColor[0, 0, 1]]\)"

Mathematica graphics

This is a single string and it contains color information for different substrings.

Do[Print@"\!\(\*StyleBox[\"text\",FontColor->RGBColor[1, 0, 0]]\) \!\(\*StyleBox[\"text\",FontColor->RGBColor[0, 0, 1]]\)", {5}]

Mathematica graphics

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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