# How to continue a piece of text so it is aligned with the last line of an inline multiline box?

Is there a way to have the continuation of a piece of text aligned with the last line of a multiline environment, such as array?

For example, I would like to define the command

\newcommand{\setst}[2]{\{#1 \mid #2\}}


for the standard set comprehension notation from mathematics. As long as the second argument fits nicely on one line, the above works fine. However, it breaks down for multiline arguments. For example, I would like to write something like

\documentclass{article}
\usepackage{amsmath}

\newcommand{\setst}[2]{\{#1 \mid #2\}}

\begin{document}
\begin{equation*}
S_1 \cap (S_2 \cup S_3)
=
\setst{x}{\begin{array}[t]{@{}l@{}}
x \in S_1 \land {} \\
(x \in S_2 \lor x \in S_3)
\end{array}}
\end{equation*}
\end{document}


As shown above, this prints the \} on the same line as the =. Instead, I would like the output to look like

That is, the \} should appear at the end of the last line of the second argument to \setst. Is there a way to do this without manually expanding the definition of \setst?

# Revised question

Herbert's solution works excellently for many situations, but does not work well for similar constructs that may be nested. Consider, for example,

\documentclass{article}
\usepackage{amsmath}

\newcommand{\setstHerbert}[2]{\{#1 \mid \begin{array}[t]{@{}l@{}}#2\}\end{array}}

\begin{document}
\begin{equation*}
S_1 \cap (S_2 \cup S_3)
=
\setstHerbert{x}{x \in S_1 \land {} \\
x \in \setstHerbert{y}{y \in S_2 \lor {} \\
y \in S_3}}
\end{equation*}
\end{document}


To be typeset correctly, the outermost \} should be on the same line as y \in S_3 and the inner \}. Is there some way to write a command that will allow nesting and still place the \}s on the appropriate lines?

(I agree that nested set comprehensions are perhaps typographically questionable, but I'll be using these ideas to create an "isomorphic" command for pi-calculus parallel compositions, e.g. (\nu x)(P | Q) where Q may itself contain a pi-calculus parallel composition. For parallel compositions, nesting is not typographically questionable.)

-

use another definition:

\documentclass{standalone}
\usepackage[utf8]{inputenc}

\usepackage{amsmath,amssymb}
\pagestyle{empty}
\newcommand\setst[2]{\{#1 \mid
\begin{array}[t]{@{}l@{}}#2 \}\end{array}}

\begin{document}

$S_1 \cap (S_2 \cup S_3) = \setst{x}{ x \in S_1 \land {} \\ (x \in S_2 \lor x \in S_3) }$
$S_1 \cap (S_2 \cup S_3) = \setst{x}{ x \in \mathbb{R} }$
\end{document}

-
Thank you for the tip! I hadn't thought of placing the array inside the definition. If I wanted to add arbitrary text after the \} (on the same line), would you recommend the definition \newcommand{\setst}[3]{\{#1 \mid \begin{array}[t]{@{}l@{}}#2 \} #3\end{array}}? In a way, I was hoping that there would be a position option to handle this kind of thing directly... Thanks again! – Henry DeYoung Jul 4 '11 at 15:06
Thanks again! I've been using your solution for a year now, and it works excellently. I used the idea for other commands, but now ran into a problem with nesting. I've edited my question with details. If you have any ideas on accounting for nesting, I'd be very interested. Once again, thanks for your help earlier! – Henry DeYoung Oct 4 '12 at 20:27