If it seems like it's getting it wrong, keep writing; it often will autocorrect as you finish your equation.
You can insert a variety of pre-built equations by clicking the down-arrow under the Equation button in either application.