The macro ul provided by soul works great, allowing linebreaks within an underlined text block. It even supports macros - if they were registered with soulregister.

But if these registered macros produce text on their own, it isn't underlined:



\newcommand{\two}[1]{not underlined #1}


test1 \one{test2 \two{test3}}.

"not underlined" isn't underlined

How can I make sure this text is underlined correctly?

  • 3
    It's not math-mode that's causing the problems. Replace your math content with any text, you'll still have the same effect.
    – A.Ellett
    Jul 31 '13 at 16:42
  • Oops - I thought I had checked that, thanks for pointing that out. I'll edit my question.
    – fefrei
    Jul 31 '13 at 16:46
  • 2
    Can someone enlighten me please - if you're just underlining, why use soul and not ulem?
    – Chris H
    Jul 31 '13 at 18:07
  • @ChrisH: Because I didn't think of it. ulem seems to handle this perfectly - thanks!
    – fefrei
    Jul 31 '13 at 18:16
  • 1
    @ChrisH: Hopefully we will both get some enlightenment once there are answers to List of Underlining Packages - Pros and Cons. Aug 1 '13 at 1:47

For registered commands, soul will split up the string, turning it basically into

\ul{first part}\command{\ul{second part}}

So if \command produces any text, this will end up outside of the scope of soul's scanner. To solve this you can pre-expand the string before feeding it to soul:


EDIT: Another possibility would be to register your \two command with identifier 7 instead of 1, as explained in this answer.


If you aren't tied into soul for some other reason, then a modified \xblackout of the censor package might suffice for this task.

EDITED to fix problem with line breaking.

\newcommand{\two}[1]{not underlined #1}
test1 \one{test2 \two{test3}}.
test1 \one{test2 \two{test3}}.
test1 \one{test2 \two{test3}}.
test1 \one{test2 \two{test3}}.
test1 \one{test2 \two{test3}}.
test1 \one{test2 \two{test3}}.
test1 \one{test2 \two{test3}}.
test1 \one{test2 \two{test3}}.
test1 \one{test2 \two{test3}}.

enter image description here

  • That's a quite interesting use of censor. However, it does seem to have problems with line breaking: Sometimes, a word breaks to a new line, but the underline stays in the previous line.
    – fefrei
    Jul 31 '13 at 17:59
  • @fefrei Hmm. I can now see how that would happen, if the breaking phrase were part of the embedded macro. Noting that significant deficiency, shall I remove the answer? Jul 31 '13 at 18:07
  • Of course, that's up to you - but still, the answer may be useful in some circumstances.
    – fefrei
    Jul 31 '13 at 18:12
  • @fefrei Fixed the censor approach to work with line breaks (also using a \protected@edef). Jul 31 '13 at 18:49
  • @fefrei If interested, see tex.stackexchange.com/questions/126291/… for an improved version of this approach, which leaves a gap around descenders, and does math underlining, too. Aug 1 '13 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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