# Conflict between macro argument #1 and internal #1 argument of the package parselines

I want to run this code in order to print all lines (including each of the blank lines) of the argument inside \PrintAllLines{}. For that, I would like to use the parselines package, because it recognizes well all blank lines. \obeylines is not an option, because it doesn't recognize multiple blank lines under each other.

The problem with this code is, that the argument #1 inside \begin{parse lines}[\noindent]{#1\\} should be actually what is inserted between \begin{parse lines} and \end{parse lines} and not the argument #1, that was passed by \PrintAllLines{}. There's a conflict with both #1 arguments and I don't know to solve this situation.

Does someone have a good idea how to handle this?

Is it maybe possible to pass an argument through \PrintAllLines{}, but using something else then the code #1, so that the internal #1 of \begin{parse lines}[\noindent]{#1\\} works well?

A MWE would be great, as I'm new to LaTeX and still learning.

\documentclass[12pt,a4paper]{article}
\usepackage{parselines}

\renewcommand{\PrintAllLines[1]{
\begin{parse lines}[\noindent]{#1\\}
#1
\end{parse lines}
}}

\begin{document}
\PrintAllLines{

line 1

line 2 with multiple spaces above

line 3 with multiple spaces above

}

\end{document}

• parse lines collects the contents of the environment verbatim (that's how it manages to detect line ends), so you cannot grab the environment as the argument to a macro. What you want here is \begin{parse lines}[\noindent]{##1\\} (with two #), but again, grabbing the environment as #1 will not work. – Phelype Oleinik Jan 29 at 18:22

Since parselines was only a means to an end (retaining each linefeed), here is another means. Using listofitems, with a macro definition.

\documentclass{article}
\usepackage{listofitems}
\newcommand\PrintAllLines{\begingroup\obeylines\PrintAllLinesAux}
\begingroup
\obeylines
\gdef\PrintAllLinesAux#1{%
\setsepchar{
}%
\foreachitem\z\in\mytest[]{\noindent\z\\}%
\endgroup%
}
\endgroup
\begin{document}
\PrintAllLines{this
is

a

test}

For comparison, normal endline intake:

this
is

a

test
\end{document}


Customization is easy, just by changing the \foreachitem argument. For example, if \foreachitem\z\in\mytest[]{\noindent\makebox[2em][l]{\scriptsize\zcnt:}\z\\}% is used, this is the result:

• Thank you very much, it worked pretty well! – Quintus Dias Feb 4 at 17:17

As write Phelype Oleinik you can't use parse lines environment in \newcommand because of implementation features.

But you can define own environment for simplify your work, like this:

\documentclass[12pt,a4paper]{article}
\usepackage{parselines}

\begin{document}

\newenvironment{my parse lines}
{\begin{parse lines}[\noindent]{##1\\}}
{\end{parse lines}}

\begin{my parse lines}

line 1

line 2 with multiple spaces above

line 3 with multiple spaces above
\end{my parse lines}

\end{document}

• Thank you, your code is great and useful too! I accepted the code from @steven just because I was searching for a way to type only \PrintAllLines{content here}. – Quintus Dias Feb 4 at 17:23