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.

  • 5
    \textcolor{red}{\ast}. \textcolor works in math mode as well. To redefine it globally \let\OldAst\ast \renewcommand{\ast}{\textcolor{red}{\OldAst}}. 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
  • 2
    Well, looks like Heiko's answer is a much better solution. Good to have real experts on this site. Nov 30 '12 at 23:40

\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.

  • 1
    Would you add an explanation why you need #1 in the definition of \mathcolor?
    – egreg
    Nov 30 '12 at 23:52
  • 1
    @egreg I have updated the answer to add an explanation. 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 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.