# LaTeX Tutorial - The AAC Mathematical Formula Editor

#### Georacer

Joined Nov 25, 2009
5,182
Here in All About Circuits, users often have to communicate ideas through mathematical formulas.

An example is the diode equation.
Who would want to decipher this expression: I=Is(e^(Vd/(nVT))-1)?
On the other hand, the same expression is much more appealing in this form: $$I=I_s \cdot \left(e^{\small{\frac{V_d}{n \cdot V_T}}}-1 \right)$$

That formatting was possible thanks to the ability of the AAC forum to process LaTeX code. LaTeX is a document markup language and document preparation system. It allows us to prepare our text exactly how we want, both in font and paragraph formatting.
In this tutorial we will only examine mathematical formula formatting.

So let's learn how we can write mathematical formulas that are easy to read and understand.

First of all, the way to implement LaTeX code in your text is to include in the appropriate delimiters.
Rich (BB code):
$$yourcode$$
Any code inside those delimiters will be processed by the LaTeX compiler. Notice that any space characters are ignored, as they serve no other purpose than embellishing the look of your code.

LaTeX is based on commands that have objects as their arguments. By default, a single character is considered an object distinct by the next character. If, for some reason we want to group many characters into a single object we can include them in curly brackets:
Rich (BB code):
$${single_object}$$
Commands in LaTeX start with the backslash character "\". Anything that follows will be compared with the known commands and the appropriate action will be taken. It is good practice to enter a space right after the command identifier if it seems not to get compiled correctly.
Rich (BB code):
$$\command{obj1}{obj2}...$$
Now that the theory is over, on to the fun stuff:

Subscript
Rich (BB code):
$$T_S=44kHz$$
$$T_s=44kHz$$

Rich (BB code):
$$E_{total}=E_{kinetic}+E_{dynamic}$$
$$E_{total}=E_{kinetic}+E_{dynamic}$$

Notice the use of the curly brackets to define objects. If I had omitted the outcome would be this:
$$E_total=E_kinetic+E_dynamic$$

Superscript
This works exactly like subscript:
Rich (BB code):
$$P=I^2R$$
$$P=I^2R$$

Rich (BB code):
$$f=a^{2n^2}$$
$$f=a^{2n^2}$$

Fractions
Time for our first command:
Rich (BB code):
$$f=\frac{1}{T}$$
$$f=\frac{1}{T}$$
The first argument is the nominator and the second is the denominator.

Parentheses
A simple parenthesis often looks out of place in certain expressions:
Rich (BB code):
$$f=30(1+x^\frac12)$$
$$f=30(1+x^{\frac12})$$

We can fix this by entering the commands \left and \right before each delimiter:
Rich (BB code):
$$f=30\left(1+x^\frac12\right)$$
$$f=30\left(1+x^{\frac12}\right)$$

That way the parentheses will be set as high as their contents.

Integrals
Rich (BB code):
$$F(x)=\int f(x)dx$$
$$F(x)=\int f(x)dx$$

Rich (BB code):
$$I=\int ^a_b f(x)dx$$
$$I=\int ^a_b f(x)dx$$

Notice that the same code without a space after the \int gives an error. When in doubt, add spaces (not C4).
Rich (BB code):
$$F(x)=\intf(x)dx$$
$$F(x)=\intf(x)dx$$

Limits

In writing limits, we will introduce our first symbol. Symbols are special characters that can be entered by typing their codename after the backslash. The symbol we will use is the "approaches":
Rich (BB code):
$$\to$$
$$\to$$

Rich (BB code):
$$\lim_{x \to 0}\frac{sin(x)}{x}=1$$
$$\lim_{x \to 0}\frac{sin(x)}{x}=1$$

Roots

Rich (BB code):
$$\sqrt{-1}=i$$
$$\sqrt{-1}=i$$

Rich (BB code):
$$\sqrt{8}=2$$
$$\sqrt{8}=2$$

Symbols

Below is a list of useful symbols that are commonly used:

Operators:
Rich (BB code):
$$\cdot \times \div \pm \mp \cap \cup \wedge \vee$$
$$\cdot \times \div \pm \mp \cap \cup \wedge \vee$$
$$\equiv \neq \simeq \propto \in \leq \geq$$
$$\equiv \neq \simeq \propto \in \leq \geq$$

Arrows:
Rich (BB code):
$$\leftarrow \Leftarrow \rightarrow \Rightarrow \leftrightarrow \Leftrightarrow$$
$$\leftarrow \Leftarrow \rightarrow \Rightarrow \leftrightarrow \Leftrightarrow$$

Greek Letters:
Rich (BB code):
[/tex]\alpha \beta \gamma \delta \epsilon \zeta \eta \theta \mu \nu \xi \pi \rho \sigma \tau \phi \chi \psi \omega[/tex]
$$\alpha \beta \gamma \delta \epsilon \zeta \eta \theta \mu \nu \xi \pi \rho \sigma \tau \phi \chi \psi \omega$$

You can capitalize, where applicable, the letter symbols by writing the first letter of the code in capital.
Rich (BB code):
$$\Omega$$[/code]$$\Omega$$

Functions:
Typically, common functions must be escaped, so as to display them in Roman font and not italic:
[CODE=rich][plain]$$\sin \ \cos \ \tan \ \arccos \ \arcsin \ \arctan \ \log \ \ln$$
$$\sin \ \cos \ \tan \ \arccos \ \arcsin \ \arctan \ \log \ \ln$$
The use of the extra backslashes is to introduce spaces and will be explained soon.

Other symbols:
Rich (BB code):
$$\sum \prod \oint \iint \infty \nabla \partial \Im \Re$$
$$\sum \prod \oint \iint \infty \nabla \partial \Im \Re$$

Accents

All of the objects can have an accent. The most common ones are:
Rich (BB code):
$$\dot x \ddot x \bar x \vec x \tilde x$$
$$\dot x \ddot x \bar x \vec x \tilde x$$

Whitespaces and Newlines

Notice how the LaTeX editor interprets this code:
Rich (BB code):
$$x_1+x_2=7 and x_1-x_2=35$$
$$x_1+x_2=7 and x_1-x_2=35$$

My intention was to insert a space before "and" and a double newline between the equations. However, the editor won't compile whitespaces and blank lines.

In order to do that, we must escape the whitespace and fill the blank line with a whitespace. Moreover, the character for the newline is also the double backslash:
Rich (BB code):
$$x_1+x_2=7 \ and \ x_1-x_2=35$$
$$x_1+x_2=7 \ and \ x_1-x_2=35$$

Rich (BB code):
$$first\ line\\second\ line\\third\ line$$
$$first\ line\\second\ line\\third\ line$$

Text

It become obvious now that writing text inside the LaTeX code is somewhat cumbersome. To face that problem, we can use the \text command. This command also uses a Roman regular font for the text, instead of italics:
Rich (BB code):
$$\text{first line second line third line}$$
$$\text{first line second line third line}$$

Last edited:

#### Georacer

Joined Nov 25, 2009
5,182
Text Size

If you feel your superscript is still too large in comparison to its base, or you want to emphasize a part of your text by making it larger, you can always change the font size:

Rich (BB code):
$$\tiny{\text{The quick brown fox jumps over the lazy dog}}$$
$$\tiny{\text{The quick brown fox jumps over the lazy dog}}$$

Rich (BB code):
$$\small{\text{The quick brown fox jumps over the lazy dog}}$$
$$\small{\text{The quick brown fox jumps over the lazy dog}}$$

Rich (BB code):
$$\large{\text{The quick brown fox jumps over the lazy dog}}$$
$$\large{\text{The quick brown fox jumps over the lazy dog}}$$

Tables

Tables are by far the most complex mathematical structures you can build with LaTeX. They are also the hardest to create with simple ASCII manipulation, so there really is no way to avoid using LaTeX if you want to build a readable table.

Tables in LaTeX have significant overhead code:
\begin{array}{indentation} table_contents \end{array}

The indentation field specifies how many columns will the table have and how they will be aligned. If, for example you want a table to have three columns with left, center and right alignment respectively, you insert in the indentation field: {lcr}
If you also want vertical lines to separate the columns , you edit it as follows: {l|c|r}. Each vertical line represents one in the table.
Important note: The double vertical line (||) should work in theory, however the site's LaTeX compiler won't accept it for unknown reasons.

The table line contents are comprised of objects separated by the ampersand (&) mark. Remember that you must have as many objects as many lines you specified in the indentation field.
You can insert a new table line at the end of each line with the newline command (\\)
Horizontal lines are not inserted automatically. You must do so by writing \hline in an empty new line.

That said, let's see an example of a Boolean truth table:
Rich (BB code):
$$\begin{array}{|c|c|c|} \hline \large{X} & \large{Y} & \large{F}\\ \hline\\ \hline\\ 0 & 0 & 0\\ \hline\\ 0 & 1 & 1\\ \hline\\ 1 & 0 & 1\\ \hline\\ 1 & 1 & 0\\ \hline \end{array}$$
$$\begin{array}{|c|c||c|} \hline \large{X} & \large{Y} & \large{F}\\ \hline\\ \hline\\ 0 & 0 & 0\\ \hline\\ 0 & 1 & 1\\ \hline\\ 1 & 0 & 1\\ \hline\\ 1 & 1 & 0\\ \hline \end{array}$$

It is a lot of work, but look how pretty this table turned out!

If you want to include "merged" cells in your table, you can insert a table inside a table. For example, if I wanted to have a header for the above table saying "XOR Gate" I could do it like this:

Rich (BB code):
$$\begin{array}{|m|} \hline\\ \small{\text{XOR Gate}}\\ \hline\\ \begin{array}{c|c||c} \large{X} & \large{Y} & \large{F}\\ \hline\\ \hline\\ 0 & 0 & 0\\ \hline\\ 0 & 1 & 1\\ \hline\\ 1 & 0 & 1\\ \hline\\ 1 & 1 & 0\\ \end{array} \hline \end{array}$$
$$\begin{array}{|m|} \hline\\ \small{\text{XOR Gate}}\\ \hline\\ \begin{array}{c|c||c} \large{X} & \large{Y} & \large{F}\\ \hline\\ \hline\\ 0 & 0 & 0\\ \hline\\ 0 & 1 & 1\\ \hline\\ 1 & 0 & 1\\ \hline\\ 1 & 1 & 0\\ \end{array} \hline \end{array}$$

Another use of tables is to write multi-branch functions:
Rich (BB code):
$$f(x)=\left{ \begin{array}{lml} -x & \, & x<0\\ x^2 & \, & 0\leq x < 1\\ x & \, & x \leq 1 \end{array} \right\$$
$$f(x)=\left{ \begin{array}{lml} -x & \ & x<0\\ x^2 & \ & 0\leq x < 1\\ x & \ & x \leq 1 \end{array} \right\$$

Notice that in order to avoid inserting a right bracket, we write \right\(space), and we insert a right, big whitespace. Neat, huh?

I hope that was enough to cover your first needs.
If you have more questions, please feel free to ask below. Remember: Google is your friend. There are tons of LaTeX dedicated pages out there. Unfortunately, the embedded LaTeX compiler of the site can only do so much, so if something doesn't work, it might mean that it's not supported.

So go out there and make our equations beautiful!

Last edited: