5

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

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371

2 Answers2

10

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

cormullion
  • 24,243
  • 4
  • 64
  • 133
  • 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 06 '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 06 '13 at 18:32
5

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}, 
  Row[
    Flatten[
      {Style["0.", Black], 
  Table[Style[myStringedNumber[n][[i+1]],Hue[1/Length@myStringedNumber@n*i]],
  {i, 1,Length@myStringedNumber@n-1}]}]]]

0.123

But there must be a prettier way.

Öskå
  • 8,587
  • 4
  • 30
  • 49
  • 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 06 '13 at 17:57