# 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? Mar 19 '11 at 20:01
• @Moron: Some people are just pathetic...
– Tim
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. 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. 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. 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. 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 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! Aug 7 '11 at 11:40
• One way to get them to be the same size is using the vphantom command. Aug 7 '11 at 14:30
• Oh, I didn't know Isaac's trick. How cool.
– davidlowryduda Mod
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 Mod
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. 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... :) Aug 7 '11 at 12:52
• Thanks, Theo; thanks, J. M., I'm in good company then. Aug 7 '11 at 22:50