How to Highlight Text in LaTeX?

If you’re a student, researcher, or professional in the academic world, you probably need to highlight text in the LaTeX document. Whether you want to emphasize key points, mark revisions, or make your document more visually appealing, knowing how to highlight text in LaTeX is important. In this blog post, we’ll explore how to highlight textual content in LaTeX.

Using the soul package

This is the most straightforward way to highlight text in LaTeX. You import the soul package in your preamble and highlight text using the \hl command. The \hl command only highlights if the color package is loaded; otherwise, it falls back to underlining. The default highlight color is yellow, but you can change it by defining custom colors.

Add the soul package to your LaTeX document preamble:

\usepackage{soul}

Now, you can use the \hl command to highlight text. For example:

\documentclass{article}
\usepackage{soul}
\usepackage{color}

\begin{document}

Welcome to the Electricalvoice.com. This is \hl{highlighted} text.

\end{document}

Output

Note: If color package is not included in the preamble, then the argument in the \hl command is underlined. For example:

\documentclass{article}
\usepackage{soul}

\begin{document}

Welcome to the Electricalvoice.com. This is \hl{highlighted} text.

\end{document}

Output

The colors can be changed using the following command. The argument “color-name” is the color name.

\sethlcolor{color-name}

For example:

\documentclass{article}
\usepackage{soul}
\usepackage{color}
\sethlcolor{blue}

\begin{document}

Welcome to the Electricalvoice.com. This is \hl{highlighted} text.

\end{document}

Output

Note: The color package provides a limited set of predefined colors but allows adding custom color definitions. For example:

\documentclass{article}
\usepackage{soul}
\usepackage{color}
\definecolor{lightblue}{rgb}{.90,.95,1}
\sethlcolor{lightblue}

\begin{document}

Welcome to the Electricalvoice.com. This is \hl{highlighted} text.

\end{document}

Output

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.