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,142
    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][tex]yourcode[/tex][/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][tex]{single_object}[/tex][/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][tex]\command{obj1}{obj2}...[/tex][/plain]
    Now that the theory is over, on to the fun stuff:

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

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

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

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

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

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

    Roots

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

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

    Symbols

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

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

    Arrows:
    Code ( (Unknown Language)):
    1. [plain][tex]\leftarrow \Leftarrow \rightarrow \Rightarrow \leftrightarrow \Leftrightarrow[/tex][/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][tex]\Omega[/tex][/code][tex]\Omega[/tex]
    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][tex]\sin \ \cos \ \tan \ \arccos \ \arcsin \ \arctan \ \log \ \ln[/tex][/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][tex]\sum \prod \oint \iint \infty \nabla \partial \Im \Re[/tex][/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][tex]\dot x \ddot x \bar x \vec x \tilde x[/tex][/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][tex]x_1+x_2=7 and
    2.  
    3. x_1-x_2=35[/tex][/plain]
    x_1+x_2=7 and<br />
<br />
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][tex]x_1+x_2=7 \ and
    2. \
    3. x_1-x_2=35[/tex][/plain]
    x_1+x_2=7 \ and<br />
\ <br />
x_1-x_2=35

    Code ( (Unknown Language)):
    1. [plain][tex]first\ line\\second\ line\\third\ line[/tex][/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][tex]\text{first line
    2. second line
    3. third line}[/tex][/plain]
    \text{first line<br />
second line<br />
third line}
     
    Last edited: Nov 4, 2011
  2. Georacer

    Thread Starter Moderator

    Nov 25, 2009
    5,142
    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][tex]\tiny{\text{The quick brown fox jumps over the lazy dog}}[/tex][/plain]
    \tiny{\text{The quick brown fox jumps over the lazy dog}}

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

    Code ( (Unknown Language)):
    1. [plain][tex]\large{\text{The quick brown fox jumps over the lazy dog}}[/tex][/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][tex]
    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. [/tex][/plain]
    <br />
\begin{array}{|c|c||c|}<br />
\hline<br />
\large{X} & \large{Y} & \large{F}\\<br />
\hline\\<br />
\hline\\<br />
0 & 0 & 0\\<br />
\hline\\<br />
0 & 1 & 1\\<br />
\hline\\<br />
1 & 0 & 1\\<br />
\hline\\<br />
1 & 1 & 0\\<br />
\hline<br />
\end{array}<br />

    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][tex]
    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. [/tex]
    21. [/plain]
    <br />
\begin{array}{|m|}<br />
\hline\\<br />
\small{\text{XOR Gate}}\\<br />
\hline\\<br />
 \begin{array}{c|c||c}<br />
 \large{X} & \large{Y} & \large{F}\\<br />
 \hline\\<br />
 \hline\\<br />
 0 & 0 & 0\\<br />
 \hline\\<br />
 0 & 1 & 1\\<br />
 \hline\\<br />
 1 & 0 & 1\\<br />
 \hline\\<br />
 1 & 1 & 0\\<br />
 \end{array}<br />
\hline<br />
\end{array}<br />

    Another use of tables is to write multi-branch functions:
    Code ( (Unknown Language)):
    1. [plain][tex]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. [/tex][/plain]
    f(x)=\left{ \begin{array}{lml}<br />
-x & \  & x<0\\<br />
x^2 & \  & 0\leq x < 1\\<br />
x & \  & x \leq 1<br />
\end{array} \right\ <br />

    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
  3. Georacer

    Thread Starter Moderator

    Nov 25, 2009
    5,142
    1,266
  4. Ryan2

    Member

    May 29, 2015
    31
    0
Loading...