Skip to main content
v2026.11,986 entries · CC-BY 4.0

Highlight in LaTeX: soul hl, Colors and Limits

How to highlight text in LaTeX with soul hl and sethlcolor, why it falls back to underlining, math rules and alternatives.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

To highlight text in LaTeX, load the soul package with \usepackage{color,soul} and wrap the text in \hl{...}. The highlight is yellow by default, and \sethlcolor{...} changes it. This page covers the soul commands, the colour setup, the rules that make soul fail, and the alternatives \colorbox and lua-ul \highLight. Sources were read on 2026-11-12.

What highlighting is used for in research documents

Researchers highlight text in LaTeX to mark passages for co-authors, to flag changes between manuscript drafts, or to draw attention to a result in lecture notes and theses. LaTeX has no single built-in highlight command. The usual answer is the soul package, whose documentation lists five text-marking commands: \so (letterspacing), \caps, \ul (underlining), \st (overstriking) and \hl (highlighting). The soul README describes the package as hyphenable letterspacing, underlining and striking out, and the highlight command comes from the same mechanism.

Highlighting is a working-copy tool. Remove or neutralise it before final submission unless the journal’s author instructions say otherwise. For crossing text out rather than highlighting it, see the CASRAI guide to crossing out text in LaTeX, which covers the same package family.

How to install or access it

The soul package is published on CTAN, the Comprehensive TeX Archive Network, under macros/latex/contrib/soul. Its README gives the version as 2026-03-06 v3.2 and the licence as the LaTeX Project Public License 1.3c. Issues are tracked at github.com/ho-tex/soul/issues. Version 3.2 is described as a merge of the original soul package by Melchior Franz and the soulutf8 package by Heiko Oberdiek, with UTF-8 support. The soul documentation states that soulutf8 is obsolete and that you should use the soul package directly.

In your document you load it in the preamble. Two details come from the manual and are easy to miss:

  • The soul package has no options of its own and defines no new user commands beyond those above. Options are passed to soul-ori, which is loaded first.
  • The \hl command only highlights if the colour package was loaded. Otherwise it falls back to underlining. If your highlight shows up as an underline, a missing colour package is the first thing to check.

Step-by-step: highlight text with hl

Highlight text in LaTeX (soul \hl)

  1. Load the packages in the preamble: \usepackage{color,soul}. The soul manual’s own example loads color and soul together.
  2. Wrap the text to highlight: \hl{this text is highlighted}.
  3. Compile as usual. With no colour set, the highlight is yellow, which is the documented default of \sethlcolor.
\documentclass{article}
\usepackage{color,soul}
\begin{document}
The samples were \hl{stored at -80 degrees until analysis}.
\end{document}

LaTeX highlight color

Set the highlight colour with \sethlcolor{colour} before the text it should apply to. The manual’s official example defines a custom light blue and uses it:

\usepackage{color,soul}
\definecolor{lightblue}{rgb}{.90,.95,1}
\sethlcolor{lightblue}
...
\hl{this is highlighted in light blue color}

The same family has matching setters for the other two marking commands: \setulcolor for underlining and \setstcolor for overstriking. For these two, calling the setter with empty braces turns colouring off, as in \setulcolor{}. Underline and overstrike default to black. The data table below the article compares the three commands and their setters. Overleaf’s colour documentation lists the named-colour sets that the xcolor package provides (68 for dvipsnames, 151 for svgnames, 317 for x11names), which is where names such as BurntOrange come from. For general text and page colour, see the CASRAI guide to text colour in LaTeX.

Highlight in math

Inline math inside soul commands works only when it is surrounded by dollar signs, as in \hl{the value of $x$ was}. The manual states that the LaTeX equivalent \(...\) does not work. Other soul rules from the manual that matter in practice:

  • Braces {} make a group one unit, but the group must not contain hyphenation points.
  • \mbox{} protects its contents and may contain hyphenation points.
  • \soulomit{} typesets its contents as is.
  • Standard font-switch commands such as \texttt are allowed. Other commands must be registered with \soulregister{\cs}{0}.
  • Ligatures can be broken with {} or \null inside \ul, \st and \hl, for example \ul{Auf{}lage}.
  • A newline \\, \linebreak and the unbreakable space ~ are allowed.

Highlight with colorbox

The xcolor command \colorbox{BurntOrange}{orange background} changes the background colour of the text passed as its second argument, according to Overleaf’s documentation. Load xcolor with a colour-name option, for example \usepackage[dvipsnames]{xcolor}. Note the argument order: the colour comes first and the text second. Because soul works syllable by syllable using TeX hyphenation to find break points, it is the package designed for highlighting text that runs across lines. A box is the more direct choice for short labels.

Combining the soul commands and UTF-8 text

The soul documentation says the package supports UTF-8 input through both inputenc (utf8) and ucs (utf8x), which is why the separate soulutf8 package is no longer needed. In a document that marks revisions, a common pattern is to give each command its own purpose and colour, using only the setters described above:

\usepackage{color,soul}
\sethlcolor{yellow}
\setstcolor{red}
...
\hl{new wording}, \st{old wording}

Here the highlight marks the new wording and the strike-out, in red, marks the removed wording. Because the manual lists each command as a separate effect, nothing in the sources suggests they must be nested; keep the arguments short and apply the rules in the previous section if an error appears.

Output and how to read it

In the PDF, the highlighted words appear with a coloured background behind them. The text itself keeps its normal colour. If the words appear underlined and not coloured, the colour package was not loaded, which is the documented fallback. If the background is yellow when you expected another colour, the \sethlcolor call is missing or sits after the text it should affect. The soul commands are also listed in the manual with default colours: yellow for highlighting, black for underline and overstrike.

Troubleshooting

The soul documentation says the package gives few readable messages of its own and that most errors come from TeX itself, such as Incomplete \ifcat. Its advice is to comment out the soul statement to see whether the error disappears, then check the argument against the rules above.

Symptom Cause stated in the soul manual What to check
Highlight appears as an underline The hl command only highlights if the colour package was loaded; otherwise it falls back to underlining Load color (or xcolor) alongside soul
Error with inline math Math is accepted only when surrounded by $…$; (…) does not work Rewrite the math with dollar signs
Reconstruction failed Hyphenatable material was grouped, or an unregistered command that changes syllable width, such as a font switch, was used Move the group out of the hyphenatable text, or register the command with \soulregister
Incomplete \ifcat or another raw TeX error soul passes through TeX’s own messages Comment out the soul command; if the error vanishes, check the argument against the rules
Broken ligature or odd spacing in the highlighted word Ligatures must be broken manually inside ul, st and hl Insert {} or \null, as in Auf{}lage

Alternatives to soul’s hl

Command Package What it does Requirement stated in the source
\hl{text} soul Highlights text, breaking it across lines by syllable The colour package must be loaded, otherwise it falls back to underlining; licence LPPL 1.3c
\colorbox{colour}{text} xcolor Changes the background colour of the text in the second argument Colour names need an xcolor option such as dvipsnames, svgnames or x11names
\highLight[colour]{text} lua-ul Highlights text in LuaLaTeX Requires luacolor to be loaded; LuaLaTeX only

The lua-ul entry comes from Overleaf’s colour page, which presents \highLight as the highlighting route under LuaLaTeX. For boxed callouts around whole paragraphs, see the CASRAI guides to tcolorbox examples and framed text in LaTeX.

FAQ

How do I highlight text in LaTeX?

Load soul and a colour package with \usepackage{color,soul}, then write \hl{text}. The default highlight colour is yellow.

How do I change the highlight colour?

Use \sethlcolor{colour} before the text, for example \sethlcolor{lightblue} after defining lightblue with \definecolor. The default is yellow.

Why is my hl text underlined and not highlighted?

The soul manual states that hl only highlights if the colour package was loaded; otherwise it falls back to underlining.

Can I highlight math in LaTeX?

Inline math inside soul commands must be surrounded by dollar signs. The (…) form does not work.

Is highlight in LaTeX the same as latex highlight with colorbox?

No. colorbox from xcolor sets a background box around its second argument, while soul’s hl is built to break highlighted text across lines.

Sources (read 2026-11-12)

Data: soul package marking commands and their colour setters

Compares the soul package commands for underlining, overstriking and highlighting with the command that sets each colour and the documented default, compiled from the soul package documentation source (version 2026-03-06 v3.2).

soul package marking commands and their colour setters
CommandEffectColour setterDefault colour
\ulUnderlining\setulcolor{colour}; \setulcolor{} turns colouring offblack
\stOverstriking (strike-out)\setstcolor{colour}; \setstcolor{} turns colouring offblack
\hlHighlighting (falls back to underlining without the colour package)\sethlcolor{colour}yellow

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Highlight in LaTeX: soul hl, Colors and Limits

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →