The soul package
Underlines, strikes out, highlights and letterspaces text that still breaks across lines: \ul, \st, \hl, \so and \caps.
Loading the package
\usepackage{soul}\underline puts its text in a box that cannot break, so a long underlined passage runs into the margin. The commands of soul work syllable by syllable: the text breaks at the end of a line and is hyphenated like normal text.
\hl highlights with a coloured background and needs xcolor or color. Without a colour package it underlines the text instead.
Main commands
\ul{text} | Underlines. |
\st{text} | Strikes out. |
\hl{text} | Highlights with a yellow background. |
\sethlcolor{green} | Colour of the highlighting; \setulcolor and \setstcolor set the colour of the lines. |
\so{text} | Letterspaces the text. |
\caps{Text} | Letterspaced small capitals. |
\setul{0.4ex}{0.2ex} | Depth and thickness of the underline. |
Complete example
\documentclass{article}
\usepackage{xcolor}
\usepackage{soul}
\begin{document}
\ul{Underlined text}, \st{struck-out text} and \hl{highlighted text}.
\sethlcolor{green}
\hl{A highlighted passage that is long enough to reach the end of the
line continues on the next line, and words are hyphenated as usual.}
\so{Letterspaced text} and \caps{Small Capitals}.
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
\citeand\refinside\hl,\ulor\ststop with errors such as Argument of \align has an extra }. Wrap them in\mbox{...}, or register them once in the preamble with\soulregister\cite7and\soulregister\ref7.- Font commands such as
\textbf{...}and inline math$...$work inside the argument. - Versions from 2023 on accept umlauts and other UTF-8 characters with pdfLaTeX. Older versions need the package
soulutf8for that.
Related pages
- How-to Highlight text in LaTeX
- How-to Strikethrough text in LaTeX
- How-to Bold, italic and underlined text in LaTeX
- Package
ulem - Package
xcolor