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.

Some packages (ntheorem for example) take only text switches as arguments that can be used in the form {\switch text}, for example \bfseries. If I now want to have a suitable command for underlining, the \underline command does not work, as it requires the argument explicitly using parentheses.

To make this clearer, I would like to convert something like

\underline{lorem ipsum}

to the form

{\ulswitch lorem ipsum}
share|improve this question
2  
The latex-project tag is really just about the develop project of LaTeX. You don't need to tag a question for LaTeX, that's the default here. –  Martin Scharrer Dec 19 '11 at 22:23
    
AFAIK, you should not use \underline for text, because it is only intended for math. Use \uline from ulem as I show in my answer or the corresponding macro from soul. –  Martin Scharrer Dec 19 '11 at 22:35
    
I'm using ulem, but I thought \underline would make the question clearer. –  David Dec 19 '11 at 22:37
add comment

1 Answer 1

up vote 7 down vote accepted

You can use the ulem package to define such formatting macros. The section 2 Defining new commands in the manual.

Basically you can turn a \textsomething{<content>} macro into a {\switch <content>} macro using \useunder{\textsomething}{\switch}{}. For underlying this can be done using \useunder{\uline}{\ulined}{} where \uline{<content>} is provided by ulem and \ulined is made a switch-version of it. See my answer to I cannot get a (properly) underlined hyperlink in blue where I'm using it.

\documentclass{article}

\usepackage[normalem]{ulem}
\useunder{\uline}{\ulined}{}

\begin{document}

before 
{\ulined Some underlined text}
after

\end{document}

You should load it with the normalem option to keep \emph as normal. There is also the soul package (Strike-Out, UnderLine) which might do the same.

share|improve this answer
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.