[Tex/LaTex] the difference between \textcolor and \color

color

I would like to define a new command to work as an alert command. If I want to alert some part of my text I would simply write \alert{}. But I want the result in red color.

What is the best way to do this? I tried

\def\alert#1{{\color{red}{#1}}}

but I know that there is \textcolor also. I want my command to work both for text and math contents.

What is the difference between them?

Best Answer

Despite the name \textcolor also works in math mode. The main difference is just one of syntax, \textcolor takes text as an argument (like \textrm) \color affects all text to the end of the group (like \rmfamily). However \textcolor also executes \leavevmode which makes the color special occur in a much less destructive place as part of the paragraph rather than on a vertical list. So \textcolor is usually a better choice unless you are setting a colour for a large amount of text, such as the whole document.