# How do I write mathematics in LaTeX?

Like you write text.

## 1. General Idea

Math expressions can be 'inline' or 'displayed'. That is, they can appear inside a running text paragraph (inline) or stand out separately (displayed). Here's the difference (compile and run the following):
\documentclass[12pt]{article}

\title{Hello, Cruel World!}
\author{Obedient Grad Student\thanks{My advisor for not reading a single draft.}
\\Department of Political Science
\\UCSD}

\begin{document}
\maketitle

\section{The Model}

My great model involves $\Pr(X\leq x)=a$ such that $a\in[0,1]$. We covered
cumulative distribution functions:
$$F(x) = \int_{-\infty}^x f(u)du.$$

We also covered some logic. Here is DeMorgan's first law:
$$\neg[p\wedge q]\equiv\neg p\vee\neg q,$$
and here's the other:
$$\neg[p\vee q]\equiv\neg p\wedge\neg q.$$

If event $A=\bigcup_{i=1}^n A_i$ such that $A_i\subset X$ and $A_i\cap A_j=\emptyset$ for all $i$, then:
$$\Pr(A)=\sum_{i=1}^n \Pr(A_i).$$

To see how fractions are done, here's Bayes rule:
$$\Pr(A|B)=\frac{\Pr(B|A)\Pr(A)}{\Pr(B|A)\Pr(A)+\Pr(B|\neg A)\Pr(\neg A)}$$
%
That's all.

\end{document}

This may appear a bit messy, but it's very easy to understand and can become quite readable with practice, especially once you've learned the basic commands to typeset simple math.

Inline math is written between two -signs. Displayed math is written either between two -signs (unnumbered) or, if you want numbered equations in the 'equation' environment, which is designated with the '$$' and '$$' commands. The math commands are pretty self-explanatory. If you want a subscript, you type '_' (underscore) and then whatever you want in the subscript. If you want a superscript, you type '^' (caret) and then whatever you want there. You can also have both (note the summation sign) and, if they involve more than one symbol, you must enclose them in braces (note the lower bound on the integral). Another great feature of WinEdt is the LaTeX toolbar (which it misleadingly calls "GUI Page Control") which has a lot of the math symbols available by clicking on the appropriate button. This is nice especially while you are remembering the commands. Once you remember them, typing becomes very quick and painless. ## 2. The AMS Packages You will also notice that the GUI toolbar has tabs that begin with the letters "AMS". These stand for "American Mathematical Society" and to use the symbols in these tabs you need the "AMS-LaTeX" package which (helpfully) came with your MiKTeX installation. The AMS package is exceedingly useful because it has special environments for more complicated math expressions, theorems, proofs, and anything you may ever need. Here's how you'd use the AMS packages: \documentclass[12pt]{article} \usepackage{amsmath,amsthm} \newtheorem{proposition}{Proposition} \title{Hello, Cruel World!} \author{Obedient Grad Student\thanks{My advisor for not reading a single draft.} \\Department of Political Science \\UCSD} \begin{document} \maketitle \section{The Model} Here are the DeMorgan laws: \begin{align} \neg[p\wedge q]&\equiv\neg p\vee\neg q\\ \neg[p\vee q]&\equiv\neg p\wedge\neg q. \end{align} \noindent Let's look at an important result. \begin{proposition} If event A=\bigcup_{i=1}^n A_i such that A_i\subset X and A_i\cap A_j=\emptyset for all i, then: \Pr(A)=\sum_{i=1}^n \Pr(A_i).$\end{proposition} \begin{proof} Left as an exercise. \end{proof} \end{document}  Notice the '\usepackage' command in the preamble. This tells the compiler to pull in other macro packages (two in this case: basic math and theorem environments). Still in the preamble, we define the new 'proposition' environment that we shall be using. Everything else is automatic. The AMS documentation is distributed with MiKTeX. ## 3. Where, the (*&#$^%, do a I get a list of math commands?

Several places. First, you really should buy at least one LaTeX book. These are the two I have found most useful:
1. Lamport, Leslie. 1994. LaTeX: A Document Preparation System. Reading, MA: Addison-Wesley.
2. Goosens, Michel, Frank Mittelbach, and Alexander Samarin. 1994. The LaTeX Companion. Reading, MA: Addison-Wesley.
There was another, but someone stole it and I can't remember the name. Something like "LaTeX by example" or "LaTeX Line by Line"?

There are many online guides, here's one that is basic and useful.

Branislav L. Slantchev, UCSD