Text FormattingHighlighting a single word

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
coachbennett1981
Posts: 274
Joined: Fri Feb 05, 2010 10:15 pm

Highlighting a single word

Post by coachbennett1981 »

For the life of me I can't remember/find how to highlight a single word in latex. I can change the color, but I would like to highlight instead.

Please, somebody tell me. I know its cheating, but I need this ;)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Highlighting a single word

Post by gmedina »

Hi,

perhaps the \colorbox command could be useful:

Code: Select all

\documentclass{report}
\usepackage{xcolor}

\begin{document}

text text text \colorbox{red}{text} text text

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Highlighting a single word

Post by localghost »

Define a command with an optional argument for the text color and a mandatory one for the color of the surrounding box.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[svgnames]{xcolor}

\newcommand{\highlight}[3][black]{{\fboxsep0.5pt\colorbox{#2}{\color{#1} #3}}}

\begin{document}
  A sentence with \highlight[white]{blue!50}{some highlighted text} in the middle.

  Another sentence with \highlight{green!50}{highlighted text} in another color for text and box.
\end{document}

Best regards
Thorsten
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Highlighting a single word

Post by gmedina »

localghost wrote:Define a command with an optional argument for the text color and a mandatory one for the color of the surrounding box...

Code: Select all

...
\newcommand{\highlight}[3][black]{{\fboxsep0.5pt\colorbox{#2}{\color{#1} #3}}}
...
Didn't you mean with two mandatory arguments? (the box color and its contents).
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Highlighting a single word

Post by localghost »

gmedina wrote:Didn't you mean with two mandatory arguments? (the box color and its contents).
Of course you are right. Just a matter of false expression. I only referred to the arguments regarding the colors and forgot the argument for the actual contents. Thanks for the hint preventing confusion.
coachbennett1981
Posts: 274
Joined: Fri Feb 05, 2010 10:15 pm

Re: Highlighting a single word

Post by coachbennett1981 »

Curses!! You guys make it to easy... AHHH!!!

thank you :D
Post Reply