# Command \obeylines in a macro

I need to collect data (a sequence of input strings) in the preamble of a document, but the strings are to be typeset later in the document and must obey the line breaks set when typing the strings at the keyboard. Here is an MWE:

\documentclass[12pt]{memoir}

{\obeylines #1}
}
}

Second line}

\begin{document}

Some text here just to fill before typesetting the line-break obeying lines.

And now more text, not obeying line breaks verbatim.

\end{document}


What I find is that I write the argument to the command \makeAddress as shown, namely, with a single stroke of my keyboard's RETURN key, I get a single output line for \address, whereas if I use two strokes, leaving a blank line in the argument between the strings "First line" and "Second line", I get the expected behavior: two output lines. What am I doing wrong?

Ian Thompson's answer set the line breaking issue straight. That was my original question in this post, hence his reply qualifies as answer. But my point is now, how can I do that and at the same time not have the text typeset until the point where it is supposed to?

• I don't think that inputting the address with line breaks is the best approach: I'd use \\ to mark the end of lines. Jul 28, 2012 at 21:13
• @egreg: Sure. But this is in the context of a small class intended to provide a layout for letters which are to be used by people who should remain as unaware as possible of TeX-LaTeX when typing the document's contents. Something like a tiny showcse of the efficiency of TeX-based document generation by stressing the separation from highly-automated, but flexible nonetheless, document layout to content. There are still those used to things like MS Word asking for a non-intimidating and clear chance to discern. Jul 28, 2012 at 22:36
• The biggest problem I see in terminating lines with end-of-lines only is exactly that a clear markup is missing. With \\ you can even type the address on one line and not rely on editor's features. Jul 29, 2012 at 15:54
• @egreg: Absolutely. I agree that's better even as a final user, but some people coming from the WYSIWYG world need to take some things one at a time and I'd need to go step by step. Moreover, I'd like, even if only in order to improve my skills as a TeXnician, to learn how to solve the issue that remains open in my question. Thanks for your remarks. Jul 29, 2012 at 18:14

The problem is that TeX isn't obeying line breaks when it reads the argument of \makeAddress, so it ignores the single carriage return. With two carriage returns, TeX inserts a \par, so you do get a line break in the output. To make it work with one carriage return, you just need to change the order in which things happen.

\documentclass[12pt]{memoir}
\makeatletter
{#1
}
\par\noindent}
\egroup}
%
\begin{document}

You also need to use grouping to prevent \obeylines from staying in effect after \makeAddress is executed. Note that \egroup cannot be placed directly after \@makeAddress because that macro expects to find an argument.
• I was just going to ask you about it. The ways of TeX are convoluted indeed! But then the braces around #1 in the definition of \address are not really necessary, and the \par\noindent goes actually after the call to \address. Jul 28, 2012 at 12:47
• @Marcos: I think it is more LaTeX like to use the command \obeylines inside an environment instead of a command. Jul 28, 2012 at 12:59