# \textcolor

Colors a single argument, used to highlight one term in a formula without affecting what follows; an optional model argument such as rgb, RGB, or gray gives the color numerically.

https://texform.dev/latex/commands/textcolor

## Metadata

| Field | Value |
| --- | --- |
| Packages | color, textmacros |
| Allowed mode | math, text |
| Tags | presentation |
| Commonality | medium |
| Kind | prefix |

## Syntax

### color

Argument specification: `o:N m:N m`

Colors a single argument, used to highlight one term in a formula without affecting what follows; an optional model argument such as rgb, RGB, or gray gives the color numerically.

### textmacros

Argument specification: `o:N m:N m:T`

Colors a span of text inside text-mode content such as \text; the colored argument is text and may contain inline math, and an optional model argument gives the color numerically.

## Examples

```latex
\textcolor{red}{x^2} + y^2
```

[Open in Playground](https://play.texform.dev/?input=%5Ctextcolor%7Bred%7D%7Bx%5E2%7D+%2B+y%5E2)

```latex
f(x) = \textcolor{blue}{\sin x} + \cos x
```

[Open in Playground](https://play.texform.dev/?input=f%28x%29+%3D+%5Ctextcolor%7Bblue%7D%7B%5Csin+x%7D+%2B+%5Ccos+x)

```latex
\textcolor[RGB]{0,128,0}{a + b} = c
```

[Open in Playground](https://play.texform.dev/?input=%5Ctextcolor%5BRGB%5D%7B0%2C128%2C0%7D%7Ba+%2B+b%7D+%3D+c)

```latex
\frac{\textcolor{red}{\partial f}}{\partial x}
```

[Open in Playground](https://play.texform.dev/?input=%5Cfrac%7B%5Ctextcolor%7Bred%7D%7B%5Cpartial+f%7D%7D%7B%5Cpartial+x%7D)

```latex
\text{\textcolor{red}{important}}
```

[Open in Playground](https://play.texform.dev/?input=%5Ctext%7B%5Ctextcolor%7Bred%7D%7Bimportant%7D%7D)

```latex
\text{see \textcolor{blue}{this note} for $x > 0$}
```

[Open in Playground](https://play.texform.dev/?input=%5Ctext%7Bsee+%5Ctextcolor%7Bblue%7D%7Bthis+note%7D+for+%24x+%3E+0%24%7D)

```latex
\text{\textcolor[RGB]{0,128,0}{valid for $n \ge 1$}}
```

[Open in Playground](https://play.texform.dev/?input=%5Ctext%7B%5Ctextcolor%5BRGB%5D%7B0%2C128%2C0%7D%7Bvalid+for+%24n+%5Cge+1%24%7D%7D)

## Package variants

| Package | Argument specification | Allowed mode | Description |
| --- | --- | --- | --- |
| color | o:N m:N m | math | Colors a single argument, used to highlight one term in a formula without affecting what follows; an optional model argument such as rgb, RGB, or gray gives the color numerically. |
| textmacros | o:N m:N m:T | text | Colors a span of text inside text-mode content such as \text; the colored argument is text and may contain inline math, and an optional model argument gives the color numerically. |

## Renderer support

| Package | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- |
| color | full | partial | full |
| textmacros | full | partial | full |

## Usage frequency

<0.01% of formulas in the measured corpus contain this entry, rank 201 of 263 entries with frequency data.

## In TeXForm

TeXForm parses this entry as prefix syntax; the package determines its argument specification.

## See also

- [\\color](https://texform.dev/latex/commands/color)
- [\\colorbox](https://texform.dev/latex/commands/colorbox)
- [\\fcolorbox](https://texform.dev/latex/commands/fcolorbox)

## Test cases

### color

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \textcolor{blue}{a} | Positive: baseline | Pass | Pass | Pass |
| \textcolor[RGB]{0,0,255}{a} | Positive: vary:o[0] | Pass | Fail | Pass |
| \textcolor{blue}a | Positive: bare[2] | Pass | Pass | Pass |
| \textcolor[\alpha]{0,0,255}{a} | Negative: neg:N[0] | Fail | Fail | Fail |
| \textcolor{\alpha}{a} | Negative: neg:N[1] | Pass | Fail | Fail |

### textmacros

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \textcolor{blue}{a} | Positive: baseline | Pass | Pass | Pass |
| \textcolor[RGB]{0,0,255}{a} | Positive: vary:o[0] | Pass | Fail | Pass |
| \textcolor{blue}a | Positive: bare[2] | Pass | Pass | Pass |
| \textcolor[\alpha]{0,0,255}{a} | Negative: neg:N[0] | Fail | Fail | Fail |
| \textcolor{\alpha}{a} | Negative: neg:N[1] | Pass | Fail | Fail |
| \textcolor{blue}{a^2} | Negative: neg:T[2] | Fail | Fail | Fail |
