# How to deal with long formula?

How to show a formula too long to fit in a line?

For example: $$P(Y-X=m | Y > X) = \sum_{k} P(Y-X=m, X=k | Y > X) = \sum_{k} P(Y-X=m | X=k, Y > X) P(X=k | Y > X) = \sum_{k} P(Y-k=m | Y > k) P(X=k | Y > X).$$

Thanks!

• Why downvote this? – Aryabhata Mar 19 '11 at 20:01
• @Moron: Some people are just pathetic... – Ethan Mar 20 '11 at 0:43
• Let us not jump to conclusions. Perhaps they think they have a valid reason? I am guessing one possible reason could be that it is already in the FAQ (although my brief search didn't bring up any). The downvote could be to encourage searching the FAQ first. Of course, downvoting without commenting is pointless in that case. – Aryabhata Mar 20 '11 at 2:25

Use double dollars and the \begin{align*} environment (within TeX-mode) to solve the problem.

\begin{align*} P(Y-X=m | Y > X) &= \sum_{k} P(Y-X=m, X=k | Y > X) \\ &= \sum_{k} P(Y-X=m | X=k, Y > X) P(X=k | Y > X) \\ &= \sum_{k} P(Y-k=m | Y > k) P(X=k | Y > X).\end{align*}

\begin{align*} P(Y-X=m | Y > X) &= \sum_{k} P(Y-X=m, X=k | Y > X) \ &= \sum_{k} P(Y-X=m | X=k, Y > X) P(X=k | Y > X) \ &= \sum_{k} P(Y-k=m | Y > k) P(X=k | Y > X).\end{align*}

• What about a case where one has a single long formula which begins with a \left(and ends with a \right)? The align environment seems to fail (in MathJax) for that case. – Eric Nitardy Mar 19 '11 at 17:47
• @Eric: You can use the invisible \right. to close the left( on the first line and the invisible \left. to open the closing \right) on the last line and make \begin{align}...\end{align} happy. – Isaac Mar 19 '11 at 19:26
• Actually, the \begin{align*} environment can be used without first going into TeX mode (without the double dollar signs), though it sometimes requires you to escape with extra backslashes to get the interpreter to understand. – Arturo Magidin Mar 19 '11 at 21:13
• @Eric: the specific problem with \left and \right pairs not working across line breaks is also inherent already in standard TeX, so not a problem with MathJax per se. The usual way to solve the problem is to manually insert \big and similar versions. See en.wikipedia.org/wiki/Help:Displaying_a_formula – Willie Wong Mar 23 '11 at 16:11
• @Isaac: But that can give problems because the left bracket and the right bracket don't have to be of the same size! – Jonas Teuwen Aug 7 '11 at 11:40
• One way to get them to be the same size is using the vphantom command. – David E Speyer Aug 7 '11 at 14:30
• Oh, I didn't know Isaac's trick. How cool. – davidlowryduda Aug 7 '11 at 20:59
• @AsafKaragila What is the difference between \begin{align*} and \begin{align}? – user93957 Jan 29 '14 at 12:42
• @Aðøbe: On this site? None. In general? align* is an unnumbered environment, whereas align is numbered. – Asaf Karagila Jan 29 '14 at 13:04
• @AsafKaragila Thanks! – user93957 Jan 29 '14 at 13:05

Alternatively, since MathJax supports the amsmath extensions, the split environment is also supported:

$$\begin{split}P(Y-X=m | Y > X) &= \sum_{k} P(Y-X=m, X=k | Y > X) \\ &= \sum_{k} P(Y-X=m | X=k, Y > X) P(X=k | Y > X) \\ &= \sum_{k} P(Y-k=m | Y > k) P(X=k | Y > X).\end{split}$$

which is generated by

$$\begin{split} P(Y-X=m | Y > X) &= \sum_{k} P(Y-X=m, X=k | Y > X) \\ &= \sum_{k} P(Y-X=m | X=k, Y > X) P(X=k | Y > X) \\ &= \sum_{k} P(Y-k=m | Y > k) P(X=k | Y > X).\end{split}$$

• And nobody pointed out that it would be much nicer to use \mid instead of |... :) – t.b. Aug 7 '11 at 9:56
• @Theo: ROFL, yes. :D It sucks MathJax doesn't support the \middle to go along with \left and \right though. – J. M. isn't a mathematician Aug 7 '11 at 10:14
• Oh, I wasn't aware of that... Hmm. That's probably because I normally use colons for that purpose. – t.b. Aug 7 '11 at 10:24

As the last mathematician in the world still using Plain TeX, I'd do it with eqalign.

\eqalign{P(Y-X=m\mid Y\gt X)&=\sum_kP(Y-X=m,X=k\mid Y\gt X)\cr&=\sum_kP(Y-X=m\mid X=k,Y\gt X)\,P(X=k\mid Y>X)\cr&=\sum_kP(Y-k=m\mid Y\gt k)\,P(X=k\mid Y\gt X)\cr}

\eqalign{
P(Y-X=m\mid Y\gt X)
&=\sum_kP(Y-X=m,X=k\mid Y\gt X)\cr
&=\sum_kP(Y-X=m\mid X=k,Y\gt X)\,P(X=k\mid Y>X)\cr
&=\sum_kP(Y-k=m\mid Y\gt k)\,P(X=k\mid Y\gt X)\cr
}

• "last mathematician in the world still using Plain $\TeX$" - IIRC, Arturo's another one, so I'm not sure about that claim... :) – J. M. isn't a mathematician Aug 7 '11 at 12:52
• Thanks, Theo; thanks, J. M., I'm in good company then. – Gerry Myerson Aug 7 '11 at 22:50