# Switch styles for special words

I want to create a Cloze test in Mathematica.

I want to have text in a text cell and leave some words blank (to be filled in by students).

With a button I want be able to switch between styles for those words (visible red or invisible and replaced by dots for example). How could this be done?

• Should those blanks be editable? – Kuba May 2 '17 at 6:45
• Not necessarily. Originally I was looking for some global setting like in TeX which I could change. – Darwin1871 May 2 '17 at 18:25

One out of many possible ways:

hideF = Row[List @@ StringReplace[#,  w: Alternatives @@ #2 :> Style["...", Blue]]] &;
highlightF = Row[List @@ StringReplace[#, w: Alternatives @@ #2 :> Style[w, Red, Bold]]] &;

text = StringTake[ExampleData[{"Text", "LoremIpsum"}], 200];
words = {"amet", "rutrum", "feugiat"};

FlipView[{hideF[text, words], highlightF[text, words]}]


• Thank you very much for all the possibilities. Originally I was looking for a global setting changing some "marked" words in text cells. But the answer from kglr might work well. – Darwin1871 May 2 '17 at 18:28

Just as a start:

f = DynamicModule[{col = White},
DynamicWrapper[Dynamic[Style[#, col]],
If[CurrentValue["MouseOver"], col = Red, col = White]]] &;
DynamicModule[{dat = (f /@ {"pig", "dog"})},

{Button["White highlight", FrontEndTokenExecute["FontColor", White]],