The xcolor package provides a macro called \colorbox
, which can be combined with \textcolor
to generate the desired effect.
In the following example, the utility macro \highlight
takes three arguments -- the background color, the foreground color, and the word(s) to be highlighted, while the macro \rev
hard-codes the background and foreground colors (as yellow and red, respectively).
If you load xcolor
with the option svgnames
, you'll have access to a named color called Crimson
, which is slightly darker than red
.
\documentclass{article}
\usepackage{xcolor} % for '\textcolor' and '\colorbox' macros
% Define two utility macros:
\newcommand\highlight[3]{\colorbox{#1}{\textcolor{#2}{#3}}}
\newcommand\rev[1]{\highlight{yellow}{red}{#1}} % hard-coded color choices
\begin{document}
I wish to \colorbox{yellow}{\textcolor{red}{highlight}} a word.
\smallskip
I wish to \highlight{yellow}{red}{highlight} a word.
\smallskip
I wish to \rev{highlight} a word.
\smallskip
I wish to \highlight{yellow}{blue}{\textbf{highlight}} a word.
\end{document}