%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This is a sample LaTeX document. Hopefully there are enough
% introductory tips here that you can get started with some
% rudimentary documents.
%
% The hardest part of getting started with LaTeX is getting used
% to the fact that you are typing in a plain text document and
% that document gets transformed (the word is "compiled") into a
% .pdf document. It feels like computer programming at first
% but you'll get used to it. In writeLaTeX you can make small
% changes and observe how they affect the output.
%
% It is important to understand the different between "the stuff
% that you type" and "the stuff that shows up in the .pdf file."
% I will call the document in which you type the "input" and I
% will call the created .pdf document the "output." The input
% lives in a document with a .tex extension and contains "plain"
% text. The LaTeX "compiler" then does its magic and turns that
% .tex file into the output. At various points I will try to
% explain that magic by trying to explain what bits of that input
% tell the compiler to do.
%
% (Note: If you think about it, "compiling" is kind of like a
% function whose inputs are plain text documents and whose outputs
% are .pdf documents. Actually...that's exactly what it is.)
%
% The first thing to notice is that if the % character appears at
% any point in a line then anything after that character will
% not affect the output. Lines which start with the % character
% will be where I put my comments about the input.
%
% LaTeX uses many, many "commands." Commands are the things which
% start with the \ character. (Note: the \ character is very
% important to LaTeX and if you try to use it to create a backslash
% in the output then you will cause it problems.) Some commands
% have one or more "argument." A command might look like
% \command[...optional argument(s)...]{argument1}{argument2}
% I will try to explain commands and arguments as I use them.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Every single LaTeX document in the world MUST contain the
% \documentclass command. It tells the compiler what the basic
% layout of the document should be. Using "article" for the
% argument, as we do here, summons a rather basic structure.
% This is sufficient for most small documents
\documentclass{article}
% Everything between \documentclass{article} and \begin{document}
% is called the "preamble." Nothing in the preamble will be
% printed directly into the output, but there are several
% commands in the preamble which greatly influence the output.
% LaTeX is very powerful and has a lot of utilities. It is
% inefficient for the compiler to load all of those utilities
% every time it compiles documents because most documents are
% simple. Instead, there are several "packages" which allow the
% user to specify various bits of LaTeX capabilities that he or
% she wants to use. These packages are loaded by using the
% \usepackage command in the preamble. I won't explain these
% four packages in depth, but if you're typing a document which
% contains mathematics then all four of them could be useful.
% (In general, there is no harm in loading packages that aren't
% used.)
\usepackage[english]{babel} % babel specifies the language
\usepackage[utf8]{inputenc} % this one is...confusing
\usepackage{amsmath} % amsmath allows many useful math tools
\usepackage{graphicx} % graphicx handles graphics
% The following is an optional package but I think it makes
% things look better. "1in" is margin. Delete this line to see
% the default LaTeX margins.
\usepackage[margin=1in]{geometry}
% The next three commands take arguments which get printed by
% the \maketitle command. They should be self-explanitory.
\title{MATH 112 Sample Project Template - University of Oregon}
\author{First Name \\ Second Name \\ Third Name \\ Fourth Name}
\date{May 2, 2014} % \today will print the compile date
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A small note about writeLaTeX:
% writeLaTeX uses the contents of the \title command to name the
% project. You can still use the \title command even if you don't
% use the \maketitle command anywhere.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Every single LaTeX document must also have a \begin{document}
% command. This tells the compiler where the actual content of
% the document starts. Much of what gets typed from this point
% forward will appear directly in the output.
\begin{document}
% \maketitle prints the title information. Try removing the
% \maketitle command and see what happens to the output.
\maketitle
% The \section command tells the compiler that you want to start
% a new section and the argument tells it the title of that
% section. If you don't want a section to have a number then
% use \section* instead of \section.
\section{Introduction}
% To make a paragraph in LaTeX just start typing on a new line.
% Make sure, however, that there is a blank line before and after
% the paragraph. Try removing the line after "...useful skill."
% and see what happens to the output.
The rest of this document introduces some things that a MATH 112 student might need in my class for their projects. It is not manditory that projects are typed, but I believe that in some disciplines, learning \LaTeX\ is a useful skill.
I started with the default template provided by writelatex.com and I edited it for my own needs. I kept only the basic skills needed for my class' project and added a few examples.
% This section has a label on it. Any use of \ref{sec:examples}
% will then print out the number of this section.
\section{Some \LaTeX\ Examples}\label{sec:examples}
% Subsections work similarly. There is also a \subsubsection
% and more.
\subsection{How to Include Figures}
First you have to upload the image file (.jpeg, .png, or .pdf) from your computer to writeLaTeX using the upload link the project menu. Then use the includegraphics command to include it in your document. Use the figure environment and the caption command to add a number and a caption to your figure. See the code for Figure \ref{fig:frog} in this section for an example.
% The \includegraphics command below is what actually displays the
% picture. This command will work without all of the stuff around
% it. However, the figure environment (things which start with
% \begin{...stuff...} and end with \end{...stuff...} are called
% environments) allows the compiler to make an educated decision
% about where it best fits in the document.
%
% The [ht] bit here is option and it tells the compiler the
% following: I want this picture to be placed exactly [h]ere in the
% document but if you can't do that, then try to place it at the
% [t]op of a page
\begin{figure}[ht]
% \centering simply centers the picture on the page. (Try removing
% it to see what I mean.)
\centering
% \includegraphics actually displays the picture. As is mentioned
% in the paragraph, frog.jpg must be in the same "directory" as
% this .tex document in order for that to happen. In writeLaTeX
% that is done by uplading as described. Also, there are many ways
% to describe the size of the image; width=... is only one of them.
% Here, width=0.3\textwidth tells the compiler that the image should
% be 30% as wide as the text.
\includegraphics[width=0.3\textwidth]{frog.jpg}
% The caption command should be self-explanitory.
\caption{This frog was uploaded to writeLaTeX via the project menu.}
% This allows you to reference the figure later using \ref{fig:frog}
% as is done above.
\label{fig:frog}
\end{figure}
\subsection{How to Make Tables}
Use the table and tabular commands for basic tables --- see Table~\ref{tab:widgets}, for example.
% The table environment is very similar to the figure environment,
% as you can see. The biggest difference between this and the
% figure is that the \includegraphics command has been replaced
% with the tabular environment.
\begin{table}[ht]
\centering
% Tabular is more complicated than \includegraphics. The argument
% that is shown here as {l|r} controls a lot of things. The letters
% control the spacing; try changing it to {l|c} or {l|l}. The bar
% tells LaTeX to put a bar between columns. Try {lc} or {|l|c|}.
% To add another column, simply add another letter like {l|r|r}.
\begin{tabular}{l|r}
% Within the tabular environment, column entries are separated by
% the & character and \\ represents the end of a row. Use \hline
% between rows to print a line between them in the output.
Item & Quantity \\ %<-- an entire row
\hline %<-- the horizontal line
Widgets & 42 \\ %<-- an entire row
Gadgets & 13 %<-- an entire row
% Note that the LAST row does not need a \\ after it.
\end{tabular}
\caption{An example table.}
\label{tab:widgets}
\end{table}
\subsection{How to Write Mathematics}
\LaTeX\ is great at typesetting mathematics. This is one of its most useful features. The syntax used in the source document can be confusing at first but the output that it produces is quite beautiful.
% Note that I use \$ here to produce a dollar sign. The $ character
% is another character that is very important to LaTeX. If you use
% it in the input it will go into math mode and stay that way until
% you use another one. Using \$ instead of $ tells the compiler
% that you don't want math mode but rather you want it literally to
% print the dollar sign character in the output.
In order to type math, one must use ``math mode.'' The simplest way to use math mode is to use the \$ character in the input. Anything between two \$ symbols will be typeset as inline-mathematics such as $a^2 + b^2 = c^2$ or $f(\theta) = 150 + 100 \sin(\theta)$. Another way to use math mode is with \textbackslash[ and \textbackslash]. Things that are between those will be typeset as displayed-mathematics, meaning that they will go on their own line. A few examples are demonstrated below.
% You should look at the difference between typing x-coordinate and
% typing $x$-coordinate.
Let $f(x) = ax^2 + bx + c$ be any second-degree polynomial. Then the $x$-coordinates of the $x$-intercepts of $y=f(x)$ are given by
% \frac{numerator}{denominator} is used for fractions
\[x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.\]
There may be one, two, or zero such values of $x$.
% LaTeX always uses { and } for grouping; they are both reserved
% characters. You can use \{ and \} to create the bracket
% characters in the output if you'd like.
In math mode, underscores are used for subscripts and carets are used for superscripts. \[F_1 + F_2 = x^3\] However, the default behavior is for the compiler to assume that the text of your superscripts and subscripts are only one character long. To fix this, put braces (\{ and \}) around your subscript. Look at the difference in the code used to produce $x^24$ and $x^{24}$.
% It may seem like a silly distinction, but if you use $sin(x)$
% instead of $\sin(x)$ then it will look much worse to
% mathematicians or to people that use these functions in their
% profession.
There are commands for all of the greek letters such as $\theta$, $\phi$, and $\alpha$. However, you need to be in math mode to use them. Also, there are special commands for important functions. Typing $sin(x)$ is acceptable but it doesn't look very good and it is much better to use $\sin(x)$. Check the code to see the difference. Some examples are shown below:
\[\sin^2(\theta) + \cos^2(\theta) = 1\]
\[\tan(\theta) = \frac{b}{a}\]
\[\log(ab) = \log(a) + \log(b)\]
\[\ln(a/b) = \ln(a) - \ln(b)\]
\[\log_b(x^p) = p \log_b(x)\]
% If you do some google searching about this type of environment
% then you will likely come across the eqnarray environment. DO NOT
% USE THE EQNARRAY ENVIRONMENT. I cannot stress this strongly
% enough. A puppy cries every time someone uses eqnarray.
One often comes up with the need to write a string of equalities (or whatever) that are stacked vertically. This is done with the align environment as demonstrated here. If $f(x) = x^2 + 2x - 3$ and $g(x) = 6x-5$ then
% The * is used here because I didn't want the equations to be
% numbered. Try removing the * (in both places) and see what
% happens.
\begin{align*}
% Note the similarity to the tabular environment. & is an alignment
% character: it tells the compiler that each line should be aligned
% right at the &. The \\ signifies the end of a line.
(f \circ g)(x) &= (6x-5)^2 + 2(6x-5) - 3 \\
&= 36x^2 - 60x + 25 + 12x - 10 - 4 \\
&= 36x^2 - 48x + 11.
\end{align*}
Compare that with
% Note that the "new lines" in the equation below don't make a
% difference. Outside of math mode, line skips are important but
% inside of math mode they don't make much difference.
\[
(f \circ g)(x) = (6x-5)^2 + 2(6x-5) - 3
= 36x^2 - 60x + 25 + 12x - 10 - 4
= 36x^2 - 48x + 11.
\]
which is produced using very similar input.
\subsection{How to Make Sections and Subsections}
% It is at this point that you might be wondering why I keep putting
% a \ at the end of \LaTeX. Why do I use "\LaTeX\ handles..." in
% one place and "...benefits of \LaTeX ." in another place? What is
% up with the backslash there? The answer is that the \ at the end
% of \LaTeX tells the compiler that there should be a space after
% that command. In the first instance below I want that space, but
% in the next instance I don't. This is subtle and is not something
% with which you should be concerned just yet.
Use section and subsection commands to organize your document. \LaTeX\ handles all the formatting and numbering automatically. Use ref and label commands for cross-references. Indeed, this functionality is one of the nicest benefits of \LaTeX . You can move things around and the compiler will handle all of the numbering and labeling for you. The code shows some examples of creating, labelling, and referencing sections.
\subsection{How to Make Lists}
% Typing "\ldots" is better than typing "..." It's a kearning
% thing. Don't worry about it much.
You can make lists with automatic numbering \dots
% I believe these are self-explanatory.
\begin{enumerate}
\item Like this,
\item and like this.
\item and you can make sub-lists if you want.
\begin{enumerate}
\item item.
\item another item.
\item last one.
\end{enumerate}
\end{enumerate}
\dots or bullet points \dots
\begin{itemize}
\item Like this,
\item and like this.
\end{itemize}
\dots or with words and descriptions \dots
% I don't use the description environment much.
\begin{description}
\item[Word] Definition
\item[Concept] Explanation
\item[Idea] Text
\end{description}
\subsection{How to Graph Functions}
% Graphing functions is actually pretty awesome in LaTeX. Let's
% take baby steps for now, though. I don't want people to get
% frustrated and discouraged.
In short, don't do it. It's not that it's unreasonably difficult, it's just frustrating to learn. \LaTeX\ definitely has the capabilities to make very nice graphs and many other useful images. However, in the beginning, it's better not to get ahead of ourselves.
% writeLaTeX seems to use \textit{sketch} to make italics which is
% not incorrect, but if you're using italics as a way to emphasise
% something then you should use \emph{sketch}. This is not a big
% deal, but \textit says "I want this text to be italic no matter
% what" whereas \emph says "I want this text to stand out from the
% surrounding text for emphasis." Again, this distinction is not
% a big deal.
For now, one option is to create an image somewhere else, turn it into a usable image file, and use the includegraphics command to import it as a figure. Or, specifically with the projects in my class, if you are asked to sketch a graph then you are welcome to \emph{sketch} it. If you want to leave space for sketch in the output, use the vspace command.
% This is kind of a weird command. There is also a \vfill command
% and a \clearpage command which can be useful.
\vspace{1in}
Yay vertical space!
% Don't forget the \end{document} command. It tells the compiler
% that you're done and it should stop looking for more stuff to
% compile. It is the third (and final) command that every LaTeX
% document must contain.
\end{document}
In fact, anything that comes after the \end{document} command will be ignored in the output - even if it is not in a comment.