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.
2 Answers
$\begingroup$
$\endgroup$
3
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
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$– KubaCommented 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$ Commented Jun 6, 2013 at 18:32
$\begingroup$
$\endgroup$
1
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}]}]]]
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