GLM 1 Marksheet
GLM 1 Marksheet
GLM 1 Marksheet
HSTS204\HSTS331\HSTS401
TEX is the typesetting language written by Donald Knuth. He wrote a format of TEX called
Plain TEX, but many people find Plain TEX complicated, so Leslie Lamport wrote a format of
TEX called LaTex to make it a bit easier to use. You can think of LaTex as a go-between
converting your instructions into TEX. These notes mostly use the term LaTex, even if the
matter is more general to TEX, to avoid complicating matters. Some error messages you may see
will be LaTex messages, some will be TEX messages. The aim of these notes is to introduce
LaTex to a non-technical person. LaTex is excellent for producing professional looking
documents; however it is a language not a word processor, so it can take a bit of getting used to,
particularly if you have never had any experience using programming languages. LaTex does
take a while to learn, so why should you use it? Here are a few reasons but it is not an exhaustive
list:
(i) LaTex is far better at typesetting mathematical equations than word processors.
(ii) One can concentrate on writing the document, rather than worrying about how it will
look. It also means that if, after having written a 200 page document, I then find that I
need to change all the figure captions so that they are labeled “Fig” instead of
“Figure”, all I need to do is edit a single line, rather than going through 200 pages to
individually edit every single figure caption.
(iii) LaTex makes it very easy to cross-reference chapters, sections, equations, figures,
tables etc.
(iv) It also makes it very easy to generate a table of contents, list of figures, list of tables,
index, glossary and bibliography.
(v) You don’t need to worry about numbering anything, as this is done automatically,
which means that you can insert new sections or swap sections around without having
to worry about updating all the section numbering etc.
(vi) When you are editing a document using a word processor, the word processor has to
work out how to reformat the document every time you type something. If you have a
large document with a great many inserted objects (such as figures and equations), the
response to keyboard input can become very slow. You may find that after typing a
few words you will have to wait until the computer catches up before you can see
what you have typed. With LaTex you type in your code using an ordinary text editor.
The document doesn’t get formatted until you pass it to LaTex, which means that you
are not slowed down by constant reformatting. Lastly, there’s the fact that LaTex
follows certain typographical rules, so you can leave most of the typesetting to
LaTex. You rarely need to worry about minor things such as inter-sentence spacing.
The default is English spacing, but if you have a publisher who disapproves of this,
you can switch it off with a single command.
These points may seem minor but they all contribute towards the impact of the entire document.
When writing technical documents, the presentation as well as the content is important. All too
often examiners or referees are put off reading a document because it is badly formatted. This
provokes an immediate negative reaction and provides little desire to look favorably upon your
work.
Every time you want to create or edit a LaTex document, there are three basic steps you will
always need to follow:
1. A text editor (to perform Step 1). For example Vim, Emacs or Gedit.
2. The TEX software (to perform Step 2). If you don’t already have TEX on your machine,
you will need to install it. You can download and install free TEX distributions, such as
TeX Live, MiKTeX or MacTeX, from the Internet. There is also proTeXt, an
enhancement of MiKTeX that aims to be an easy-to-install TEX Distribution.
3. A PDF viewer (to perform Step 3). For example Adobe Reader, Sumatra, Evince or
Okular.
Definitions
LaTex is a language, so you can’t simply start typing and expect to see your document appear
before your very eyes. You need to know a few things before you can get started, so it’s best to
define a few terms first.
Source Code
The source code consists of all the text and LaTex commands that makeup an entire document.
The source code is typed in using a text editor, and saved with the file extension .tex. The source
code may be contained in just one file, or it might be split across several files.
Output File
The LaTex application reads in your source code and creates the typeset document, the output
file. From Source Code to Typeset Output, you need to select the “PDFLaTeX” item from the
drop-down list. If you are using TeXnicCenter, select the “LaTeX=>PDF” build profile. If you
are using WinEdit, when you want to build your document click on the button marked
“PDFLaTeX” rather than the one marked “LaTeX”. If you are using a terminal or command
prompt, use the command pdflatex rather than latex. Tex and subsequently LaTex originally
created DVI (DeVice Independent) files instead of PDF files. However, although there are free
DVI viewers, not many people have them installed, so it’s really only Tex users who can read
them. Also, you can’t embed image files in a DVI file or have fancy effects, such as rotation.
Instead, people can use Tex/LaTex to create a DVI file and then use an application to convert the
DVI file to PostScript. These days PDF is the preferred platform-independent format, and with
the advent of PDFTEX, modern Tex/LaTex users can directly create PDF documents rather than
going through the DVI route. Some people still prefer to create DVI files as an intermediate step,
particularly if they want to embed PostScript instructions.
Auxiliary Files
When LaTex creates your output file, it not only creates a PDF file but also creates other
associated files. The most common of these are the log file, which has the extension .log, and the
auxiliary file, which has the extension .aux. The log file contains a transcript of the most recent
LaTex run. It lists all the files that have been loaded, including the class file and any packages
that your document has used. Error messages, warnings and general information messages are
also written to the log file as well as the document statistics. You can delete this log file if you
like. It will be created again the next time you run LaTex.
The auxiliary file contains all the information needed for cross-referencing. This is needed to
ensure all your cross-references are up-to-date. You can delete this file, but you will need at least
two LaTex runs to ensure your cross-references are correct the next time you create your output
file. Other files that may be created include the table of contents file (.toc), the list of figures file
(.lof) and the list of tables file (.lot). Some class files or packages create additional files. If your
operating system hides file extensions, you might want to switch off this behavior, if possible, to
make it easier to distinguish between all the various files.
Commands
A command is used to tell LaTex to do a particular thing at that point in the document. These are
the basic forms a command can take:
1. A Control Word.
2. A Starred Command
Some commands have variants that are indicated by an asterisk at the end of the name. For
example, \chapter makes a numbered chapter whereas \chapter* makes an unnumbered chapter.
A starred command is the version of the command with the asterisk.
3. A Control Symbol.
This is a backslash followed by a single non-alphabetical character. For example \% will print a
percent symbol. Spaces are not ignored after this type of command, for example 17.5\% VAT
Input will produce “17.5% VAT” Output. It’s also possible to have starred forms of control
symbols. For example \\ forces a line break, if it’s not followed by an asterisk a page break is
allowed at that line break, but if it is followed by an asterisk \\* no page break is allowed at that
line break. (If a page break is needed, it will be made at the end of the previous line instead.)
4. Character Sequence.
Some special sequences of characters combine to form an instruction. For example the sequence
of symbols! is the command to produce the upside down exclamation mark¡
5. An Internal Command.
This is like the first type, a control word, but the @ character appears in the command name (for
example\c@section) however internal commands should only be used in class files or packages.
The @ symbol takes on a special meaning when a file is included using \documentclass (a class
file) or \usepackage (a package). For example, in a class file or package \c@section is an internal
representation of the section counter, whereas in a tex file \c@section is interpreted as the
command \c(the cedilla accent command) that takes the character @ as its argument, followed by
section, which produces the rather odd looking@¸section. Don’t be tempted to use internal
commands until you have first grasped the basics. Be warned!
A segment of code may be grouped by placing it within curly braces {and}. Most commands
that occur within a group will be local to that group. For example, \bfseries changes the font
weight to bold, so the following segment of code with Input: Here is some text. {This
text \bfseries is in a group.} Here is some more text; will appear in the typeset document looking
like: “Here is some text. This text is in a group. Here is some more text”. Output As can be seen,
the font change only stays in effect until it reaches the end of the group (signified by the closing
curly braces). For a command to be in the same scope as another command, both commands
must be within the same group. For example, in the following input; \bfseries and \itshape are in
the same scope: {\bfseries Some bold \itshape and italic text} Input. But the input below, they
are in different scopes: {\bfseries Some bold text} {\itshape and some italic text}.
Some commands take one or more arguments. This provides a way to give LaTex additional
information so that it is able to carry out the command. There are two types of arguments:
mandatory and optional.
Mandatory Arguments
Mandatory (or compulsory) arguments are arguments that have to be specified. Examples:
1. If you want a footnote, you need to use the \footnote command, which has a mandatory
argument that specifies the contents of the footnote. Like this Input: Here is a
footnote. \footnote{This is the footnote text.} The Output is “Here is a footnote.2.4
2. If you want to start a new chapter, you need to use the \chapter command, but you also need
to tell LaTex the title of this new chapter. So the \chapter command takes one mandatory
argument that specifies the title. For example, the following code: \chapter{Some
Definitions}.
3. The command \textbf typesets its argument in a bold font (as opposed to the
declaration \bfseries which switches to a bold font.) For example, the following
code: \textbf{Some bold text.} produces the output “Some bold text”.
Notes:
1. LaTex takes the first non-space object following the command name as the argument, which
is why in the above examples the arguments have to be grouped. Suppose the last example
above didn’t have a group, so instead the code was: \textbf Some bold text, then only the “S”
would be the argument because it’s the first object following the command, in which case the
output would look like: Some bold text.
2. If you want the argument to be blank, use empty braces: {}. For example, suppose you want
to have a chapter without a title you would need to do: \chapter{}
Optional Arguments
Some commands may have one or more optional arguments. Unlike mandatory arguments,
optional arguments must always be enclosed in square brackets [ ]. Example: The command \\
ends a line. So the following segment of code: Line one\\ Line two will produce the following
output:
“Line one
Line two”.
However the \\ command also has an optional argument that allows you to specify how big the
gap between the two lines should be. So the following segment of code: Line one\\[1cm]Line
two, will produce the following output:
“Line one
Line two”.
Incidentally, note the difference between the previous example, and the following example: Line
one\\{[1cm]} Line two. Input ↑
“Line one
[1cm] Line two”.
In this example the [1cm] has been placed inside a group, so it is no longer considered to be an
optional argument, and since the command \\ does not take a mandatory argument, the [1cm] is
simply interpreted as ordinary text.
Environments
\begin{⟨env-name⟩}
And
\end{⟨env-name⟩}
Where ⟨env-name⟩ is the name of the environment. The block of code is then formatted in a
method specific to that environment. For example, the \bfseries environment will typeset the
contents of the environment in a bold font. The following code:
\begin{bfseries}
Here is some bold text.
\end{bfseries}
Will appear in the typeset document looking like: Here is some bold text. Some environments
also supply commands that may only be used within that environment. Example: The itemize
environment provides a command called \item so that you can specify individual items within an
unordered list as in the following input code:
Shopping List:
\begin{itemize}
\item Cabbages
\item Bananas
\item Apples
\end{itemize}
The above will produce the following output:
Shopping List:
•Cabbages
•Bananas
•Apples
1. Missing out the backslash \ at the start of one or more of the commands
2. Using a forward slash / instead of a backslash \.
3. .Forgetting \end{document}.
4. Misspelling “document” (in \begin{document} and \end{document}).
5. Missing a closing brace }.
Packages
Packages are files with the extension .sty that either define new commands or redefine existing
commands. They’re like a type of add-on or plug-in. Most of the commonly used packages
should have been installed when you installed your TEX distribution.
Most packages come with documentation that can be accessed using the texdoc application.
Packages are loaded in the preamble (after \documentclass and before \begin{document})
using \usepackage[⟨option list⟩]{⟨package⟩}; where ⟨package⟩ is the name of the package and
⟨option list⟩ is a list of comma-separated options. For example, to load the package graphicx
with the draft option: \usepackage[draft]{graphicx}
Any applicable class options are also passed to packages, so in
\documentclass[draft]{scrartcl}
\usepackage{graphicx}
The draft option is set for both the scrartcl class and the graphicx package. You can specify
more than one package in the argument of \usepackage, where each package name is separated
by a comma. For example:
\usepackage{amsmath,amsfonts}
Aligning Material in Rows and Columns
Text can be aligned in rows and columns using the tabular environment. \begin{tabular}[⟨pos⟩]
{⟨column specifiers⟩}
This environment has a mandatory argument ⟨column specifiers⟩ that specifies how to align each
column. Within ⟨column specifiers⟩, there must be a specifier for each column. The three basic
are: r (right aligned), l (left aligned) and c (centred). Example: Three columns (left, centred,
centred):
\begin{tabular}{lcc}
Another Example: Four columns (left, centred, centred, right):
\begin{tabular}{lccr}
The r, l and c specifiers don’t allow line breaks or paragraphs within a cell. It’s not a good idea
to have too much text in a cell, but if it’s required you can use p {⟨width⟩} which indicates a
paragraph cell of the given width. Example: Three columns (paragraph of width 1 in, centred,
right):
\begin{tabular}{p{1in}cr}
The ampersand character & is used to separate column entries. Rows are separated using: \\
[⟨vertical space⟩] where ⟨vertical space⟩ is extra vertical spacing between rows, if required.
There is also a longer equivalent: \tabularnewline. Example: Let’s have two columns, the first
left justified and the second right justified:
\begin{tabular}{lr}
Video & 8.99\\
CD & 9.11\\
DVD & 15.00\\
Total & 33.10
\end{tabular}
Or simply:
\begin{tabular}{lr} Video & 8.99\\ CD & 9.11\\ DVD & 15.00\\ Total & 33.10 \end{tabular} and
still have got the same result, but now the code is easier to read. Entries form implicit grouping,
so declarations made within a tabular environment only have an effect up to the next & or \\.
Example:
\begin{tabular}{lr} Video & 8.99\\ CD & 9.11\\ DVD & 15.00\\ \bfseries Total & 33.10
\end{tabular}
Let’s add an extra column and a header row:
\begin{tabular}{lrr} Item & ex VAT & inc VAT\\ Video & 8.99 & 10.56 \\ CD & 9.11 & 10.70 \\
DVD & 15.00 & 17.63 \\ \bfseries Total & 33.10 & 39.89 \end{tabular}
Spanning Columns.
This can be done using the command:
\multicolumn{⟨cols spanned⟩}{⟨col specifier⟩}{⟨text⟩}
The first mandatory argument ⟨cols spanned⟩ is the number of columns you want to span, the
second argument ⟨col specifier⟩ indicates how to align this column spanning entry, the third
argument ⟨text⟩ indicates what should go in this entry. Note that ⟨col specifier⟩ should only have
a single column specifier, such as {c} or {r}. We can use \multicolumn to modify an earlier
example as follows:
\begin{tabular}{lrr} & \multicolumn{2}{c}{Price(\pounds)}\\ Item & ex VAT & inc VAT\\ Video
& 8.99 & 10.56 \\ CD & 9.11 & 10.70 \\ DVD & 15.00 & 17.63 \\ \bfseries Total & 33.10 &
39.89 \end{tabular}
Here we are spanning two columns, so the first argument to \multicolumn is {2}, we want the
entry centred, so the second argument is {c} and the text to go in this entry is simply
{Price(\pounds)}. The \multicolumn command can also be used to override the alignment of
individual entries. Consider the following example:
\begin{tabular}{lrr} & Year1 & Year2 \\ Travel & 100,000 & 110,000\\ Equipment & 50,000 &
60,000 \end{tabular}
In this example, the headers “Year1” and “Year2” would look better centred, but the rest of the
entries in the second and third columns look best right aligned. We can use \multicolumn to span
just one column, and use the second argument of \multicolumn to override the column
specification:
\begin{tabular}{lrr} & \multicolumn{1}{c}{Year1} & \multicolumn{1}{c}{Year2}\\ Travel &
100,000 & 110,000\\ Equipment & 50,000 & 60,000 \end{tabular}
Graphics
To insert an image file into your document, you first need to specify that you want to use the
graphicx package. So the following must go in the preamble:
\usepackage{graphicx}
The image can then be included in your document using the command \includegraphics[⟨key-val
options⟩]{⟨filename⟩} where ⟨filename⟩ is the name of your image file without the file extension,
and ⟨key-val options⟩ is a comma-separated list of options that can be used to change the way the
image is displayed. The optional argument ⟨key-val options⟩ should be a comma-separated list of
⟨key⟩=⟨value⟩ pairs. Common options are:
angle =⟨x⟩ rotate the image by x∘ anticlockwise.
width =⟨length⟩ scale the image so that the width is ⟨length⟩. (Remember to specify the units.)
height =⟨length⟩ scale the image so that the height is ⟨length⟩.(Remember to specify the units.)
scale =⟨value⟩ scale the image by ⟨value⟩
trim =⟨l⟩ ⟨b⟩ ⟨r⟩ ⟨t⟩ specifies the amount to remove from each side. For
example \includegraphics[trim=1 2 3 4]{shapes}
crops the image by 1bp from the left, 2bp from the bottom, 3bp from the right and 4bp from the
top.
Figures are created using the figure environment. \begin{figure}[⟨placement specifiers⟩]. This
environment may contain one or more captions (specified with the \caption command) but page
breaks are not allowed in the contents of a figure environment.
\begin{figure}[htbp] \includegraphics{shapes} \caption{Some Shapes} \end{figure}
The picture needs to be centred by using the \centering declaration.
\begin{figure}[htbp]
\centering
\includegraphics{shapes}
\caption{Some Shapes}
\end{figure}
The \caption command generates a number, so we can cross-reference it with \ref and \label.
First, let’s label the figure: ↑
\begin{figure}[htbp]
\centering
\includegraphics{shapes}
\caption{Some Shapes}
\label{fig:shapes}
\end{figure}
Now we can reference it by Figure~\ref{fig:shapes}. (We use ~ to make an unbreakable space.)
Tables
Tables are produced in much the same way as figures, except that the table environment is used
instead; \begin{table}[⟨placement specifiers⟩]. Tables typically have the caption at the top of the
table. Page breaks are not permitted in the table environment. Example:
\begin{table}[htbp] \caption{A Sample Table} \label{tab:sample} \centering \begin{tabular}{lr}
Item & Cost\\ Video & 8.99\\ CD & 9.99\\ DVD & 15.00 \end{tabular} \end{table}
Again, the \centering declaration is used to centre the tabular environment.
Mathematics
LaTex is particularly good at typesetting mathematics. In order to use any of the maths
commands we need to be in one of the mathematics environments. There are two basic types of
mathematics: in-line maths and displayed maths.
1. In-line maths is mathematics that occurs within a line of text, for example: The variable x
is transformed by the function f(x).
2. Displayed maths is mathematics that occurs on a line of its own. For example: A
polynomial is a function of the form :
n
f (x)=∑ ai xi
i=0
The maths environments switch to LaTex’s “math mode”, which uses specialist maths fonts and
spacing rather than just using an italic font. If you want to typeset any mathematics, use the
amsmath package: \usepackage{amsmath}.
This patches some existing LaTex commands and environments and also provides many useful
additions.
In-Line Mathematics
In-line mathematics is created using the math environment. (“math” not “maths”). Example:
There is an even shorter notation: The special character $ is equivalent to both \begin{math}
and \end{math}:
Note: you should always make sure you are in maths mode to typeset any variables (such as x, y,
z), as this will ensure that the correct maths fonts are used, as well as the appropriate spacing.
Similarly, don’t use $ as a shortcut for an italic font. For example:
Displayed Mathematics
One-line unnumbered displayed mathematics can be created using: \[⟨maths⟩\] where ⟨maths⟩ is
the mathematics to be displayed. Example:
The equation environment provides something similar to \[ \], except that the equation is
numbered. Modifying the above example:
Equation numbers are usually given in parentheses, which can be done using:
Equation~(\ref{eqn:linear}). The amsmath package provides a convenient
shortcut: \eqref{⟨label⟩}. So the above can be written as: Equation~\eqref{eqn:linear}
Both the equation environment and \[...\] are only designed for one line of maths. Therefore you
must not have any line breaks or paragraph breaks within them. The following will cause an
error:
\begin{equation}
f(x) = mx + c
\end{equation}
Either remove the blank lines or comment them out:
\begin{equation}
%
f(x) = mx + c
%
\end{equation}
The amsmath package provides the align and align* environments for aligned equations. The
starred version doesn’t number the equations. These environments provide pairs of left- and
right-aligned columns. Just as with the tabular environment, use & to separate columns and \\ to
separate rows. Unlike the tabular environment, there is no argument as the column specifiers are
predefined. Another difference is that no page breaks can occur in the tabular environment, but
it’s possible to allow a page break in align or align* using \displaybreak[⟨n⟩] immediately before
the \\ where it is to take effect. The optional argument is a number from 0 to 4 indicating the
desirability to break the page (from 0 the least to 4 the most). If you want to mix numbered and
unnumbered rows, you can use \notag to suppress the numbering for a particular row in the align
environment. This command must go before \\ at the end of the row. The default equation
numbering can be overridden for a particular row using: \tag{⟨tag⟩} where ⟨tag⟩ is the
replacement for the equation number. Don’t use the eqnarray or eqnarray* environments.
They’re obsolete. Example (Unnumbered):
\begin{align*}
y &=2x+2\\
&=2(x+1)
\end{align*}
Note that the equals sign is placed at the start of the second column, after the ampersand &. This
ensures the correct amount of spacing on either side. If the first line of the above equation was
changed to: y =& 2x + 2\\
There wouldn’t be enough space on the right of the equal sign.
Example (One Row Numbered):
\begin{align}
y &= 2x + 2\notag\\
&= 2(x+1)
\end{align}
Example (Four Columns):
\begin{align*}
y &= 2x + 2 & z &= 6x + 3\\
&= 2(x+1) & &= 3(2x+1)
\end{align*}
As with equation, you can cross-reference individual rows of an align environment, but you must
remember to put \label before the end of row \\ separator. You can reference a row in the align*
environment if you have assigned it a tag with \tag, but don’t try labeling a row in the align
environment where the numbering has been suppressed with \notag.
Example (Cross-Referenced): This example has two numbered equations in an align
environment, both of which are labelled and referenced:
The function $f(x)$ is given in Equation~\eqref{eq:fx}, and its derivative $f’(x)$ is given in
Equation~\eqref{eq:dfx}.
\begin{align}
f(x) &= 2x + 1 \label{eq:fx}\\
f’(x) &= 2 \label{eq:dfx}
\end{align}
Recall the command \text{⟨text⟩} from the previous section. This can be used within cells of the
align and align* environments, but the amsmath package also provides \intertext{⟨text⟩} which
can be used for a line of interjection between the rows. This command may only go right after \\.
Example
\begin{align*}
y &= 2x + 2\\
\intertext{Using the distributive law:}
&= 2(x+1)
\end{align*}
Greek Letters
Greek letters that differ from the corresponding Roman letters are obtained by placing a
backslash in front of the name, for example, \theta. There are also some variants of certain
symbols, such as \vartheta as opposed to \theta.
3. Mandatory arguments only consisting of one character don’t need to be grouped, so the
above code can also be written as:
This is simpler than the first two examples. However it’s a good idea to be in the habit of
always using braces in case you forgot them when they’re needed. All three of the above
examples produce the same output. Notice how the subscript gets tucked under the slope of
the Y in:
$$Y_{1}^{2} $$
Compare with:
$$Y{}_{1}^{2}$$
Example (Nested)
Subscripts and superscripts can also be nested (note that it is now necessary to group the
argument to the superscript command):
$$f(x) = e^{x_1}$$
This example isn’t quite right as e isn’t actually a variable and shouldn’t be typeset in italic.
The correct way to do this is:
$$f(x) = \mathrm{e}^{x_1}$$
If you are going to use e a lot, it will be simpler to define a new command to do this. The
definition should go in the preamble: \newcommand{\e}{\mathrm{e}}. Then in the document:
Take care when nesting subscripts or superscripts. The following x _1_2 will give a Double
subscript error.
Fractions
Fractions are created using the command \frac{⟨numerator⟩}{⟨denominator⟩}. The amsmath
package also provides the command \cfrac[⟨pos⟩]{⟨numerator⟩}{⟨denominator⟩} which is
designed for continued fractions. The optional argument <pos> can be used for left (l) or right
(r) placement of any of the numerators (The default is centred). Example:
A simple fraction:
$$\frac{1}{1+x}$$
$ \frac{1}{1+x} $
Example (Nested):
$$\frac{1+\frac{1}{x}}{1+x+x^2} \]$$
Roots
Roots are obtained using the command \sqrt[⟨order⟩]{⟨maths⟩} without the optional argument
⟨order⟩ it will produce a simple square root. Cubic roots etc. can be obtained using the optional
argument. Examples:
1. A squareroot:
$$\sqrt{a+b}$$
2. A cubic root:
$$\sqrt[3]{a+b}$$
3. An nth root:
$$\sqrt[n]{a+b}$$
Mathematical Symbols
Relational Symbols
symbolsdependsonwhethertheyareindisplayedmathsorin-linemaths.
Example (Displayed Summation and Product): The
limitsofsummationsandproductsareplacedaboveandbelowthe symbolindisplayedmaths: ↑ Input \
[ f(x) = \sum_{i=1}^{n} x_i + \prod_{i=1}^{n} x_i \]
Example (In-line Summation and Product):
Thelimitsofsummationsandproductsareplacedtotherightofthesymbol inin-linemaths: ↑ Input In a
line of text: \begin{math} f(x) = \sum_{i=1}^{n} x_i + \prod_{i=1}^{n} x_i \end{math}
↓ Input
Inalineoftext:f(x)=∑︀n i=1xi+∏︀n i=1xi OutputMultiline Sub- or Superscripts
Arrays
Mathematical structures such as matrices and vectors require elements to be arranged in rows
and columns. Just as we can align material in rows and columns in text mode using the tabular
environment, we can do the same in maths mode using the array environment. The array
environment has the same format as the tabular environment, however it must be in maths mode.
Example:
$$\begin{array}{rrr}
0 & 1 & 19\\
-6 & 10 & 200
\end{array}$$
Example (Adding Delimiters):
$$\left(
\begin{array}{rrr}
0 & 1 & 19\\
-6 & 10 & 200
\end{array}
\right)$$
A vertical rule can be added using | in the column specifier. For example:
$$\left(
\begin{array}{rr|r}
0 & 1 & 19\\
-6 & 10 & 200
\end{array} \right) $$
$$ f(x) =
\left\{
\begin{array}{rl}
-1 & x < 0\\
0 & x = 0\\
+1 & x > 0
\end{array}
\right.$$
This can be rewritten more compactly using the amsmath cases environment:
$$f(x) =
\begin{cases}
-1 & x < 0\\
0 & x = 0\\
+1 & x > 0
\end{cases} $$
The amsmath package provides some convenient environments to typeset matrices: pmatrix,
bmatrix, Bmatrix, vmatrix andVmatrix.These are similar to the array environment except there is
no argument, and they add (respectively) ( ), [], {},||∧‖‖delimiters. Example:
\begin{equation}
\begin{pmatrix}
a & b\\
c&d
\end{pmatrix}
\end{equation}