# Custom switches (such as for underlining)

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}

-
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

## 1 Answer

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.

-