# LaTeX Tutorial - The AAC Mathematical Formula Editor

Discussion in 'Homework Help' started by Georacer, Oct 2, 2011.

1. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,151
1,266
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.
Code ( (Unknown Language)):
1. [plain]$$yourcode$$[/plain]
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:
Code ( (Unknown Language)):
1. [plain]$${single_object}$$[/plain]
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.
Code ( (Unknown Language)):
1. [plain]$$\command{obj1}{obj2}...$$[/plain]
Now that the theory is over, on to the fun stuff:

Subscript
Code ( (Unknown Language)):
1. [plain]$$T_S=44kHz$$[/plain]
$T_s=44kHz$

Code ( (Unknown Language)):
1. [plain]$$E_{total}=E_{kinetic}+E_{dynamic}$$[/plain]
$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:
Code ( (Unknown Language)):
1. [plain]$$P=I^2R$$[/plain]
$P=I^2R$

Code ( (Unknown Language)):
1. [plain]$$f=a^{2n^2}$$[/plain]
$f=a^{2n^2}$

Fractions
Time for our first command:
Code ( (Unknown Language)):
1. [plain]$$f=\frac{1}{T}$$[/plain]
$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:
Code ( (Unknown Language)):
1. [plain]$$f=30(1+x^\frac12)$$[/plain]
$f=30(1+x^{\frac12})$

We can fix this by entering the commands \left and \right before each delimiter:
Code ( (Unknown Language)):
1. [plain]$$f=30\left(1+x^\frac12\right)$$[/plain]
$f=30\left(1+x^{\frac12}\right)$

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

Integrals
Code ( (Unknown Language)):
1. [plain]$$F(x)=\int f(x)dx$$[/plain]
$F(x)=\int f(x)dx$

Code ( (Unknown Language)):
1. [plain]$$I=\int ^a_b f(x)dx$$[/plain]
$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).
Code ( (Unknown Language)):
1. [plain]$$F(x)=\intf(x)dx$$[/plain]
$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":
Code ( (Unknown Language)):
1. [plain]$$\to$$[/plain]
$\to$

Code ( (Unknown Language)):
1. [plain]$$\lim_{x \to 0}\frac{sin(x)}{x}=1$$[/plain]
$\lim_{x \to 0}\frac{sin(x)}{x}=1$

Roots

Code ( (Unknown Language)):
1. [plain]$$\sqrt{-1}=i$$[/plain]
$\sqrt{-1}=i$

Code ( (Unknown Language)):
1. [plain]$$\sqrt[3]{8}=2$$[/plain]
$\sqrt[3]{8}=2$

Symbols

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

Operators:
Code ( (Unknown Language)):
1. [plain]$$\cdot \times \div \pm \mp \cap \cup \wedge \vee$$[/plain]
2. $$\cdot \times \div \pm \mp \cap \cup \wedge \vee$$
3. [plain]$$\equiv \neq \simeq \propto \in \leq \geq$$[/plain]
$\equiv \neq \simeq \propto \in \leq \geq$

Arrows:
Code ( (Unknown Language)):
1. [plain]$$\leftarrow \Leftarrow \rightarrow \Rightarrow \leftrightarrow \Leftrightarrow$$[/plain]
$\leftarrow \Leftarrow \rightarrow \Rightarrow \leftrightarrow \Leftrightarrow$

Greek Letters:
Code ( (Unknown Language)):
1. [plain][/tex]\alpha \beta \gamma \delta \epsilon \zeta \eta \theta \mu \nu \xi \pi \rho \sigma \tau \phi \chi \psi \omega[/tex][/plain]
$\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.
Code ( (Unknown Language)):
1. [plain]$$\Omega$$[/code]$$\Omega$$
2.
3. Functions:
4. Typically, common functions must be escaped, so as to display them in Roman font and not italic:
5. [CODE=rich][plain]$$\sin \ \cos \ \tan \ \arccos \ \arcsin \ \arctan \ \log \ \ln$$[/plain]
$\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:
Code ( (Unknown Language)):
1. [plain]$$\sum \prod \oint \iint \infty \nabla \partial \Im \Re$$[/plain]
$\sum \prod \oint \iint \infty \nabla \partial \Im \Re$

Accents

All of the objects can have an accent. The most common ones are:
Code ( (Unknown Language)):
1. [plain]$$\dot x \ddot x \bar x \vec x \tilde x$$[/plain]
$\dot x \ddot x \bar x \vec x \tilde x$

Whitespaces and Newlines

Notice how the LaTeX editor interprets this code:
Code ( (Unknown Language)):
1. [plain]$$x_1+x_2=7 and 2. 3. x_1-x_2=35$$[/plain]
$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:
Code ( (Unknown Language)):
1. [plain]$$x_1+x_2=7 \ and 2. \ 3. x_1-x_2=35$$[/plain]
$x_1+x_2=7 \ and
\
x_1-x_2=35$

Code ( (Unknown Language)):
1. [plain]$$first\ line\\second\ line\\third\ line$$[/plain]
$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:
Code ( (Unknown Language)):
1. [plain]$$\text{first line 2. second line 3. third line}$$[/plain]
$\text{first line
second line
third line}$

Last edited: Nov 4, 2011
2. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,151
1,266
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:

Code ( (Unknown Language)):
1. [plain]$$\tiny{\text{The quick brown fox jumps over the lazy dog}}$$[/plain]
$\tiny{\text{The quick brown fox jumps over the lazy dog}}$

Code ( (Unknown Language)):
1. [plain]$$\small{\text{The quick brown fox jumps over the lazy dog}}$$[/plain]
$\small{\text{The quick brown fox jumps over the lazy dog}}$

Code ( (Unknown Language)):
1. [plain]$$\large{\text{The quick brown fox jumps over the lazy dog}}$$[/plain]
$\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:
Code ( (Unknown Language)):
1. [plain]$$2. \begin{array}{|c|c|c|} 3. \hline 4. \large{X} & \large{Y} & \large{F}\\ 5. \hline\\ 6. \hline\\ 7. 0 & 0 & 0\\ 8. \hline\\ 9. 0 & 1 & 1\\ 10. \hline\\ 11. 1 & 0 & 1\\ 12. \hline\\ 13. 1 & 1 & 0\\ 14. \hline 15. \end{array} 16.$$[/plain]
$
\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:

Code ( (Unknown Language)):
1. [plain]$$2. \begin{array}{|m|} 3. \hline\\ 4. \small{\text{XOR Gate}}\\ 5. \hline\\ 6. \begin{array}{c|c||c} 7. \large{X} & \large{Y} & \large{F}\\ 8. \hline\\ 9. \hline\\ 10. 0 & 0 & 0\\ 11. \hline\\ 12. 0 & 1 & 1\\ 13. \hline\\ 14. 1 & 0 & 1\\ 15. \hline\\ 16. 1 & 1 & 0\\ 17. \end{array} 18. \hline 19. \end{array} 20.$$
21. [/plain]
$
\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:
Code ( (Unknown Language)):
1. [plain]$$f(x)=\left{ \begin{array}{lml} 2. -x & \, & x<0\\ 3. x^2 & \, & 0\leq x < 1\\ 4. x & \, & x \leq 1 5. \end{array} \right\ 6.$$[/plain]
$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: Nov 4, 2011

Nov 25, 2009
5,151
1,266

May 29, 2015
31
0