# How does AutoStyleWords work?

The title says it all. I assume it provides some way of automatically applying a certain style, or a list of options, to certain words written, just like other options of the sort like AutoItalicWords. But I haven't been able to make it work...

Thanks!

-
I tried to change that setting and it crashed Mathematica. :-O – Mr.Wizard Mar 6 '12 at 9:48

A very similar question came up internally at WRI, so I have a nearly ready-made answer. In that case, the fellow wanted to highlight certain loop constructs, like Do and For in his code automatically. Here's how I responded.

In a fresh notebook, Format->Edit Stylesheet..., then paste and interpret the cells below at the bottom of the stylesheet. And voila, you'll got purple Dos and Fors in the notebook the stylesheet modified.

{
Cell[StyleData["Input"],
AutoStyleWords->{"Do"->"MyStyle", "For"->"MyStyle"}],

Cell[StyleData["MyStyle"],
FontColor->RGBColor[0.5, 0, 0.5]]
}


Rojo is correct that this doesn't have to be in a newly created stylesheet...you could set it in the OI at the notebook or global level, or add it to a shared stylesheet. What I'm doing here is providing a specific formula that any newbie can follow and make work. This, like any other option, works in various and predictable manners which I'm happy to elucidate on in other questions where the issue would be on topic. And, to clarify...it's not "executing code"...it's merely an option setting like Background or FontColor or any other. – John Fultz Mar 9 '12 at 8:02