\documentclass[a4paper]{article}
\title{A Quick Introduction}
\author{Sean Allred}
\date{\today}
\renewcommand\today{June 19, 2014}
% Last edited 2015-12-31T22:17:14Z
% Things that start with a % (percent sign) are ignored by LaTeX. They are `comments' and are set off in blue on writeLaTeX.com. They will never appear in the final output.
\usepackage{mathtools,amsthm} % some advanced mathematics notation
\usepackage{graphicx} % easy inclusion and manipulation of images
\usepackage{microtype} % just for fun: really hone in with the typography
\usepackage{booktabs} % nice looking tables that present the content first and foremost
\usepackage{multicol} % multiple columns in a local context
\usepackage[hidelinks]{hyperref} % clickable references in the output, but hide them visually
% These are called macros. They aren't actually this simple, but you can think of it like a smart `find and replace' for most of your needs.
% Macros are case-sensitive. See section 2.
% These two lines tell LaTeX that I want to
% 1) create a new piece of markup called `term' that takes one `thing' and puts single quotes around it
% 2) create a new piece of markup called `pkg' that takes one `thing' and sets it in a sans-serif font
% 3) redefine an existing piece of markup that doesn't take any `things' and just puts the text you see there.
\newcommand\term[1]{`#1'}
\newcommand\pkg[1]{\textsf{#1}}
\newcommand\writeLaTeX{{\sffamily Overleaf}}
% The above macro (\writeLaTeX) is a good example of when macros come in handy. This online service recently rebranded itself from 'writeLaTeX' to 'Overleaf'. All references to the company have been replaced with this one change! In all honesty this is not *unique* to TeX, but it is exceptionally *easy* in TeX.
% The next few macros use moderately advanced TeX. They've been fine-tuned for appearance according to personal taste; you should never have to worry about this in your documents. Ignore these macros except for the logical meanings: `control sequence' (formal term for a TeX macro) and `environment'.
\newcommand\embrace[1]{\texttt{\char`\{#1\char`\}}}
\newcommand\env[1]{\embrace{#1}}
\newcommand\cs[1]{\texttt{\string#1}}
\newcommand\csarg[2]{\cs{#1}\embrace{#2}}
\newtheorem{thm}{Theorem}
\begin{document}
\maketitle
\begin{abstract}
This article aims to be a model \LaTeX\ document while teaching you the basics of what it is and how to use it. It contains all of the basic constructs you are likely to encounter as you write your first papers and articles. This article will not go into detail about how to get started with a local installation of \LaTeX.
\end{abstract}
\tableofcontents
\section{Introduction}
I might have sent you this link because you've demonstrated frustration with Word or curiosity in other ways of doing things. If you want to see how something in the output was done, click on it and \writeLaTeX\ will highlight the appropriate line. You can clone this example to your own, editable copy using the \writeLaTeX\ interface, and I encourage you to do so. The best way to learn is to do, and usually to mess things up. In the immortal words of Mrs.~Frizzle:
\begin{quote}
Take chances! Make mistakes! Get \emph{messy}!
\end{quote}
% Adapted from what writeLaTeX provided. They've developed a pretty good web interface here; learn to use it :)
In addition to a `soft' introduction, some examples of commonly used commands and features are listed below to help you get started. If you have a question about \LaTeX\ or \writeLaTeX, use the help menu (\textsf?) on the top bar.
\section{What is \LaTeX?}
\label{sec:what-is}
First, it's important to note that \LaTeX\ is \emph{not} \writeLaTeX; rather, \writeLaTeX\ is \emph{powered} by the underlying \LaTeX\ program. Every time you change the plain text, this is run through the \LaTeX\ program and the server displays the image for you to see.
\LaTeX\ is, in the words of its creator, a `document preparation system'. It takes the raw text that you see here on the left and it produces the formatted document that you see on the right. It is not just another format available for you to write your papers in (like using OpenOffice instead of Word), but it's rather a different way of thinking about what you as an author should be doing with your document.
Let's face it: you are neither a typographer nor a publisher, but you're at least pretty OK at writing. \LaTeX\ knows this and knows that it's far more important for you to understand \emph{what you mean} in your document. If you know what you \emph{mean} and can tell \LaTeX\ how to demonstrate that meaning on the page, then you have a very consistent and easy-to-use \emph{document preparation system}. It is not just a format; it is a system. Use the system.
\LaTeX\ comes with a lot of this `meaning' markup baked-in.\footnote{This `meaning' markup is often called \term{semantic} markup.} For instance, I can emphasize a piece of text by surrounding it with the \csarg\emph{stuff} markup; \LaTeX\ will do the `right' thing. For instance, if I want to emphasize part of an emphasize \emph{it will actually \emph{switch back} to demonstrate that \emph{additional} emphasis}. There are many commands that do multiple things all at once: if I wanted to start a new section---like those you see in this article---all you need to do is say \csarg\section{title} and \LaTeX\ will do the `right' thing(s):
\begin{itemize}
\item It will increment the section counter.
\item It will set the title as it understands how sections are set.
\item It will insert the title into the table of contents.
\end{itemize}
This part of \LaTeX\ is about what we call \term{typographical consistency}. I can change the behavior of \emph{all} sections with a few short lines. If you're reading along in the \term{source document} (the plain text to the left), I can change how \term{terms} are set everywhere by changing exactly one line. The possibilities really do not stop there, but in the interest of keeping this article relatively short, I will leave that research to the reader.
\section{Some \LaTeX\ Examples}
\label{sec:examples}
Now that you know the idea behind \LaTeX, let's get into some concrete examples. If you haven't read the introduction (\autoref{sec:what-is}), I strongly urge you to; things from here on out will make more sense. I encourage you to read along with the source; if you have been you already know how to
emphasize text with \cs\emph,
start a bulleted list with \env{itemize},
start a section with \cs\section,
give a footnote with \cs\footnote,
and use a cross-reference using \cs\label and \cs\autoref.\footnote{%
Actually, this command is given by the \pkg{hyperref} package.
The standard command to use is \cs\ref,
but \cs\autoref will insert the appropriate label in front
(like `section') when \pkg{hyperref} knows it.
Of course, you can teach the package new things.}
You also know that \LaTeX\ doesn't really pay attention to
inconsistent inter-word spacing or
random
line
breaks. The only real `rule':
if it encounters a \emph{blank} line---whitespace only---%
it starts a new paragraph.
% You can also `skip' spaces using the comment character.
% If you take the following, for example:
%
% Lorem ipsum doler---
% sit amet.
%
% You will see that there is an unwanted space after the dash.
% If we had a comment character to `comment out' the rest of the line:
%
% Lorem ipsum doler---%
% sit amet.
%
% This yields the desired result.
% Note also that it is generally poor practice to have excessively long lines -- it even makes your content harder for you to read while you're writing it -- so I make sure that my view of the content never makes the lines very long. I will squeeze the window to be thinner (soft-wrapping the content) or tell my text editor to hard-wrap it into shorter lines to make sure I can easily read my content. (Shorter lines also come in handy if you choose to use version control -- an advanced topic for another day.)
\subsection{How to Organize Your Document}
As you've already seen, \LaTeX\ comes with at least one command to organize your document: \cs\section. There are, in fact, many others:
\begin{multicols}{3}
\begin{enumerate}
\item \cs\part
\item \cs\chapter
\item \cs\section
\item \cs\subsection
\item \cs\subsubsection
\item \cs\paragraph
\item \cs\subparagraph
\end{enumerate}
\end{multicols}
Actually, the availability of these commands\footnote{Or \term{control sequences} as they are more properly called.} depends on the \term{document class} you use. For example, \csarg\documentclass{article} doesn't define \cs\part or \cs\chapter, but \csarg\documentclass{book} does.
\subsection{How to Make Lists}
% Very slightly adapted from the stock text by writeLaTeX.com
You can make lists with automatic numbering using \env{enumerate}\dots
\begin{enumerate}
\item Like this,
\item and like this.
\end{enumerate}
\dots or bullet points using \env{itemize}\dots
\begin{itemize}
\item Like this,
\item and like this.
\end{itemize}
\dots or with words and descriptions using \env{description}\dots
\begin{description}
\item[Word] Definition
\item[Concept] Explanation
\item[Idea] Text
\end{description}
\subsection{How to Include Figures}
% adapted from the stock text by writeLaTeX.com
See the code for \autoref{fig:frog} in this section for an example.
\begin{enumerate}
\item Upload the image file (JPEG, PNG or PDF) from your computer to \writeLaTeX\ using the upload link the project menu.
\item Use the \cs\includegraphics command to include it in your document.
\item Use the \env{figure} environment and the \cs\caption command to add a number and a caption to your figure.
\end{enumerate}
\begin{figure}
\centering
\includegraphics[width=0.3\textwidth]{frog.jpg}
\caption{This frog was uploaded to \writeLaTeX\ via the project menu.}
\label{fig:frog}
\end{figure}
\subsection{How to Make Tables}
Use the \env{table} and \env{tabular} commands for basic tables---see \autoref{tab:widgets} on page~\pageref{tab:widgets}, for example. \cs\toprule, \cs\midrule, and \cs\bottomrule are all provided by \pkg{booktabs}. The standard command to use is \cs\hline, but see the \pkg{booktabs} documentation\footnote{\url{http://texdoc.net/texmf-dist/doc/latex/booktabs/booktabs.pdf}} for some nice reading on why the tables it suggests are better.
% the \url command is provided by the `hyperref' package.
\begin{table}
\centering
\begin{tabular}{lr}
\toprule
Item & Quantity \\
\midrule
Widgets & 42 \\
Gadgets & 13 \\
\bottomrule
\end{tabular}
\caption{An example table.}
\label{tab:widgets}
\end{table}
\subsection{How to Write Mathematics}
% adapted from stock example for correctness and best practices
\LaTeX\ is great at typesetting mathematics. Let $X_1, X_2, \ldots, X_n$ be a sequence of independent and identically distributed random variables with $\text{E}[X_i] = \mu$ and $\text{Var}[X_i] = \sigma^2 < \infty$, and let
\[S_n = \frac{X_1 + X_2 + \cdots + X_n}{n}
= \frac{1}{n}\sum_{i}^{n} X_i\]
denote their mean. Then as $n$ approaches infinity, the random variables $\sqrt{n}(S_n - \mu)$ converge in distribution to a normal $\mathcal{N}(0, \sigma^2)$.
% Back to totally me
I have no idea what \emph{any} of that means, so see \autoref{eq:simple}.
If you want to be concise about it, you can also use \cs\eqref: see~\eqref{eq:simple}.
\begin{thm}
If this, then that.
\end{thm}
\begin{proof}
Since we know that
\begin{equation}
\text{this} \implies \text{that},
\label{eq:simple}
\end{equation}
the result directly follows.
\end{proof}
There is a lot more to mathematics typesetting, but that's beyond the scope of this article. There may be another that looks at this in-depth.
\section{Getting Help}
\LaTeX\ comes with very thorough documentation. For online use, simply Google-search \texttt{texdoc (package)} to look up the official documentation for \pkg{package}. This mirrors the command-line tool, \texttt{texdoc}, which is used in the same way. For everything else, usually a simple search for \texttt{LaTeX (thing)} for information on \cs\thing or \env{thing}. For everything else, including specific help, there's the \TeX~StackExchange.\footnote{\url{http://tex.stackexchange.com}}
\section{Next Steps}
\subsection{Getting \LaTeX}
\writeLaTeX\ is a useful resource and I encourage you to use it to the fullest. However, \LaTeX\ is a program that can run on \emph{your} computer just as easily as it can run online. It is absolutely free.
My recommendations are as follows:
\begin{description}
\item[Windows] \TeX~Live\footnote{\url{http://www.tug.org/texlive/windows.html}} (but MiK\TeX\footnote{\url{http://www.miktex.org}} is another popular option).
\item[Mac] Mac\TeX\footnote{\url{http://www.tug.org/mactex}} is by \emph{far} the best. I highly recommend it.
\item[Linuxes] \TeX~Live\footnote{\url{http://www.tug.org/texlive}} is your \emph{only} option, and I actually recommend against using your distribution's package manager to install it and encourage you to use install script provided upstream. The versions are almost always several years behind, and \LaTeX\ package development is very active. If you absolutely must use the package manager, install \texttt{texlive-full} or similar---trust me when I say that it makes life \emph{much} easier.
\end{description}
To make links easier to work with, download the PDF using the appropriate button above on the top bar. This is what \LaTeX\ actually produced for \writeLaTeX; it is fully clickable and otherwise interactive. (It also just looks \emph{nicer} somehow\dots)
\subsection{Choosing an Editor}
Your experience with \LaTeX\ will largely be impacted by your choice of editor. For learning on any platform, TUG's own \TeX works is a good starting point. When you find you're repeating yourself a lot, I recommend moving onto \TeX maker (also cross-platform). If you are comfortable using it---I won't lie and say it's immediately intuitive for a beginner---the venerable Emacs editor has an excellent mode called \textsc{Auc\TeX}. It is \emph{extremely} good. \TeX maker and Emacs will see you through from then on, and both are absolutely free.
\vfill
\begin{center}
Happy \TeX ing!
\end{center}
\vfill
\end{document}