7
$\begingroup$

I can't see a way to get Mathematica to check my spelling as I type. Is this feature not supported? I've done everything I can think of with my options:

enter image description here

Is there a setting I'm missing?

$\endgroup$
  • $\begingroup$ Unless I am mistaken this syntax colouring is only for Input Cells. $\endgroup$ – Mike Honeychurch Nov 15 '12 at 21:55
  • $\begingroup$ @MikeHoneychurch: So is there no "while you type" spelling error highlighting for basic text?! $\endgroup$ – orome Nov 15 '12 at 21:56
  • $\begingroup$ Not AFAIK ...but there is so much in Mathematica that I do not know. Someone else may know of this if it exists. $\endgroup$ – Mike Honeychurch Nov 15 '12 at 22:00
2
$\begingroup$

This is almost a solution:

Module[{str},
 checkPrevWord[char_] := (
   SelectionMove[nb, Previous, Word];
   SelectionMove[nb, All, Word];
   str = StringJoin[
     StringCases[NotebookRead[nb] /. StyleBox[a_, b___] :> a, 
      RegularExpression["\\w"]]];
   If[StringLength[str] =!= 0 && 
      Length[DictionaryLookup[str, IgnoreCase -> True]] === 0, 
     SetOptions[NotebookSelection[nb], FontColor -> Red]; 
     SelectionMove[nb, Next, Word];
     SetOptions[NotebookSelection[nb], FontColor -> Black],
     SetOptions[NotebookSelection[nb], FontColor -> Black];
     SelectionMove[nb, Next, Word]
     ]
    NotebookWrite[nb, char];);

 SetOptions[nb =  CreateDocument[], 
  NotebookEventActions -> ({"KeyDown", #} :> 
       checkPrevWord[#] & /@ {" ", ";", ".", "-", "!", "?", ",", "/"})];
 ]

I create a new notebook and check if the previous word you typed is in the dictionary (English). Unfortunately, I do not know how to test for being in a TextCell versus any other Cell, so the spell-checker will try to check the code too. Also, (BEWARE), this crashes Mathematica if you delete your text cell.

Note that you can replace CreateDocument with SelectedNotebook if you want to affect the current notebook.

Hopefully someone can help me identify what I'm missing, and then we'll have a spell-highlighter.

$\endgroup$
  • $\begingroup$ So does this mean that Mathematica, unlike every other text editing tool on the planet, doesn't have as-you-type spellchecking? $\endgroup$ – orome Nov 16 '12 at 20:06
  • $\begingroup$ @raxacoricofallapatorius None that I know of. However, it does seem to be implementable. I don't think Wolfram had Microsoft Word in mind when MMA was being made. $\endgroup$ – VF1 Nov 16 '12 at 20:23

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.