Teaching my grandson mathematics in the online regime through Skype, I show him my screen on which a Mathematica notebook is open. I use it to give him tasks by writing simple arithmetical expressions (according to his age) in the Input Cells. Then I show him how to cope with them.

In the course of such sessions I faced one need: I would like to be able to highlight some elements of the expression on the screen. I imagine to operate as follows: I write the expression, then mark its desired element and press a button of a palette with different colors. As a result, the marked element turns into a desired color. Such a palette already exists in the Classroom Assistant but it takes too many clicks to use it. Methodically, it is a disadvantage, since it takes too much time during which the child may get distracted. Such a highlighting should be made quickly. I need a special palette that would hover over the screen and it should take one click to apply.

I tried the following:

CreatePalette[{Button[Style["Red    ", White], 
    Evaluate[Style[NotebookRead[InputNotebook[]], Red]]], 
   Background -> Red],
  Button[Style["Blue   ", White], 
    Style[NotebookRead[InputNotebook[]], Blue]], Background -> Blue], 
  Button[Style["Green", White], 
    Style[NotebookRead[InputNotebook[]], Green]], 
   Background -> Green]}]

which does not do what I expected.

Any idea, how to achieve that?


1 Answer 1


Instead of NotebookRead and NotebookWrite, you should use FrontEndExecute to change the FontColor. Here is a simple implementation:

With[{colors = {Red, Blue, Darker@Green, Yellow}}, 
  Button[" ", 
     FrontEndExecute[{FrontEndToken[InputNotebook[], FontColor, #]}]; 
     FrontEndExecute[FrontEndToken[InputNotebook[], "MoveNext"]], 
     Background -> #, ImageSize -> {80, 20}] & /@ colors, 
  WindowTitle -> "Text Color", Saveable -> False]

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.