5
$\begingroup$

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

$\endgroup$
10
$\begingroup$

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

$\endgroup$
  • $\begingroup$ You should make $Post Bold because it is the most important line in this page :) $\endgroup$ – Kuba May 30 '13 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$ – mystackexchangeusername Jun 6 '13 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 Jun 6 '13 at 18:32
5
$\begingroup$

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.

$\endgroup$
  • $\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$ – mystackexchangeusername Jun 6 '13 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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