# Changing existing commands/ macros frome 1 to 0 parameters

How do you change an already existing command such that it works with 0 parameters?

For instance, the \underline{} and \textbf{} macros takes 1 parameter each. However, I want them to take 0 parameters so I can use them in an environment:

\newenvironment{e}{\textbf\underline}{}


or like this: {\textbf Hello this text is BOLD.} And this is not. I was thinking about defining a new macro:

\newcommand{\underlinee}{}


Then my question is: How can I define this new macro? What should I write in the blanck {}?

• for \textbf it is easy, just use \bfseries instead, but for \underline what do you wannt it to do? you could use the enviornm package and \underline{\BODY} but it does not allow line breaking so is not usually what you want for an environment. – David Carlisle Jan 28 at 21:26
• Yes, you are right. For the underline part, I want it to underline all text inside the environment. – Vebjorn Jan 28 at 21:39
• look at ulem package (note that thinking of turning a macro with arguments to one without is the wrong way to think of it and is not generally possible. \textbf is defined by essentially \newcommand\textbf[1]{{\bfseries #1}} and it is \bfseries that you want. You can't in general define a command with a syntax like \bfseries from the argument form. – David Carlisle Jan 28 at 21:42

You can do it with soul or ulem.

\documentclass{article}
\usepackage{xparse}
\usepackage{soul}

\NewDocumentEnvironment{obnoxious}{b}
{\textbf{\ul{#1}}}
{}

\begin{document}

Some text before
\begin{obnoxious}
some text in bold face and underlined. You can't use multiple paragraphs
\end{obnoxious}
and other text follows.

\end{document}


Of course, instead of \textbf it's better to use \bfseries:

\documentclass{article}
\usepackage{xparse}
\usepackage{soul}

\NewDocumentEnvironment{obnoxious}{b}
{\bfseries\ul{#1}}
{}

\begin{document}

Some text before
\begin{obnoxious}
some text in bold face and underlined. You can't use multiple paragraphs
\end{obnoxious}
and other text follows.

\end{document}


because \textbf{text} is mostly like {\bfseries text} (just a simplification).

Can you use multiple paragraphs? Yes, with some more work.

\documentclass{article}
\usepackage{xparse}
\usepackage{soul}

\ExplSyntaxOn
\seq_new:N \l__vebjorn_obnoxious_in_seq
\seq_new:N \l__vebjorn_obnoxious_out_seq

\NewDocumentEnvironment{obnoxious}{+b}
{
\seq_set_split:Nnn \l__vebjorn_obnoxious_in_seq { \par } { #1 }
\seq_set_map:NNn \l__vebjorn_obnoxious_out_seq \l__vebjorn_obnoxious_in_seq
{
\exp_not:n { \ul { ##1 } }
}
\bfseries\seq_use:Nn \l__vebjorn_obnoxious_out_seq { \par }
}
{}
\ExplSyntaxOff

\begin{document}

Some text before
\begin{obnoxious}
some text in bold face and underlined.

You can even use multiple paragraphs
\end{obnoxious}
and other text follows.

\end{document}


Of course this is just for academic interest, isn't it? Long text in boldface type and underlined is like a punch in the eye. Underlining itself is not considered a good device in fine typography.

For this reason, I won't show an image of the result.

• For this reason, I won't show an image of the result. Oh, I came here just to see the output!!! :) – Sigur Jan 28 at 23:41
• It is actually for creating some small "headlines" in a text. Thank you. – Vebjorn Jan 29 at 13:56
• @Vebjorn Don't underline. Never. – egreg Jan 29 at 14:01