# passing text to alltt embeded in command (extra newline needed)

I wanted to close alltt inside a command (to add some ornaments around the text), but the spaces that were used for putting the monospaced text into columns was not preserved.

I found the solution here: Problem with alltt package when defining new command

It is (in simplified form):

\newenvironment{comm}[1]
{%
#1%
\begin{alltt}}
{\end{alltt}}


it works, but I need to put extra newline after \begin:

\begin{comm}

user:        some-user
\end{comm}


Without this newline it looks like this:

This extra newline is not 'eaten' though, it is preserved, so you always have a huge vertial space before actual text. I tried to switch it for for example \null but it didn't work.

I tried to remove % signs and it worked exactly the same way.

This is not a big problem (I hacked it with some vspace), but I would like to know why is it so, because I think it might clarify some matters for me.

-
Welcome to TeX.SX! Why are you specifying an argument to the comm environment? Try removing [1] and #1. –  egreg Sep 14 '12 at 14:18
Hi! Thanks, removing argument worked :) I used it because it was included in original example (in the question mention above). The fact that it shouldn't be there clears some things up. I think I got confused because I was trying many different options. If you make your comment an answer I can choose it as right one. –  nuoritoveri Sep 14 '12 at 14:39

The syntax you're using tells LaTeX to look for an argument to the comm environment. Usually arguments are specified in braces, but the rules of TeX allow to specify it without braces: in this case it's the first token following.

\begin{comm}
user:        some-user
\end{comm}


results in u to be the argument.

Since you don't need anything printed before the alltt environment, the solution is to say

\newenvironment{comm}
{\begin{alltt}}
{\end{alltt}}


By the way, it's a good idea to provide a proper name instead of using a generic environment, just as you're doing. You may later need to change how the environment must be printed; if you had used alltt everywhere, you'd need to look at each alltt environment in order to see if it is one that needs changes. By assigning a different name you can instead change the definition of comm, which would not affect other environments based on alltt you have in your document.

-
Thanks for the answer and the additional clarification about the escaping u. In the last paragraph you mean using a more specific and self-explanatory name than comm or you mean something else? This command is just the basic one and I will add some other things to it. –  nuoritoveri Sep 14 '12 at 15:07
@nuoritoveri The name should be useful to you for remembering what the environment is used for. What I meant is: if some particular logical unit appears frequently in a document, give it a name (with an environment or a command, depending on the object's nature). Thus your policy is correct! –  egreg Sep 14 '12 at 15:22
Now I understand what you meant. I know it's important and I always try to do this, so thanks once more for help on this particular case. –  nuoritoveri Sep 14 '12 at 15:33