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

I'm looking to cause the front end to display individual characters in a specific color, just in general, as a default sort of thing. For instance, the character "1" would always display as a red 1, except of course when an output color is manually specified. I'm basically looking for something like the image. I have no idea how to go about doing this. I looked at stylesheets enough to know I hate them.

enter image description here

share|improve this question

What a strange idea! You could play with this approach:

rainbow[l_List] := (l /.
{"1" -> Style["1", 18, Red],
 "2" -> Style["2", 18, Blue],
 "3" -> Style["3", 18, Purple],
 "4" -> Style["4", 18, Cyan, Background -> Black]
(* and so on *)

format[i_Integer] := Row[Join[rainbow[ToString /@ IntegerDigits[i]]]];

$Post = format;

Now your integer answers are displayed in Rainbow Style:

2 ^ 47

colored text

However, I'm not sure how $Post interacts with the rest of the front end, so don't do anything important with this set-up.

Coloring other types of number is LAAEFTR...

share|improve this answer
You should make $Post Bold because it is the most important line in this page :) – Kuba May 30 '13 at 20:03
@cormullion I like how you implemented this, except for the &Post. It really tends to mess up a lot of other kinds of evaluations. However, with a few filters added I could make this very workable. ty. – mystackexchangeusername Jun 6 '13 at 18:00
@mystackexchangeusername Yes, I wasn't keen on completely ruining the display of all other output... :) But used in NumberForm it might be more useful! – cormullion Jun 6 '13 at 18:32

Using this and this you can do something like that:

myNumber[n_] := N[ChampernowneNumber[], n]
myStringedNumber[n_] := StringCases[ToString[myNumber@n], DigitCharacter]

Block[{n = 15}, 
      {Style["0.", Black], 
  {i, 1,Length@myStringedNumber@n-1}]}]]]


But there must be a prettier way.

share|improve this answer
This 'stretches' the hue gradient over the entire string of digits, rather than displaying each character with a specific color. Not quite what I had in mind, but still interesting, especially with much longer strings. – mystackexchangeusername Jun 6 '13 at 17:57

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.