> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/formatting/13-using-colors-in-latex.md).

# Using colours in LaTeX

## Introduction

This article explains how to use color in your LaTeX document via the [`color`](https://ctan.org/pkg/color?lang=en) or [`xcolor`](https://ctan.org/pkg/xcolor?lang=en) packages. Note that user-level documentation of the `color` package is contained in [The LaTeX standard graphics bundle](http://mirrors.ctan.org/macros/latex/required/graphics/grfguide.pdf).

Both packages provide a common set of commands for color manipulation, but `xcolor` is more flexible and supports a larger number of color models, so is the recommended approach.

We’ll start with the following example:

```latex
\documentclass{article}
\usepackage{xcolor}
\begin{document}
This example shows some instances of using the \texttt{xcolor} package
to change the color of elements in \LaTeX.

\begin{itemize}
\color{blue}
\item First item
\item Second item
\end{itemize}

\noindent
{\color{red} \rule{\linewidth}{0.5mm}}
\end{document}
```

[Open this `xcolor` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=A+basic+xcolor+package+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bxcolor%7D%0A%5Cbegin%7Bdocument%7D%0AThis+example+shows+some+instances+of+using+the+%5Ctexttt%7Bxcolor%7D+package+%0Ato+change+the+color+of+elements+in+%5CLaTeX.%0A%0A%5Cbegin%7Bitemize%7D%0A%5Ccolor%7Bblue%7D%0A%5Citem+First+item%0A%5Citem+Second+item%0A%5Cend%7Bitemize%7D%0A%0A%5Cnoindent%0A%7B%5Ccolor%7Bred%7D+%5Crule%7B%5Clinewidth%7D%7B0.5mm%7D%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Example use of xcolor package in LaTeX](/files/9wTzyZL9v6b59nNq1H1h)

In this example, the package `xcolor` is imported with

```latex
\usepackage{xcolor}
```

then the command `\color{blue}` sets the `blue` color for the current block of text. In this case for the `itemize` environment.

The code to typeset the horizontal line created by `\rule{\linewidth}{0.5mm}` is contained in a group, delimited by { and }, in order to keep the effects of the `\color{red}` local to that group.

## Named colors provided by the xcolor package

As noted in the [xcolor package documentation](http://mirrors.ctan.org/macros/latex/contrib/xcolor/xcolor.pdf), the following named colors are always available without needing to load any package options:

![list of colours in the xcolor package](/files/pSIGHK0xqyrGHWdpcFrp)

### Accessing additional named colors

Additional named colors can be accessed via the following `xcolor` package options:

* `dvipsnames`: loads 68 named colors (CMYK)
* `svgnames`: loads 151 named colors (RGB)
* `x11names`: loads 317 named colors (RGB)

For example, if you write

```latex
\usepackage[dvipsnames]{xcolor}
```

you can access the following named colors:

![colours loaded by dvipsnames option of xcolor package](/files/Z1MKHESeE1TDG0HAXW0b)

Refer to the [xcolor package documentation](http://mirrors.ctan.org/macros/latex/contrib/xcolor/xcolor.pdf) for tabulated lists of colors provided by the `svgnames` and `x11names` options.

### Example usage

The following example uses named colors loaded via the `dvipsnames` option.

```latex
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\begin{document}
This example shows how to use the \texttt{xcolor} package
to change the color of \LaTeX{} page elements.

\begin{itemize}
\color{ForestGreen}
\item First item
\item Second item
\end{itemize}

\noindent
{\color{RubineRed} \rule{\linewidth}{0.5mm}}

The background color of text can also be \textcolor{red}{easily} set. For
instance, you can change use an \colorbox{BurntOrange}{orange background} and then continue typing.
\end{document}
```

[Open this `**xcolor**` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+xcolor+package+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bdvipsnames%5D%7Bxcolor%7D%0A%5Cbegin%7Bdocument%7D%0AThis+example+shows+how+to+use+the+%5Ctexttt%7Bxcolor%7D+package+%0Ato+change+the+color+of+%5CLaTeX%7B%7D+page+elements.%0A%0A%5Cbegin%7Bitemize%7D%0A%5Ccolor%7BForestGreen%7D%0A%5Citem+First+item%0A%5Citem+Second+item%0A%5Cend%7Bitemize%7D%0A%0A%5Cnoindent%0A%7B%5Ccolor%7BRubineRed%7D+%5Crule%7B%5Clinewidth%7D%7B0.5mm%7D%7D%0A%0AThe+background+color+of+text+can+also+be+%5Ctextcolor%7Bred%7D%7Beasily%7D+set.+For+%0Ainstance%2C+you+can+change+use+an+%5Ccolorbox%7BBurntOrange%7D%7Borange+background%7D+and+then+continue+typing.%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Demonstration of the xcolor package](/files/jTABuK0agAeKiFionMq3)

Two new commands are also used in the example:

* `\textcolor{red}{easily}`: Changes the color of inline text. This command takes two parameters, the color to use and the text whose color is changed. In the example the word `easily` is printed in `red`.
* `\colorbox{BurntOrange}{orange background}`: Changes the background color of the text passed in as the second argument. In the example above, the words `orange background` are typeset on a background color of `BurntOrange`.

## Loading and using named colors in the color package

You can also use the `color` package and load named colors via its `usenames` and `dvipsnames` package options:

```latex
\usepackage[usenames,dvipsnames]{color}
```

The following code uses the `color` package to apply the same named colors used in the previous `xcolor` package example.

```latex
\documentclass{article}
\usepackage[usenames,dvipsnames]{color} %using the color package, not xcolor
\begin{document}
This example shows how to use the \texttt{\bfseries color} package
to change the color of \LaTeX{} page elements.

\begin{itemize}
\color{ForestGreen}
\item First item
\item Second item
\end{itemize}

\noindent
{\color{RubineRed} \rule{\linewidth}{0.5mm}}

The background color of text can also be \textcolor{red}{easily} set. For
instance, you can change use an \colorbox{BurntOrange}{orange background} and then continue typing.
\end{document}
```

[Open this `**color**` example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+color+package+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Busenames%2Cdvipsnames%5D%7Bcolor%7D+%25using+the+color+package%2C+not+xcolor%0A%5Cbegin%7Bdocument%7D%0AThis+example+shows+how+to+use+the+%5Ctexttt%7B%5Cbfseries+color%7D+package+%0Ato+change+the+color+of+%5CLaTeX%7B%7D+page+elements.%0A%0A%5Cbegin%7Bitemize%7D%0A%5Ccolor%7BForestGreen%7D%0A%5Citem+First+item%0A%5Citem+Second+item%0A%5Cend%7Bitemize%7D%0A%0A%5Cnoindent%0A%7B%5Ccolor%7BRubineRed%7D+%5Crule%7B%5Clinewidth%7D%7B0.5mm%7D%7D%0A%0AThe+background+color+of+text+can+also+be+%5Ctextcolor%7Bred%7D%7Beasily%7D+set.+For+%0Ainstance%2C+you+can+change+use+an+%5Ccolorbox%7BBurntOrange%7D%7Borange+background%7D+and+then+continue+typing.%0A%5Cend%7Bdocument%7D)

This example produces the same output as the previous `xcolor` version:

![Demonstration of the color package](/files/d5C8DpIt99YPhWE5OmsX)

## Drivers and color

Use of color when typesetting text or math was not part of the original design of TeX; instead, use/application of color was delegated to external “drivers” which converted TeX’s original output file format (DVI) into PostScript or PDF. In order for color to work, driver-specific instructions had to be “injected” into TeX’s output by using a built-in TeX command called `\special` whose job is simply to allow code/data to pass through the typesetting process and become embedded into the output file. When the chosen driver (software) processed the typeset output it would detect the embedded code/data and act upon it to achieve whatever the user intended—such as the use of color.

Times have changed, and PDF is now by far the most common output format used by TeX engines, long supplanting the use of legacy DVI drivers and creation of PostScript. Users also have a greater choice of TeX engine to use for typesetting their LaTeX documents, most notably pdfTeX, XeTeX or LuaTeX/LuaHBTeX, so it is still important to take account of differences in those TeX engines—ensuring the correct mechanisms are used to insert color data (PDF instructions) into their PDF files. To support and accommodate the legacy DVI output format and the wider environment of TeX engines and workflows in use, you can, if required, configure the `color` or `xcolor` packages to use a particular “driver” so that LaTeX will generate color data using using the appropriate method.

### Drivers for color and xcolor

The `color` package provides out-of-the-box support for the following driver options:

* `dvipdfmx`, `dvips`, `dvisvgm`, `luatex`, `pdftex` and `xetex`

There are other options as described in the [`color` package documentation](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/required/graphics/grfguide.pdf).

The `xcolor` package provides the following driver options:

* `dvips`, `xdvi`, `dvipdf`, `dvipdfm`, `dvipdfmx`, `luatex`, `pdftex`, `dvipsone`, `dviwindo`, `emtex`, `dviwin`, `oztex`, `textures`, `pctexps`, `pctexwin`, `pctexhp`, `pctex32`, `truetex`, `tcidvi`, `vtex` and `xetex`.

### Automatic color driver detection

When typesetting your document LaTeX reads a configuration file called `color.cfg` which contains code that can determine if you are running pdfTeX, XeTeX or LuaTeX and automatically loads the appropriate driver (`.def` file) for you, so you don’t *need* to specify the driver package option for those engines.

### More advanced example using the dvisvgm driver to create an SVG file

The following example uses the `color` package with options that load named colors and the `dvisvgm` driver to output color definitions/data using SVG code:

```latex
\usepackage[dvisvgm, usenames, dvipsnames]{color}
```

Specifically, the output file typeset by Overleaf is converted to SVG using a program called [`dvisvgm`](https://dvisvgm.de/), which is part of TeX Live and available on our servers. To run `dvisvgm`, after the page is typeset, we use a [`latexmkrc` file](/latex/in-depth-articles/28-how-to-use-latexmkrc-with-overleaf.md) which is created when you open the following code in Overleaf:

```latex
\documentclass{article}
\usepackage[dvisvgm, usenames, dvipsnames]{color}
\title{Creating SVG graphics}
\author{Overleaf}
\begin{document}
\maketitle
Hello, {\color{Apricot}in Apricot} and now in {\color{DarkOrchid} DarkOrchid} but perhaps it might look nicer if we use {\color{JungleGreen}JungleGreen}---or may not?
\end{document}
```

[Open this example to create an SVG file](https://www.overleaf.com/docs?engine=latex_dvipdf\&snip_name\[]=main.tex\&snip\[]=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bdvisvgm%2C+usenames%2C+dvipsnames%5D%7Bcolor%7D%0A%5Ctitle%7BCreating+SVG+graphics%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0AHello%2C+%7B%5Ccolor%7BApricot%7Din+Apricot%7D+and+now+in+%7B%5Ccolor%7BDarkOrchid%7D+DarkOrchid%7D+but+perhaps+it+might+look+nicer+if+we+use+%7B%5Ccolor%7BJungleGreen%7DJungleGreen%7D---or+may+not%3F%0A%5Cend%7Bdocument%7D\&snip_name\[]=latexmkrc\&snip\[]=END+%7B%0Asystem%28%22dvisvgm+-n+-o+mygraphic.svg+.%2Foutput.dvi%22%29%0A%7D\&main_document=main.tex)

Once Overleaf has finished compiling you can access the SVG graphic, called `mygraphic.svg`, by selecting `Logs and outputs` and choosing the `Other logs and files` dropdown list:

![Accessing a generated file on Overleaf](/files/PxeulmtN4rO2bXHwz2aE)

## Creating your own colors

It is possible to define your own colors, the manner in which the color is defined depends on the preferred color model. The following example uses 4 color models.

```latex
\documentclass{article}
\usepackage[dvipsnames]{xcolor}

\definecolor{mypink1}{rgb}{0.858, 0.188, 0.478}
\definecolor{mypink2}{RGB}{219, 48, 122}
\definecolor{mypink3}{cmyk}{0, 0.7808, 0.4429, 0.1412}
\definecolor{mygray}{gray}{0.6}

\begin{document}
User-defined colors with different color models:

\begin{enumerate}
\item \textcolor{mypink1}{Pink with rgb}
\item \textcolor{mypink2}{Pink with RGB}
\item \textcolor{mypink3}{Pink with cmyk}
\item \textcolor{mygray}{Gray with gray}
\end{enumerate}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+user-defined+colours\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bdvipsnames%5D%7Bxcolor%7D%0A%0A%5Cdefinecolor%7Bmypink1%7D%7Brgb%7D%7B0.858%2C+0.188%2C+0.478%7D%0A%5Cdefinecolor%7Bmypink2%7D%7BRGB%7D%7B219%2C+48%2C+122%7D%0A%5Cdefinecolor%7Bmypink3%7D%7Bcmyk%7D%7B0%2C+0.7808%2C+0.4429%2C+0.1412%7D%0A%5Cdefinecolor%7Bmygray%7D%7Bgray%7D%7B0.6%7D%0A%0A%5Cbegin%7Bdocument%7D%0AUser-defined+colors+with+different+color+models%3A%0A%0A%5Cbegin%7Benumerate%7D%0A%5Citem+%5Ctextcolor%7Bmypink1%7D%7BPink+with+rgb%7D%0A%5Citem+%5Ctextcolor%7Bmypink2%7D%7BPink+with+RGB%7D%0A%5Citem+%5Ctextcolor%7Bmypink3%7D%7BPink+with+cmyk%7D%0A%5Citem+%5Ctextcolor%7Bmygray%7D%7BGray+with+gray%7D%0A%5Cend%7Benumerate%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![LaTeX example creating user-defined colours](/files/IUfbgSUVHBmPninXeQUZ)

The command `\definecolor` takes three parameters: the name of the new color, the model, and the color definition. Roughly speaking, each number represent how much of each color you add to the mix that makes up the final color.

* `**rgb**`: Red, Green, Blue. Three comma-separated values between 0 and 1 define the components of the color.
* `**RGB**`: The same as `rgb`, but the numbers are integers between 0 and 255.
* `**cmyk**`: Cyan, Magenta, Yellow and blacK. Comma-separated list of four numbers between 0 and 1 that determine the color according to the [subtractive CMYK model](https://en.wikipedia.org/wiki/CMYK_color_model) used by commercial printers.
* `**gray**`: Grey scale. A single number between 0 and 1.

In the example, `mypink1`, `mypink2` and `mypink3` define the same color but for different models. You can actually see that the one defined by `cmyk` is slightly different.

Colors defined by either model can later be used within your document not only to set the color of the text, but for any other element that takes a color as parameter, for instance [tables](/latex/figures-and-tables/01-tables.md#colouring-a-table-28cells2c-rows2c-columns-and-lines29) (you must add the `table` option to `xcolor`), [graphic elements created with TikZ](/latex/figures-and-tables/05-tikz-package.md), [plots](/latex/field-specific/08-pgfplots-package.md), [vertical rulers in multicolumn documents](/latex/formatting/09-multiple-columns.md#inserting-vertical-rulers) and [code listings](/latex/formatting/11-code-listing.md#code-styles-and-colours).

### xcolor-only color models

The `xcolor` package provides additional commands which provide support for more color models and friendly color mixing, as demonstrated in the following example:

```latex
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\colorlet{LightRubineRed}{RubineRed!70}
\colorlet{Mycolor1}{green!10!orange}
\definecolor{Mycolor2}{HTML}{00F9DE}
\begin{document}
This document presents several examples showing how to use the \texttt{xcolor} package
to change the color of \LaTeX{} page elements.

\begin{itemize}
\item \textcolor{Mycolor1}{First item}
\item \textcolor{Mycolor2}{Second item}
\end{itemize}

\noindent
{\color{LightRubineRed} \rule{\linewidth}{1mm}}

\noindent
{\color{RubineRed} \rule{\linewidth}{1mm}}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Custom+colours+with+xcolor\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bdvipsnames%5D%7Bxcolor%7D%0A%5Ccolorlet%7BLightRubineRed%7D%7BRubineRed%2170%7D%0A%5Ccolorlet%7BMycolor1%7D%7Bgreen%2110%21orange%7D%0A%5Cdefinecolor%7BMycolor2%7D%7BHTML%7D%7B00F9DE%7D%0A%5Cbegin%7Bdocument%7D%0AThis+document+presents+several+examples+showing+how+to+use+the+%5Ctexttt%7Bxcolor%7D+package+%0Ato+change+the+color+of+%5CLaTeX%7B%7D+page+elements.%0A%0A%5Cbegin%7Bitemize%7D%0A%5Citem+%5Ctextcolor%7BMycolor1%7D%7BFirst+item%7D%0A%5Citem+%5Ctextcolor%7BMycolor2%7D%7BSecond+item%7D%0A%5Cend%7Bitemize%7D%0A%0A%5Cnoindent%0A%7B%5Ccolor%7BLightRubineRed%7D+%5Crule%7B%5Clinewidth%7D%7B1mm%7D%7D%0A%0A%5Cnoindent%0A%7B%5Ccolor%7BRubineRed%7D+%5Crule%7B%5Clinewidth%7D%7B1mm%7D%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Custom colours produced by the xcolor package](/files/lW727XlvXTVtWj7eZnvU)

Three new colors are defined in this example, each one in a different manner.

* `\colorlet{LightRubineRed}{RubineRed!70}`: A new color named `LightRubineRed` is created, this color has 70% the intensity of the original `RubineRed` color. You can think of it as a mixture of 70% RubineRed and 30% white. Defining colors like this lets you derive different tints of a main color—common practice in corporate branding. In the example, you can see the original `RubineRed` and the new `LightRubineRed` used in two consecutive horizontal rules.
* `\colorlet{Mycolor1}{green!10!orange}`: A color named `Mycolor1` is created with 10% green and 90% orange.
* `\definecolor{Mycolor2}{HTML}{00F9DE}`: The color `Mycolor2` is created using the `HTML` model. colors in this model must be created with 6 hexadecimal digits, the characters A, B,C, D, E and F must be in upper-case.

The color models that only `xcolor` supports are:

* `cmy`: cyan, magenta, yellow
* `hsb`: hue, saturation, brightness
* `HTML`: RRGGBB
* `Gray`: Grayscale, a number between 1 and 15.
* `wave`: Wavelength, a number between 363 and 814. The number represents the wavelength of light, in nanometres (nm)

## Setting the page background color

The background color of the entire page can be easily changed with `\pagecolor`. The following code demonstrates this, using the text of an earlier example::

```latex
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\colorlet{LightRubineRed}{RubineRed!70}
\colorlet{Mycolor1}{green!10!orange}
\definecolor{Mycolor2}{HTML}{00F9DE}
\begin{document}
\pagecolor{black}
\color{white}% set the default colour to white
This document presents several examples showing how to use the \texttt{xcolor} package
to change the color of \LaTeX{} page elements.

\begin{itemize}
\item \textcolor{Mycolor1}{First item}
\item \textcolor{Mycolor2}{Second item}
\end{itemize}

\noindent
{\color{LightRubineRed} \rule{\linewidth}{1mm}}

\noindent
{\color{RubineRed} \rule{\linewidth}{1mm}}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Custom+colors+with+xcolor\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bdvipsnames%5D%7Bxcolor%7D%0A%5Ccolorlet%7BLightRubineRed%7D%7BRubineRed%2170%7D%0A%5Ccolorlet%7BMycolor1%7D%7Bgreen%2110%21orange%7D%0A%5Cdefinecolor%7BMycolor2%7D%7BHTML%7D%7B00F9DE%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cpagecolor%7Bblack%7D%0A%5Ccolor%7Bwhite%7D%25+set+the+default+colour+to+white%0AThis+document+presents+several+examples+showing+how+to+use+the+%5Ctexttt%7Bxcolor%7D+package+%0Ato+change+the+color+of+%5CLaTeX%7B%7D+page+elements.%0A%0A%5Cbegin%7Bitemize%7D%0A%5Citem+%5Ctextcolor%7BMycolor1%7D%7BFirst+item%7D%0A%5Citem+%5Ctextcolor%7BMycolor2%7D%7BSecond+item%7D%0A%5Cend%7Bitemize%7D%0A%0A%5Cnoindent%0A%7B%5Ccolor%7BLightRubineRed%7D+%5Crule%7B%5Clinewidth%7D%7B1mm%7D%7D%0A%0A%5Cnoindent%0A%7B%5Ccolor%7BRubineRed%7D+%5Crule%7B%5Clinewidth%7D%7B1mm%7D%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Setting the page background color in LaTex](/files/MuBcQBFpDDW5xtnLj11K)

The command `\pagecolor{black}` set the page color to `black`. This is a switch command, meaning it will take effect in the entire document unless another switch command is used to revert it. `\nopagecolor` will change the background back to normal.

## Additional color packages for LuaLaTeX

In addition to the standard `color` and `xcolor` packages, LuaLaTeX supports the [`luacolor`](https://ctan.org/pkg/luacolor?lang=en) and [`lua-ul`](https://ctan.org/pkg/lua-ul?lang=en) packages—both are written specifically for use with LuaLaTeX and neither is compatible with pdfLaTeX or XeLaTeX.

### The luacolor package

The `luacolor` package redefines some internals of the standard `color` package commands using techniques unique to LuaTeX-based TeX engines.

Although `luacolor` automatically incorporates the `color` package, if you want to do either of the following:

* use specific options of the `color` package, such as `\usepackage[usenames,dvipsnames]{color}`, or
* use the `xcolor` package

you need to load the `color` or `xcolor` package prior to `luacolor`. For example, you can load the `color` package using:

```latex
\usepackage[usenames,dvipsnames]{color} % example color package options, see the documentation
\usepackage{luacolor} % loaded after the color package
```

or load the `xcolor` package with:

```latex
\usepackage[dvipsnames]{xcolor} % example xcolor package option, see the documentation
\usepackage{luacolor} % loaded after the xcolor package
```

Consult the documentation of [`color`](http://mirrors.ctan.org/macros/latex/required/graphics/grfguide.pdf) and [`xcolor`](http://mirrors.ctan.org/macros/latex/contrib/xcolor/xcolor.pdf) for details of package options.

By leveraging the capabilities of LuaLaTeX, `luacolor` enables more advanced applications of color; for example, colorizing individual glyphs within complex script languages or applying color to diacritical marks. `luacolor` also avoids kerning issues when applying color to single characters—see tex.stackexchange questions [here](https://tex.stackexchange.com/questions/622544/kerning-when-coloring-single-letters) and [here](https://tex.stackexchange.com/questions/567220/kerning-with-xcolor) for examples of that.

### The lua-ul package

This package is mentioned because it has color highlighting features. It applies the advanced capabilities of LuaTeX to provide underlining, strikethough, and highlighting using methods in which kerning is not affected, underlined text can use arbitrary commands, hyphenation works and ligatures are preserved.

### Example: luacolor

Here, we'll demonstrate using `luacolor` to colorize text typeset in Hindi and Arabic together with diacritics used on a Latin script (based on [this example](https://tex.stackexchange.com/questions/698933/color-breaks-diacritics-stacking)). The following example uses the [babel package](/latex/languages/02-multilingual-typesetting-on-overleaf-using-babel-and-fontspec.md) to configure LuaLaTeX to typeset Hindi and Arabic using fonts present on Overleaf.

```latex
\documentclass{article}

% Prefer a small page width for the demo
\usepackage[paperwidth=15cm]{geometry}

% Use babel with Arabic, Hindi and English languages
% English is loaded last, making it the default language
\usepackage[hindi,english]{babel}
\babelprovide[import=ar]{arabic}
% Set Roman font for Arabic
\babelfont[arabic]{rm}{Scheherazade}

% Set Roman and sans serif fonts for English
\babelfont{rm}{Noto Serif}
\babelfont{sf}{Noto Sans}

% Set up Roman and san serif fonts for Hindi
\babelfont[hindi]{rm}[Language=Default]{Noto Serif Devanagari}
\babelfont[hindi]{sf}[Language=Default]{Noto Sans Devanagari}

% Because we want to use the "dvipsnames" option to
% access additional named colors, we must load xcolor
% before luacolor (see the luacolor package documentation)
\usepackage[dvipsnames]{xcolor}
\usepackage{luacolor}

% Create a convenience command to typeset Hindi
\newcommand\hinditext[1]{\foreignlanguage{hindi}{#1}}

% Create a convenience command to typeset Arabic
\newcommand\arabictext[1]{\foreignlanguage{arabic}{#1}}

\usepackage{hyperref}
\hypersetup{
colorlinks=true,
urlcolor=cyan
}
\begin{document}
% The Noto fonts benefit from a larger line spacing
\setlength{\baselineskip}{14bp}

\section{Colorizing Hindi text}
Google translates the Hindi word \textsf{\hinditext{किंकर्तव्यविमूढ़}} as
``bewildered''. By using the \texttt{luacolor} package it's possible to colorize glyphs within Hindi text; for example \hinditext{किंक\textcolor{purple}{र्तव्यव}\textcolor{green}{िमूढ़}}. You can also add color to the whole word: \hinditext{\textcolor{blue}{किंकर्तव्यविमूढ़}}.

\section{Colorizing Arabic text}
% Create a custom environment to
% typeset colored Arabic text
\newenvironment{colorarabic}
{% Typeset Arabic using a larger font
\fontsize{30}{30}
% Set right-to-left paragraph and text directions
\pardir TRT\textdir TRT}
{}

Here is some colorized Arabic text:  \begin{colorarabic}
\textcolor{red}{\arabictext{هَذَا}} \arabictext{نَصٌّ عَرَب}\textcolor{green}{\arabictext{ِ}}\arabictext{ي}\textcolor{blue}{\arabictext{ٌّ}}
\end{colorarabic}
\section{Colorizing diacritics}
This example is based on \href{https://tex.stackexchange.com/questions/698933/color-breaks-diacritics-stacking}{code from tex.stackexchange}.

\vspace{12pt}
\bgroup
\newcommand{\emptydiacritic}{\char"034F}
\fontsize{60}{60}\selectfont
á̀̐{\color{blue}a\emptydiacritic\color{green}́\color{red}̀\color{magenta}̐
\egroup
\end{document}
```

[Open this luacolor example in Overleaf.](/latex/formatting/13-using-colors-in-latex.md)

This example produces the following output:

![sample output using the luacolor package](/files/2Z3TqeJdzdyCZFlXrxAB)

### Example: lua-ul

This example demonstrates the following `lua-ul` package commands:

* `\highLight[*color*]{*text to highlight*}` which applies the (optional) `*color*` to `*text to highlight*`. Note the capital **`L`** in the spelling of `\high**L**ight` command!
* `\LuaULSetHighLightColor{*default color*}`: this sets the `*default color*` used by the `\highLight` command when the optional `[*color*]` is not specified.

Note: the `luacolor` package must also be loaded when using the `\highLight` command provided by the `lua-ul` package.

```latex
\documentclass{article}
% Prefer a small page width for the demo
\usepackage[paperwidth=12cm]{geometry}

\usepackage[dvipsnames]{xcolor} % To access some named colors used with \highLight
\usepackage{luacolor} % Required to use the lua-ul \highLight command
\usepackage{lua-ul}

\usepackage{blindtext}
\begin{document}
% Use the Apricot color to highlight the text
\highLight[Apricot]{\blindtext}

% Use \LuaULSetHighLightColor to set default colors for
% the \highLight command
\begin{itemize}
    \item \LuaULSetHighLightColor{CornflowerBlue} \highLight{\blindtext[1]}.
    \item \LuaULSetHighLightColor{Goldenrod}\highLight{{\(y=f(x)\)}}
\end{itemize}
\end{document}
```

[Open this `lua-ul` example in Overleaf.](https://www.overleaf.com/docs?engine=lualatex\&snip_name=lua-ul+package+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Prefer+a+small+page+width+for+the+demo%0A%5Cusepackage%5Bpaperwidth%3D12cm%5D%7Bgeometry%7D%0A++%0A%5Cusepackage%5Bdvipsnames%5D%7Bxcolor%7D+%25+To+access+some+named+colors+used+with+%5ChighLight%0A%5Cusepackage%7Bluacolor%7D+%25+Required+to+use+the+lua-ul+%5ChighLight+command+%0A%5Cusepackage%7Blua-ul%7D+%0A++%0A%5Cusepackage%7Bblindtext%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Use+the+Apricot+color+to+highlight+the+text++%0A%5ChighLight%5BApricot%5D%7B%5Cblindtext%7D+%0A%0A%25+Use+%5CLuaULSetHighLightColor+to+set+default+colors+for+%0A%25+the+%5ChighLight+command%0A%5Cbegin%7Bitemize%7D%0A++++%5Citem+%5CLuaULSetHighLightColor%7BCornflowerBlue%7D+%5ChighLight%7B%5Cblindtext%5B1%5D%7D.%0A++++%5Citem+%5CLuaULSetHighLightColor%7BGoldenrod%7D%5ChighLight%7B%7B%5C%28y%3Df%28x%29%5C%29%7D%7D%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Highlighting text with the lua-ul package](/files/7lO870LKjXoh8TYMzWSN)

## Further reading

For more information see:

* [The **color** package documentation](http://mirrors.ctan.org/macros/latex/required/graphics/grfguide.pdf) (or [access via `texdoc.org`](https://texdoc.org/serve/color/5))
* [The **xcolor** package documentation](http://mirrors.ctan.org/macros/latex/contrib/xcolor/xcolor.pdf) (or [access via `texdoc.org`](https://texdoc.org/serve/xcolor/0))
* [Lengths in LaTeX](/latex/formatting/01-lengths-in-latex.md)
* [Font sizes, families, and styles](/latex/fonts/01-font-sizes-families-and-styles.md)
* [Font typefaces](/latex/fonts/02-font-typefaces.md)
* [Supporting modern fonts with XeLaTeX](/latex/fonts/03-xelatex.md)
* [Tables](/latex/figures-and-tables/01-tables.md)
* [Inserting Images](/latex/more-topics/27-inserting-images.md)
* [Beamer](/latex/presentations/01-beamer.md)
* [Powerdot](/latex/presentations/02-powerdot.md)
* [Posters](/latex/presentations/03-posters.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/formatting/13-using-colors-in-latex.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
