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 have text that I need to repeat quite a few times:

\newcommand{\repeatme}{text to repeat that is somewhat long and verbose}

I'd like to underline this text and have it not cause hbox overflow errors. Thus I try (using the soul package, as if I use ulem or underline it'll hbox):

Blah blah blah, \ul{\repeatme}

This gives this error:

I came across hyphenatable material enclosed in group braces,
which I can't handle. Either drop the braces or make the material
unbreakable using an \mbox (\hbox). Note that a space
also counts as possible hyphenation point. See page 4 of the manual.

My current workaround is this:

\newcommand{\repeatmeul}{\ul{text to repeat that is somewhat long and verbose}}

and

Blah blah blah, \repeatmeul

But that fails... wrong. Surely there's a more elegant way!

share|improve this question
add comment

2 Answers

Hope the MWE explains every thing.

\documentclass{article}
\usepackage[normalem]{ulem}
\usepackage{soul}
%----------------------------------------------------
\newcommand*{\repeatme}{text to repeat that 
is somewhat long and verbose} %<----without underline
%----------------------------------------------------
\newcommand{\repeatmeul}{\uline{text to repeat that 
is somewhat long and verbose}} % ,---using ulem
%----------------------------------------------------
\newcommand{\repeatmeulsoul}{\ul{text to repeat that 
is somewhat long and verbose}} %<--- using soul
%----------------------------------------------------
\begin{document}
This is going to be a small task for \verb|ulem| -- \repeatmeul. 
And  another example of using \verb|soul| -- 
\repeatmeulsoul. And this is with underline -- \ul\repeatme. Here we used 
\verb|soul| package. And a similar one with \verb|ulem| won't work since the material inside \verb|{}| 
is considered as a box -- that won't break.
\end{document} 

This code works with the following output.

enter image description here

Conclusion: Use \ul\repeatme or \repeatmeulsoul using soul package. Or use \repeatmeul using ulem package. Do not use \uline\repeatme from ulem, it won't work.

PS: If this MWE doen't work for you, you should consider updating your packages.

share|improve this answer
add comment

The following surely works (with soul)

\expandafter\ul\expandafter{\repeatme}

It's always a pain to get things expanded inside \ul or similar commands. On the other hand, underlining is frowned upon in typographic circles.

With \expandafter\ul\expandafter{\repeatme}, the macro \ul is presented the expansion of \repeatme rather than the macro itself, so that this is equivalent to writing

\ul{text to repeat that is somewhat long and verbose}

but shorter.

share|improve this answer
    
Unfortunately I'm required to use underlines. What's the difference between \ul{\repeatme} and \ul\repeatme and \expandafter\ul\expandafter{\repeatme}? What's actually going on, in other words? –  alcaras Mar 26 '12 at 17:29
add comment

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.