[Tex/LaTex] \bar only allowed in math mode error

amsmathmath-mode

I am trying to type up an equation for my discrete math class but I keep on getting the "\bar allowed only in math mode" error. My previous usage of \bar worked out fine.

$p( \bar{E} \cap \bar{F}) = p( \bar{E \cup F})
= 1 - p(E \cup F)  = 1 - p(E) - p(F) + p(E \cap F)
= 1 - p(E) - p(F) + p(E)p(F\)  = (1-p(E))(1-p(F)) = p( \bar{E})p( \bar{F})$

Best Answer

Your problem is:

$p( \bar{E} \cap \bar{F}) = p( \bar{E \cup F})
= 1 - p(E \cup F)  = 1 - p(E) - p(F) + p(E \cap F)
= 1 - p(E) - p(F) +
% -------------------
p(E)p(F\) %right here
% -------------------
= (1-p(E))(1-p(F)) = p( \bar{E})p( \bar{F})$

p(E)p(F\). That's your problem. \) exits math mode. \( ... \) is an alternative to $ ... $. Where you've put \), it's exited math mode. And then when you have \bar afterwards, you're outside of math mode, and:

\bar allowed only in math mode

If we correct that, then it compiles, however, \bar{E \cup F} is not going to work out very well, you probably want \overline{E \cup F}

Might I also recommend something more like:

\begin{flalign*}
  p(\bar{E} \cap \bar{F}) &= p(\,\overline{E \cup F}\,) \\[\parskip]
  &= 1 - p(E \cup F) \\[\parskip]
  &= 1 - p(E) - p(F) + p(E \cap F) \\[\parskip]
  &= 1 - p(E) - p(F) + p(E)p(F) \\[\parskip]
  &= (1-p(E))(1-p(F)) \\[\parskip]
  &= p(\bar{E})p(\bar{F})
\end{flalign*}

enter image description here