## LaTeX forum ⇒ Text Formatting ⇒ New Command for bold Text on colored Background

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
rawlins02
Posts: 20
Joined: Tue Oct 07, 2008 6:56 pm

### New Command for bold Text on colored Background

I'm looking to define a command that will facilitate placement of bold text in a yellow background. Here is a start without the bold, that also fails to wrap. I've tried a number of options without much success.
\def\comment{\colorbox{yellow}}{}

Tags:

Johannes_B
Site Moderator
Posts: 3582
Joined: Thu Nov 01, 2012 4:08 pm
In order to help you, we need more information. What is going to happen, if the text is longer than one line, or longer than one paragraph.

Can you supply those info in form of a compilable minimal example?

Have a look at mdframed or todonotes.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

rawlins02
Posts: 20
Joined: Tue Oct 07, 2008 6:56 pm
Johannes_B wrote:In order to help you, we need more information. What is going to happen, if the text is longer than one line, or longer than one paragraph.

Can you supply those info in form of a compilable minimal example?

An example
\documentclass{minimal}\usepackage{color,comment}\begin{document}\def\comment{\colorbox{yellow}}{} In the compiled output text in curly brackets extends beyond the right margin\comment{ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZz} \end{document}

Johannes_B wrote:Have a look at mdframed or todonotes.

I have explored both. Prefer a simple bold text in yellow background that wraps normally

Johannes_B
Site Moderator
Posts: 3582
Joined: Thu Nov 01, 2012 4:08 pm
Well, than have a look at Cool Text Highlighting in LaTeX.

The simplest approach would be soul:
\documentclass{article}\usepackage[width=5.05cm]{geometry}\usepackage{color,soul} \begin{document}\noindent\hl{Highlighting} text feels good.You can draw attention of people to a \hl{word} or perhaps \hl{even a whole sentence that spans across multiple linesin such a way that hyphenation etc. are not affected.}\end{document}
Code taken from Caramdir.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.