# Underline (or otherwise format) all text in custom environment

I'm trying to define a custom environment, in which all text is underlined. I know the underline command underlines its input, but I can't figure out how to get it to work seamlessly with my environment:

\documentclass{article}
\newenvironment{myenvironment}{\underline}{}
\begin{document}
Not underlined
\begin{myenvironment}
Only first character is underlined
\end{myenvironment}
\underline{Underlined correctly}
\end{document}


How can I apply underline (or other commands) to all the text inside the environment?

Using xelatex 2015 if that matters.

• Welcome to TeX.SX! – JP-Ellis Feb 18 '16 at 22:18
• Have you considered loading the ulem package (with the option normalem) and using the command \uline{...} to perform underlining? – Mico Feb 18 '16 at 23:01

You're looking for soulutf8 and environ. But, please, think again about underlining.

\documentclass{article}
\usepackage{fontspec}
\usepackage{soulutf8,environ}

\NewEnviron{myenvironment}{\expandafter\ul\expandafter{\BODY}}

\begin{document}

Not underlined
\begin{myenvironment}
All words are underlined
All words are underlined
All words are underlined
All words are underlined
All words are underlined
\end{myenvironment}

\ul{Underlined correctly}

\end{document}