Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using soul's \hl to set background for the paragraph parts and ulem's \uline to underline text.

The problem is what I cant underline text for text with background.

Initial doc:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage[normalem]{ulem}
\usepackage{soul}

\newcommand{\bg}[2]{\sethlcolor{#1}\hl{#2}}

\definecolor{ColorFg}{HTML}{FFFFFF}
\definecolor{ColorBg}{HTML}{008000}

\begin{document}

{\color{ColorFg}\bg{ColorBg}{Some Text}} another text.

\end{document}

initial doc

I want to underline Text:

{\color{ColorFg}\bg{ColorBg}{Some \uline{Text}}} another text.

it fails with ! Argument of \UL@on has an extra }.

I tried to use \soulregister{\uline}{1} (solution from this topic) - no errors and no underlined tex.

Is it possible to underline text with background color (maybe I have to use another packages)?

PS soul docs provides solution for nested commands, but it's not useful for me since line breaks will not work.

Thanks.

share|improve this question

1 Answer 1

Simply enclose the \uline{} inside a pair of braces. You do not need any other package.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage[normalem]{ulem}
\usepackage{soul}

\newcommand{\bg}[2]{\sethlcolor{#1}\hl{#2}}

\definecolor{ColorFg}{HTML}{FFFFFF}
\definecolor{ColorBg}{HTML}{008000}

\begin{document}

{\color{ColorFg}\bg{ColorBg}{Some {\uline{Text}}}} another text.

\end{document}

And here is the output,

enter image description here


Question on answer

Could somebody please tell me why the following vanishes "Text"?

{\color{ColorFg}\bg{ColorBg}{Some \protect\uline{Text}}} another text.

enter image description here

share|improve this answer
    
This doesn't work if you have for example {\uline{Text Text}}. In this case you can use \mbox{\uline{Text Text}}. It doesn't work, in any case, if the contents of \uline has to break a line... –  karlkoeller Nov 5 '13 at 17:36
    
Hm, true. @karlkoeller is right. –  skozlovf Nov 5 '13 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.