LatexNotes

Coloured text in LaTeX

The xcolor package colours text: \textcolor{red}{...} colours what is in the braces, and \colorbox{yellow}{...} puts it on a coloured background.

LaTeX command

\textcolor{red}{red text}

Not the symbol you meant? Draw it to find the command →

Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →

Load xcolor, then \textcolor{blue}{...} for a few words, or the switch {\color{blue} ...} for a longer passage. Both work in maths too, so one term of an equation can stand out. \colorbox gives a background, and \fcolorbox{red}{white}{...} a frame and background.

xcolor knows 19 names out of the box, among them red, blue, green, orange, purple, teal, gray and black. The dvipsnames option adds 68 more, such as ForestGreen and RoyalBlue. A ! mixes with white: blue!60 is 60% blue, a lighter tint, and red!50!black is a darker red.

For an exact colour, such as a university's or a brand's, define it once by name with \definecolor, from RGB values or an HTML code, and use that name everywhere.

Load xcolor and define your own colours

The package line, the extra named colours, and a colour of your own from its HTML code.

\usepackage{xcolor}
\usepackage[dvipsnames]{xcolor}
\definecolor{brand}{HTML}{1E5AA0}

Other forms

{\color{blue} blue text}a colour switch
\colorbox{yellow}{highlighted}a coloured background
\textcolor{blue!60}{lighter blue}a tint, 60% blue
\definecolor{brand}{RGB}{30,90,160}your own colour

Examples

$\textcolor{red}{\text{red text}}$

red text

$x^2 + \textcolor{blue}{2x} + 1$

one term in blue

$\colorbox{yellow}{highlighted}$

a coloured background

$\fcolorbox{red}{white}{$x = 4$}$

a red frame around an answer

Tips and common mistakes

Working from handwritten notes?

LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.

See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).

Convert your maths to LaTeX →

FAQ

How do I change text colour in LaTeX?

Load xcolor and write \textcolor{red}{your text}.

How do I highlight text in LaTeX?

Use \colorbox{yellow}{your text} with xcolor, or the soul package's \hl for highlighting that wraps.

How do I colour part of an equation?

Use \textcolor inside the maths, as in x^2 + \textcolor{blue}{2x} + 1.

How do I use a custom colour?

Define it with \definecolor{brand}{HTML}{1E5AA0}, then write \textcolor{brand}{...}.

See also