# Most concise way to make list items from each line break

How can I convert every line to a list item automatically?

for example I want following become a list (without adding more characters):

\begin{foo}
Persian
French
Arabic
Urdu
\end{foo}

• Persian
• French
• Arabic
• Urdu
-

Here is one option: Using \obeylines and an "itemize definition" for \everypar.

\documentclass{article}
\newenvironment{foo}
{\obeylines\everypar{\textbullet\hspace{\labelsep}}}% \begin{foo}
{}% \end{foo}
\begin{document}
\begin{foo}
Persian
French
Arabic
Urdu
\end{foo}

\begin{itemize}
\item Persian
\item French
\item Arabic
\item Urdu
\end{itemize}
\end{document}

-

If the input is exactly laid out as you show, with \begin{foo} and \end{foo} on lines by themselves, the following will do:

\documentclass{article}

\makeatletter
\newcommand{\checkForEnd}{\@ifnextchar\end{}{\item}}
\makeatother
\newenvironment{foo}
{\par\obeylines
\begingroup\lccode~=\^^M
\lowercase{\endgroup\let~}\checkForEnd
\begin{itemize}}
{\end{itemize}}

\begin{document}
\begin{foo}
Persian
French
Arabic
Urdu
\end{foo}

\begin{itemize}
\item Persian
\item French
\item Arabic
\item Urdu
\end{itemize}
\end{document}


The result of the two environments will be the same. But the foo environment should not appear in the argument to a command.

You can of course modify the appearance of the itemize environment, with the help of the package enumitem. For instance

\usepackage{enumitem}

\newenvironment{foo}
{\par\obeylines
\begingroup\lccode~=\^^M
\lowercase{\endgroup\let~}\checkForEnd
\begin{itemize}[nosep]}
{\end{itemize}}


will "kill" all vertical space, while noitemsep in place of nosep will remove the space between the items, leaving the separation of the environment from the text above and below it.

You can even do the setup for each foo environment with

\usepackage{enumitem}

\newenvironment{foo}[1][]
{\par\obeylines
\begingroup\lccode~=\^^M
\lowercase{\endgroup\let~}\checkForEnd
\begin{itemize}[#1]}
{\end{itemize}}


so that the options can be passed as optional argument to foo; for instance,

\begin{foo}[nosep]
Persian
French
Arabic
Urdu
\end{foo}

-
Thanks, Dose your method have also any advantage over Werner's answer? – PHPst Sep 23 '12 at 14:22
@Reza It builds a real itemize environment. – egreg Sep 23 '12 at 14:31
Thanks, Appearance of your new environment is exactly like normal list that is perfect for some situations, but I think Werner's version line height is more appropriate for this short items. How can I modify your version so it appear like that? – PHPst Oct 5 '12 at 7:51