2
$\begingroup$

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?

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

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]}]

enter image description here

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Darwin1871 May 2 '17 at 18:28
3
$\begingroup$

Just as a start:

f = DynamicModule[{col = White}, 
    DynamicWrapper[Dynamic[Style[#, col]], 
     If[CurrentValue["MouseOver"], col = Red, col = White]]] &;
DynamicModule[{dat = (f /@ {"pig", "dog"})}, 
 Dynamic[Grid[MapThread[{#1, #2} &, {{
      "Pork comes from a ", "An animal that barks is a"}, 
     UnderBar /@ dat
     }], Alignment -> Left]]]

enter image description here

$\endgroup$
2
$\begingroup$
{Button["White highlight", FrontEndTokenExecute["FontColor", White]],
 Button["Red highlight", FrontEndTokenExecute["FontColor", Red]]}

then type: "Here is some random text"

Double click on a word then click on a color highlight button.

$\endgroup$

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.