# 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
-

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}

-
@Reza It builds a real itemize environment. –  egreg Sep 23 '12 at 14:31
After a year your code save the day again. thanks –  PHPst Oct 12 '13 at 6:22

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}

-