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


2 Answers 2


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...

  • $\begingroup$ You should make $Post Bold because it is the most important line in this page :) $\endgroup$
    – Kuba
    Commented May 30, 2013 at 20:03
  • $\begingroup$ @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. $\endgroup$ Commented Jun 6, 2013 at 18:00
  • $\begingroup$ @mystackexchangeusername Yes, I wasn't keen on completely ruining the display of all other output... :) But used in NumberForm it might be more useful! $\endgroup$
    – cormullion
    Commented Jun 6, 2013 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.

  • $\begingroup$ 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. $\endgroup$ Commented Jun 6, 2013 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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