2

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], 
   NotebookWrite[InputNotebook[], 
    Evaluate[Style[NotebookRead[InputNotebook[]], Red]]], 
   Background -> Red],
  Button[Style["Blue   ", White], 
   NotebookWrite[InputNotebook[], 
    Style[NotebookRead[InputNotebook[]], Blue]], Background -> Blue], 
  Button[Style["Green", White], 
   NotebookWrite[InputNotebook[], 
    Style[NotebookRead[InputNotebook[]], Green]], 
   Background -> Green]}]

which does not do what I expected.

Any idea, how to achieve that?

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96

1 Answers1

2

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}}, 
 CreatePalette[
  Button[" ", 
     FrontEndExecute[{FrontEndToken[InputNotebook[], FontColor, #]}]; 
     FrontEndExecute[FrontEndToken[InputNotebook[], "MoveNext"]], 
     Background -> #, ImageSize -> {80, 20}] & /@ colors, 
  WindowTitle -> "Text Color", Saveable -> False]
 ]
Domen
  • 23,608
  • 1
  • 27
  • 45