# Make newlines expand to custom command

I am making a guest list which I will print on a sticker sheet, cut them out, then stick them to envelopes. This means that each guest/guest group will have a bounding box drawn around it as a cutting guide. For the bounding box, I'm using the fancybox package and followed the examples in its documentation to create a fminipage environment to allow line breaks within a box.

I defined a \newcommand{\guest}[1]... which says:

\begin{fminipage}{\textwidth}
\center #1
\end{fminipage}


It's a success. I just type in:

\guest{Luke Skywalker}
\guest{Obi-Wan Kenobi}
\guest{Han Solo\\
Princess Leia}


Luke and Obi-Wan have their own boxes, then Han Solo and Princess Leia are placed in one box together.

Now, I want to use shortcuts. How do I implement it such that I just input the following:

Luke Skywalker
Obi-Wan Kenobi
{Han Solo
Princess Leia}


Looks like this could be a deep kernel hack, which I do not know anything about. But of course, anything that the community knows is always welcome.

-
I retagged the question (it had nothing to do with boxes). Belatedly, it occurs to me that I should have changed the title too, for the benefit of future readers. How does “Processing data from an external file” sound? –  Harald Hanche-Olsen Nov 28 '10 at 10:41
center is the name of an environment \begin{center}...\end{center}. I think you want \centering here. –  TH. Nov 28 '10 at 11:49
@TH. \center actually worked somehow. But I'll take your advice :) –  Kit Nov 28 '10 at 12:10
Yes, it does work. Environments work basically like this: \begin{foo}...\end{foo} expands to \begingroup \foo ... \endfoo \endgroup along with some checking that \foo is defined and that the argument of the \end matches the corresponding argument to \begin. For example, try \begin{LaTeX}\end{LaTeX}. Note that \endLaTeX isn't defined and yet the code still works. This is due to \csname ... \endcsname trickery. –  TH. Nov 28 '10 at 12:15
@Harald: now you’ve changed the complete meaning of the question. The original question was quite literally “how can I redefine the \cr command in LaTeX?” You’ve changed it to something completely different, which, while possibly working in this particular case, suggests entirely different answers. –  Konrad Rudolph Nov 28 '10 at 14:53

One slight speedbump here is that you have linebreaks within your arguments as well, and of course you dn't want them to turn into \guest commands as well.

But if you're not doing this as a programming exercise, I'd recommend looking at the datatool package which lets you do things with CSV files, so you'd need a guest file that looks like

Obi-Wan Kenobi
Luke Skywalker
Han Solo;Princess Leia


or similar.

-
+1 The ; or some other delimiter would work better. –  Kit Nov 29 '10 at 2:06

Apparently my first answer was based on a (partial?) misunderstanding of the question, so here is take 2. No external file this time.

\documentclass{article}
% this is just for demonstration purposes:
\newcommand{\guest}[1]{{\message{[Inviting: #1]}}}
\begin{document}
\begingroup\obeylines%
\def\doguests#1^^M{%
\ifx\relax#1\relax\else%
\guest{#1}\expandafter\doguests\fi}%
\def^^M{ and }\doguests%
Luke Skywalker
Obi-Wan Kenobi
{Han Solo
Princess Leia}

\endgroup
\end{document}

-
Clever. I was always annoyed by the brace stripping for delimited arguments, but this is a good use of them. –  TH. Nov 28 '10 at 16:44

As Ulrich says, it is best to use a package. However, if the package isn't easily made to do what you want, you can roll your own:

\documentclass{article}
% this is just for demonstration purposes:
\newcommand{\guest}[1]{{\let\\\relax\message{[Inviting: #1]}}}
\ifeof\guests\else
}
\begin{document}
\openin\guests=guests.list

Edit: I should perhaps have added a bit of explanation. Without \endlinechar=-1, each read would include a space token at the end. More importantly, the final read would return a \par token instead of being empty, so the check for end-of-file would have to be changed.
Edit 2: Used the \ifeof primitive to check for end of file. Note the somewhat nonintuitive placement of this after the \read, though: At the end of file, the empty token list will be read in, and only afterwards does \ifeof become true.
The \ifeof primitive is how you should check for the end of the file. –  TH. Nov 28 '10 at 11:48