TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First of all, I apologize if this is a repetitive question. I searched, but couldn't find it. I was wondering if I can change the color of symbols in latex. For example \ast always give me a black symbol. Is there anyway to change it? (either changing it permanently throughout the document or changing it just once.

share|improve this question
\textcolor{red}{\ast}. \textcolor works in math mode as well. To redefine it globally \let\OldAst\ast \renewcommand{\ast}{\textcolor{red}{\OldAst}}. – Peter Grill Nov 30 '12 at 23:09
@PeterGrill: It works; great! Thank you. I wish you had written it as an answer; then I get to select it as correct answer; just for the future reference. Would you please do that? – N Nik Nov 30 '12 at 23:22
Well, looks like Heiko's answer is a much better solution. Good to have real experts on this site. – Peter Grill Nov 30 '12 at 23:40
up vote 33 down vote accepted

\textcolor of package color adds a level of curly braces that become a subformula in math mode, destroying the spacing. The following example defines \mathcolor that can be used in the same way as \textcolor, but without the subformula side effect. It uses \begingroup and \endgroup instead of the curly braces that do not cause the trouble in math. A grouping level is needed for LaTeX's color handling that restores the color after the group via \aftergroup.



$a\ast b$




The parameter text of \mathcolor is #1# with a final hash symbol without number. That means all tokens before the next opening curly brace are put into #1. In case of \mathcolor (or \textcolor) this is the optional argument. Without an optional argument #1 is empty, otherwise it contains the optional argument including the square brackets.

share|improve this answer
Would you add an explanation why you need #1 in the definition of \mathcolor? – egreg Nov 30 '12 at 23:52
@egreg I have updated the answer to add an explanation. – Heiko Oberdiek Nov 30 '12 at 23:56
Thanks. I had in mind something with \binrel@ of amsmath but it's not as general as your code. – egreg Nov 30 '12 at 23:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.