Вы находитесь на странице: 1из 33

LATEX guide for Slader contributors

Slader LLC
Outline
Introduction
Typesetting Text
Typesetting Mathematics
Dollar Signs
Packages
Additional Examples
Overset Command
Overbrace/Underbrace Commands
Gather Environment
Matrices
Colors
Fractions
Brackets
Final Comments
Why LATEX

I It makes beautiful documents


I Especially documents with mathematics content
I It was created by scientist, for scientists
I A large and active community
I It is easy to use
I Slader has its own built-in LaTeX compiler
I List of packages that can be used will be given later
How does it work

I You write your document in plain text with commands that


describe its structure and meaning.
I The LaTeX program processes your text and commands to
produce a beautifully formatted document.
I A large and active community

The rain in Spain falls \emph{ mainly } on the plain.




latex
y

The rain in Spain falls mainly on the plain.


More examples of commands and their output

LaTeX code Output


\begin{itemize}
\item Tea I Tea
\item Milk I Milk
\item Biscuits I Biscuits
\end{itemize}

LaTeX code Output


\begin{equation}
\alpha + \beta + 1
\end{equation} α+β+1 (1)
Typesetting Text

I For the most part, you can just type your text normally.

I Space in the source file is collapsed in the output.


Typesetting Text

I For the most part, you can just type your text normally.

. LaTeX code . Output


Words are separated by one Words are separated by one
or more spaces. or more spaces.

Paragraphs are separated by Paragraphs are separated by


one or more blank lines. one or more blank lines.

I Space in the source file is collapsed in the output.

. LaTeX code . Output


The rain in Spain The rain in Spain falls
falls mainly on the plain. mainly on the plain.
Typesetting Text: Caveats
Typesetting Mathematics: Dollar Signs
Dollar Signs - Continued

Another important thing to remember is that single dollar signs


are used for in-line formulas and double dollar signs or \[ ... \]
are used for display style.

Example code:
Use single dollar signs for in line display of
$f(x)=x^2\cdot \sin x$.

Use double dollar signs or \[ \] for display


style of function:

$$f(x)=x^2\cdot \sin x$$


\[ f(x)=x^2 \]
Dollar Signs - Continued

LaTeX output:

Use single dollar signs for in line display of f (x) = x 2 · sin x.


Use double dollar signs or \[ \] for display style of function:

f (x) = x 2 · sin x
f (x) = x 2

Notice that when display style environment is used, output is


centered.
Typesetting Mathematics: Notation
Typesetting Mathematics: Displayed Equations
Interlude: Environments

I Commands \begin and \end are used to create many different


environments
I Here are examples of itemize and enumerate environments
Interlude: Packages
Below is the list of all the LaTeX packages included in Slader
compiler with brief descriptions:
I amsmath
Includes various elements for improving the printed
mathematical formulas such as \equation and \align.
I amssymb
Includes various symbols that can be added in math mode,
such as \cap (∩) and \cup (∪).
I wasysym
Includes various characters that come from the wasy fonts,
such as \Box (2) and \checked ().
I textcomp
Includes commands that make multiple column writing
possible.
I array
Includes implementations of the array and tabular
environments.
Interlude: Packages
I arcs
Includes two commands, \overarc and \underarc .
I polynom
Includes various commands for manipulating polynomials, such
as \polylongdiv{}{} (long division) and
\polyhornerscheme[ ]{} (synthetic division).
I cancel
Includes commands for canceling out terms (usually in
a·b
fractions),  .
a
I enumerate
Includes enumerate environment.
I dcolumn
Includes various types of column formatting.
Documentation for each package with additional explanations can
be found on https://ctan.org/ .
Typesetting Mathematics: Examples with amsmath

I Use equation* (”equation-star”) for unnumbered equations

I LATEX treats adjacent letters as variables multiplied together,


which is not always what you want. amsmath defines
command for many common mathematical operators

I You can use command \text to output any mathematical


function like sin, cos, Cov, etc.
Typesetting Mathematics: Examples with amsmath
Example #1 - Command \overset
It can be used for short descriptions of steps. For example, when
finding derivative of a function.
Code:
\begin{align*}
(\log (x^2\sin x))’&=\dfrac{1}{x^2\sin x}
\overset{\text{Chain rule}}{\cdot}(x^2\sin x)’\\
&=\dfrac{1}{x^2\sin x}\cdot
\overset{\text{Product Rule}}{((x^2)’\cdot \sin x
+ x^2\cdot (\sin x)’)}
\end{align*}

LaTeX output:
1 Chain rule
(log(x 2 sin x))0 = · (x 2 sin x)0
x 2 sin x
Product Rule
1
= 2 · ((x 2 )0 · sin x + x 2 · (sin x)0 )
x sin x
Example #2 - Command \overset
It can also be used to add detailed explanations later.
Code:
\begin{align*}
\dfrac{1}{\csc^2x}+\cos^2x&\overset{(1)}{=}
\sin^2x+\cos^2x\\
&\overset{(2)}{=}\color{red}{1}
\end{align*}

Explanations:

(1)\hspace{0.2cm}By definition,
$\dfrac{1}{\csc^2 x}
=\dfrac{1}{\frac{1}{\sin^2x}}=\sin^2x$

(2)\hspace{0.2cm}Pytagorean rule:$\sin^2x+\cos^2x=1$
Example #2 - Continued

LaTeX output:
1 (1)
2
+ cos2 x = sin2 x + cos2 x
csc x
(2)
=1

Explanations:
1 1
(1) By definition, 2
= 1 = sin2 x
csc x
sin2 x
(2) Pytagorean rule: sin2 x + cos2 x = 1

Additional commands used:


I \color{red}→ change color of the output to red
I \hspace{x cm}→ add horizontal spacing of x centimeters
Example #3 - Commands \overbrace and \underbrace
Example Code:
\begin{align*}
\overbrace{\int x^2e^xdx}^{\boxed{\begin{smallmatrix}
\text{Integration by parts}\\
u=x^2\quad du = 2x\\
dv = e^x\quad v = e^x
\end{smallmatrix}}}&=x^2e^x - \int 2xe^xdx\\
&=x^2e^x -2\underbrace{\int xe^xdx}_{\boxed{
\begin{smallmatrix}
\text{Integration by parts}\\
u=x\quad du = 1\\
dv = e^x\quad v = e^x
\end{smallmatrix}}} +C\\
&=x^2e^x-2(xe^x-\int 1\cdot e^xdx)+C\\
&=x^2e^x-2(xe^x-\int e^xdx)+C\\
&=\boxed{\color{blue}{e^x(x^2-2x-2)+C}}
\end{align*}
Example #3 - Continued
LaTeX output:

Integration by parts
u=x 2 du=2x
dv =e x v =e x
z
Z }| { Z
2 x
x e dx = x 2e x − 2xe x dx
Z
= x 2e x − 2 xe x dx +C
| {z }
Integration by parts
u=x du=1
dv =e x v =e x
Z
2 x x
= x e − 2(xe − 1 · e x dx) + C
Z
2 x x
= x e − 2(xe − e x dx) + C

= e x (x 2 − 2x − 2) + C
Example #3 - Further explanations

As seen in the example we can use \overbrace or \underbrace


command to write one group of text/formulas over/below another
group of text/formulas.
It is best used when explaining some steps. This is a very neat tool
when you want to describe:
I differentiation rules that were used when derivative was
evaluated
I rules used when simplifying some logarithmic expression or
when working with powers/roots
Also, in this example we used:
I \quad: adds white space (like tab)
I smallmatrix: like a regular matrix, just smaller
I \boxed: draws box around the output, very good for writing
formulas or final result
Example # 4 - Gather

Another way to show equations in the center of the field is to use


gather environment. Use \begin {gather} to start the environment
and \end {gather} to close the environment. To avoid automatic
numbering of equations use gather* instead of gather.

Example Code:
\begin{gather*}
3x+4y=17\\
4y=17-3x\\
y=\frac{17-3x}{4}
\end{gather*}
Example #4 - Continued

LaTeX output:

3x + 4y = 17
4y = 17 − 3x
17 − 3x
y=
4

As you can see, all rows written inside gather environment are
pushed towards the middle.
Example # 5 - Matrices
Below are examples of different types of matrices.
LaTeX code Output
\begin{matrix}
a_{11}&a_{12} \\ a11 a12
a_{13}&a_{14} a13 a14
\end{matrix}

\begin{bmatrix}
a_{11}&a_{12} \\
 
a11 a12
a_{13}&a_{14} a13 a14
\end{bmatrix}

\begin{Bmatrix}
a_{11}&a_{12} \\
 
a11 a12
a_{13}&a_{14} a13 a14
\end{Bmatrix}
Example # 5 - Continued
LaTeX code Output
\begin{pmatrix}
a_{11}&a_{12} \\
 
a11 a12
a_{13}&a_{14} a13 a14
\end{pmatrix}

\begin{Vmatrix}

a_{11}&a_{12} \\ a11 a12

a_{13}&a_{14} a13 a14
\end{Vmatrix}

\bigl[ \begin{smallmatrix}
a_{11}&a_{12} \\  a11a12

a_{13}&a_{14} a13 a14

\end{smallmatrix}\bigr]
Example # 5 - Further explanations

In previous examples we saw that the general form of matrix is:

\begin {*matrix}
cell 1 & cell 2 & cell 3 \\
cell 4 & cell 5 & cell 6
\end {*matrix}

• Choose b, B, p, V or nothing instead of * for the type of


matrix you want to produce
• We use delimiters & to separate columns and \\ to separate
rows
• smallmatrix comes without brackets by default; we have to
add brackets ourselves
Example # 6 - Colors
We can change the color of the output. Color can be changed of
both plain text and math outputs.
LaTeX code Output
\color{red}{
\text{Some text.}} Some text.

\color{blue}{
$f(x)=\sin (3x)$} f (x) = sin(3x)

\color{orange}{
x2 x
$\frac{x^2}{3x}=\frac{x}{3})$} 3x = 3

List of all colors that can be used within Slader LaTeX compiler
can be found here:
https://en.wikibooks.org/wiki/LaTeX/Colors
Using a specific color is case sensitive, so something like
\color{maroon} is not going to work.
Example # 7 - Fractions
Basically, there are two types of fractions that are most commonly
used. These are \frac and \dfrac.
The main difference here is that frac reduces the font size in
numerator and denominator where dfrac keeps the same font. The
best way is to use dfrac when you have complicated expressions in
numerator and/or denominator and use frac otherwise.

LaTeX code Output


$\dfrac{x^3}{x^2}=x$ x3
=x
x2
$\frac{\sin x}
sin x
{\cos x}=\tan x$ cos x = tan x

$\dfrac{\frac{x^3}{x}} x3
{\frac{2x+1}{3x}}= x 3x 4
2x+1
= 2x 2 +x
\frac{3x^4}{2x^2+x}$ 3x
Example #8 - Brackets
Here is the correct way brackets should be used inside LaTeX
code. This way, brackets are automatically sized up to appropriate
expression inside them.

LaTeX code Output


\left ( ... \right ) (...)

\left \| ... \right \| k...k

\left \{ ... \right \} {...}

\left \lfloor ... \right \rfloor b...c

\left | ... \right | |...|

\left \lceil ... \right \rceil d...e


Final comments

Here is the list of tips & tricks that can be useful:

• Use variables inside math environment as default (ex.


$ a, b, x, y $) so they are displayed as italic and use units and
everything else inside \text{} (ex. $ \text{ m/s } $)
• Write final answer in different color and/or with a box around
it (ex. $ \boxed{\color{Maroon}{f(x)=\sin(x)}} $)

Вам также может понравиться