How to highlight text in LaTeX

In this tutorial, I will show you how to highlight text in LaTeX.

I am going to keep this tutorial as simple as possible.

If you think that changing colors can be considered as highlighting, then I recommend you to read this once:

Highlight text in LaTeX using \hl command

We can highlight any text using soul package and \hl command.

See the below example:

\documentclass{article}
\usepackage{soul}
\begin{document}
I love reading LaTeX tutorials on \hl{Codespeedy.}
\end{document}

\hl command in latex

This only underlines the text.

Let’s make it better.

Using xcolor package with \hl

\documentclass{article}
\usepackage{soul}
\usepackage{xcolor}

\begin{document}

This is \hl{highlighted text} with default highlighting color.

\end{document}

Output:

latex highlight text

Change the highlight color in LaTeX – Soul package with \hl command

Using the below code, you can change the highlight color using soul and xcolor package.

\documentclass{article}
\usepackage{soul}
\usepackage{xcolor}

\DeclareRobustCommand{\hlgreen}[1]{{\sethlcolor{green}\hl{#1}}}

\begin{document}
This is a \hlgreen{highlighted words with green} in LaTeX.
\end{document}

Output:

highlight text in latex with color change

Highlight text using \colorbox

\colorbox{colorname}{highlighted text} – We can use this command to set the highlight color for the text in our LaTeX document.

\documentclass{article}
\usepackage{xcolor}

\begin{document}

This is \colorbox{red}{highlighted red text} in LaTeX.

\end{document}

Output:

highlight color with colorbox latex

Leave a Reply

Your email address will not be published. Required fields are marked *