This is a tutorial for AguaClara team members to learn the basics of using LaTeX within Overleaf. Use this as a reference for all of the basic skills needed to write your reports.
% Preamble: this is all of the stuff that determines the basic characteristics of your document. This is probably a good place to mention that '%' begins a comment and '\' begins a command in LaTeX.
\documentclass[english,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{float}
\usepackage{graphicx}
\usepackage{babel}
\usepackage[authoryear]{natbib}
\usepackage{hyperref}
\usepackage[inline,ignoremode]{trackchanges}
\addeditor{WP}
\usepackage[margin=1in]{geometry}
% Now, the preamble ends and the document begins! Whenever you see a \begin{}, it needs to be finished with an \end{}. Otherwise, LaTeX will give you an error. At the very end of this document, you'll see an \end{document}.
\begin{document}
\title{AguaClara Overleaf and \LaTeX \ Tutorial} % This is where you set the title.
\author{William Pennock} % This is where you list authors
\date{\today} % This is where you write the date.
\maketitle % This is the command that puts together that beautiful title.
\begin{abstract}
This is where you describe your project. This is probably a good place to mention that you can get \LaTeX \ and Overleaf help by clicking on the question mark above. Another good reference is \href{https://en.wikibooks.org/wiki/LaTeX}{the wikibook}. For specific questions, you can often find them already answered at \href{http://tex.stackexchange.com}{Stack Exchange}.
\end{abstract}
\part*{Using Overleaf}
\section*{Source and Rich Text} \label{sourcevrich}
In Overleaf, you can view the code for your document in either Source or in 'Rich Text'. The 'Source' is your raw \texttt{.tex} file, which is like a \texttt{.txt} file that contains your code which \LaTeX \ compiles and turns into a PDF. The Rich Text view adds a graphical interpretation of the code that is visually somewhere between the \texttt{.tex} file and the resulting PDF.
The Rich Text view may be the best way to view your work when you are starting out. It has the advantage of giving a sense of how your document is structured, whereas looking at the Source can sometimes be a little overwhelming. Additionally, if you prefer more of a GUI (graphical user interface) when word processing, the Rich Text view offers a few extra buttons. One of the most useful of these is the 'Add a Comment' button (rectangular speech bubble with plus sign inside), which allows you to make comments, respond to them, and close them. You can minimize comments, and if you want to do this, be sure to press the 'minimize' button in the top right of the comment box instead of the 'close' button, which marks the discussion about the comment closed. If you want to un-close a comment, you need to go to Source view and delete the last time-stamp, which ends with a period to show that the comment has been closed, as well as the \% in the line above it. A way of making comments directly in the document is given in a later section.
Viewing your code in Source mode can be helpful in terms of debugging and performing more code-oriented tasks, since it is exactly what is compiled and run (Overleaf automatically does this every time you make an edit if preview is switched to "Auto"). Source mode has a few additional advantages for those who have experience (or want to gain experience) using a text editor. Overleaf has key bindings for both VIM and Emacs, which can be accessed in 'Settings' (gear button at the top right). In my experience, both work, but the VIM bindings work a little more naturally in a web browser environment. As with text editors, you can also change the color scheme for the syntax highlighting, and this can be done in 'Settings'.
\section*{Important Buttons}
So far, we've mentioned several important buttons:
\begin{itemize}
\item Help Button (question mark) - Directs you to useful tutorials and references as well as to Overleaf support if you really get stuck (you should be able to solve most of your issues by referring to the references and tutorials).
\item Settings Button (gear) - Gives you options for how you edit and view your project.
\item Source/Rich Text Switch - Gives you the choice between editing your file in a more text-based or graphical mode.
\end{itemize}
\noindent For the rest of this part of the tutorial, we will focus on the functionality of a few of the other buttons in Overleaf.
\subsection*{Project}
The Project Button shows all of the files in your project. The way \LaTeX \ projects work is that there is a main file (the \texttt{.tex} file) and several supporting files which are called upon when the main file is compiled and run to create a document. These include image files for figures and BibTeX (\texttt{.bib}) files for bibliographies, which will be discussed later in this tutorial. To add a file to your project, simply click on Project and then on the 'Add Files...' button. To add a file saved to a location on your computer, simply click on Computer next, browse for your file, and drag and drop it. Another useful feature is that you can press the 'Download as ZIP' button to get a \texttt{.zip} file containing all of your project documents if you would like to save them locally somewhere.
\subsection*{History \& Revisions}
This button allows you to save the project in its current state so that you can refer back to it later. To do this, you simply click on History \& Revisions and then write a name for the version (perhaps who worked on it and the date) and click on the 'Add Label' button. This will create a snapshot of your project from that time. This is helpful for a number of reasons. For one, you can recover your document by pressing the 'Restore' button to bring it back to a previous state if for some reason something goes wrong. More importantly, you can press the 'Compare' button to compare the document in its current state to a prior version. This functions like the "Track Changes" feature in MS Word, and will allow you to see what edits another user has made to your document. This is essential for working with your advisor. Whenever you submit a report to your advisor, you should save a version with a name that reflects the date and the version number. When your advisor has finished editing your draft, they should also save a similarly-named version that will allow you to see what changes they have suggested.
\subsection*{Share and PDF}
The last two buttons of interest are Share and PDF, and they are fairly self explanatory. Share gives you the URLs for both the editing view of your project as well as a read-only view in case there is a reason you want someone to be able to read your document without being able to change it. The PDF button does exactly what you would think: it generates a PDF of your project.
\part*{Using \LaTeX}
This part of the tutorial is intended to give you a better understanding of how \LaTeX, the typesetting language used by Overleaf, works and how you can use it.
\section{Sections}
Here, the hierarchy of headings is shown.
\subsection{Subsections}
\subsubsection{Subsubsections}
This is probably the lowest you'll need to go.
\paragraph{Paragraphs}
\subparagraph{Subparagraphs}
\section*{Unnumbered Sections}
This would be your \emph{first} (italics added by using the \texttt{\textbackslash emph\{\}} command) paragraph. Notice that this section is unnumbered, but the "Sections" section above was numbered. This is because of the asterisk (*) following the 'section' command for this section.
This would be your \textbf{second} (boldface added by using the \texttt{\textbackslash textbf\{\}} command) paragraph.\footnote{You can add footnotes by using the \texttt{\textbackslash footnote\{\}} command.} \LaTeX \ automatically indents all paragraphs after the first paragraph.
Although this text is on a new line, it is a continuation of the same paragraph, because there is no line between it and the prior line.
\noindent Another way to insert an un-indented line is to use the \texttt{\textbackslash noindent} command to remove indentation.
\begin{itemize}
\item To add a bullet-point list, simply begin an \texttt{itemize} environment with \texttt{\textbackslash begin\{itemize\} ... \textbackslash end\{\}}.
\item Bullet points are then added with the \texttt{\textbackslash item} command.
\end{itemize}
\begin{enumerate}
\item If you want a numbered list, begin an \texttt{enumerate} environment.
\item As with the \texttt{itemize} environment, points are added with the \texttt{\textbackslash item} command.
\begin{enumerate}
\item In order to make sub-points (or sub-sub-points), simply begin a new \texttt{enumerate} (or \texttt{itemize}) environment beneath the point you wish to expand upon.
\end{enumerate}
\end{enumerate}
\section*{Comments}
In addition to the method of commenting provided by Overleaf (refer to the section titled \href{sourcevrich}{"Source and Rich Text"}), there is a more functional method of commenting, made possible by use of the \texttt{Track Changes} package. With this packages, you can insert a \texttt{\textbackslash note} in the middle of the text. \note[WP]{Like this!} You can also \annote[WP]{\texttt{\textbackslash annote} text}{like this!}. \remove[WP]{You can \texttt{\textbackslash remove} text you do not want.} \add[WP]{And, you can \texttt{\textbackslash add} text that you do want.} \change[WP]{Lastly, you can \texttt{\textbackslash change} out one piece of text}{for another that you think would be better.} To add other editors, simply go to the preamble and use the command \texttt{\textbackslash addeditor\{\}} with the new editor's initials in the curly braces. The documentation for this package can be found \href{http://trackchanges.sourceforge.net/}{here}. A note on this
\section*{Mathematics}
\LaTeX \ is particularly good at typesetting mathematics (it stems from the work of Stanford mathematician, Don Knuth), so it is quite versatile at writing equations. Your best resource for formatting mathematics is \href{https://en.wikibooks.org/wiki/LaTeX/Mathematics}{the wikibook chapter on mathematics}. Another helpful resource is a GUI equation editor (not unlike the one in MS Word) called \href{http://www.hostmath.com/}{HostMath}.
Within text, an inline equation would be $1+1=2$, accomplished by enclosing the formula with dollar signs (\$).
Numbered equations are written using \texttt{\textbackslash begin\{equation\} ... \textbackslash end\{equation\}}:
\begin{equation}
H_L = K_e\frac{V^2}{2g}.
\label{MinorLoss}
\end{equation}
Note that within the 'equation' environment, the command \texttt{\textbackslash label} was used with a name in curly brackets. This makes it possible to reference the equation number in the text. For example, the minor loss relationship is given in Equation \ref{MinorLoss} (equation number automatically generated by using the \texttt{\textbackslash ref\{\}} command).
Probably the least intuitive (but still easy) part of writing mathematics in \LaTeX \ is writing fractions. To demonstrate how to use the \texttt{\textbackslash frac} command: the price of electricity is $\$30\div GJ=\frac{\$30}{GJ}$. Now for the easy stuff. Exponents and subscripts are easy: $\rm{H_2CO_3\to CO_3^{2-}+2H^+}$. You also use them to give the limits of summations and integrals: $\sin x=\sum^\infty_{n=0}\frac{(-1)^n}{(2n+1)!}x^{2n+1}$. You can use them to denote roots, but you can also use the root symbol with \texttt{\textbackslash sqrt[]\{\}} (the order of the root goes in the square brackets) as demonstrated here: $x^{1/3}=\sqrt[3]{x}$. As shown previously, you can use parentheses as well as square and curly brackets to enclose characters in your equations. If standard parentheses or brackets are too small (for example, if they are enclosing a fraction), you can use \texttt{\textbackslash left} before the opening character and \texttt{\textbackslash right} before the closing character like this: $\left(\frac{e^x}{\log_{10}x}\right)$.
Adding special symbols in \LaTeX \ is fairly simple, and you can find a list of the ones available natively within
\LaTeX \ in \href{https://en.wikibooks.org/wiki/LaTeX/Mathematics}{the wikibook}. If you are having trouble finding one you are looking for, you can try to locate it graphically at \href{http://detexify.kirelabs.org/classify.html}{Detexify}. Greek letters, for example, are very easy. Simply type \textbackslash \ and the name of the letter (e.g., $\alpha$ is \texttt{\textbackslash alpha}). For capital Greek letters, you just capitalize the name of the letter (e.g., $\Gamma$ is \texttt{\textbackslash Gamma}). While we're thinking about symbols in this section it might also be good to mention that some symbols that commonly occur in writing happen to have very specific meanings in \LaTeX \ code that will lead to problems if you use them as they are. Some of these are \%, \&, \$, and \_. You might have guessed that the backslash is not available, either. If you use it in the text, it will give you a space. To write a backslash, you need to use \texttt{\textbackslash textbackslash}.
Lastly, there are a few good things to know about equation editing. First of all, \LaTeX \ will automatically set the spacing in your equations, so if you want to intentionally add spaces, you need to write them. There are four different spaces available, as shown here: $a\,b\:c\;d\!e$. I generally use \textbackslash : for spacing, like when I need to write units in an equation. Speaking of writing units, \LaTeX \ automatically italicizes letters in equations to reflect that they are variables, but that doesn't make sense for writing units. In this case, you can change the font by enclosing whatever you don't want italicized with \texttt{\textbackslash mathrm\{\}} (rm is short for Roman). Some other available fonts are $\mathbf{Bold}$ and $\mathtt{Monospace}$.
\section*{Figures}
To understand how to insert a figure, refer to Figure \ref{Data}. As can be seen in the code, the commands for inserting a figure are contained within a \texttt{figure} environment. Note that after \texttt{\textbackslash begin\{figure\}} is a \texttt{[H]}. This bracketed letter tells \LaTeX \ how strict to be in placing the figure. Without this bracketed expression, \LaTeX \ decides what it thinks looks best. The bracketed \texttt{H} tells it to put the figure "right here", that is, where it falls in the code. The first command given after \texttt{\textbackslash begin\{figure\}} is \texttt{\textbackslash centering}. This centers the figure, whereas the default is to left-justify it. The next command is perhaps the most important command, \texttt{\textbackslash includegraphics}, which imports the image file (which you need to add to your project with the Project button) into the document. The expression in square brackets immediately after the command modifies the command (see a pattern?). In this case, the modification is to to display the image at 50\% of its size with \texttt{[scale=0.5]}. The expression in curly brackets is the name (verbatim) of the image file that is to be imported into the document. The caption below the figure is added with \texttt{\textbackslash caption} and a label is given with \texttt{\textbackslash label} as is done with equations. Please note that it is important that the \texttt{\textbackslash label} command come after the \texttt{\textbackslash caption} command. For further reference, refer to \href{https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions}{the wikibook}.
\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{Data}
\caption{My Beautiful Data}
\label{Data}
\end{figure}
\section*{Tables}
Tables are quite like figures in their structure, as can be seen in the code for Table \ref{mydataTable}. There are, nonetheless, a few notable differences. The most important is that within the \texttt{table} environment is a \texttt{tabular} environment. This is an improvement over the \texttt{table} environment's functionality. To begin, notice the statement in curly brackets after the \texttt{\textbackslash begin\{tabular\}} command. This is where the columns of the table are generated. The letters \texttt{l}, \texttt{c}, and \texttt{r} stand for left-justified, centered, and right-justified columns. The \texttt{p} column is a column with a fixed width, in this case set to 5 cm. The pipes and doubled pipes between the columns give lines and double lines between columns. If these are left out, there is no vertical line between the columns. Looking to the next line, \texttt{\textbackslash hline} is the way to add lines between each row and must be done for each row where this is desired, just like with the pipes for vertical lines. The next line shows how rows are written. Between each column, an ampersand (\&) must be written. At the end of the row, a double backslash (\texttt{\textbackslash \textbackslash}), which is the command for a new line, is needed to indicate the end of the row. At the end of the table, the \texttt{\textbackslash hline} command is doubled to show how double lines can be placed between rows in tables. As a last comment about tables, notice that the \texttt{\textbackslash caption} command comes before the table. This is in order to place the caption on top of the table, which is proper style for tables. For further reference, refer to \href{https://en.wikibooks.org/wiki/LaTeX/Tables}{the wikibook}. Also, for a great tool for creating tables, visit \href{www.tablesgenerator.com}{tablesgenerator.com}.
\begin{table}[H]
\centering
\caption{Look at my data!}
\label{mydataTable}
\begin{tabular}{|| l |c r | p{5cm} ||}
\hline
100 & 2 & 3 & These data are very interesting. \\ \hline
4 & 500 & 6 & Don't you think? \\ \hline
7 & 8 & 900 & Okay, so they aren't real data. \\
\hline \hline
\end{tabular}
\end{table}
\section*{Adding References}
Once you know how to do it, citations and bibliographies are easy in \LaTeX, and you may find yourself wondering why you would ever trouble yourself with the tedium of doing it manually again. In order to do this in \LaTeX, you need to import a \texttt{.bib} file into your project which contains the bibliographic information of your sources. There are many ways to do create a BibTeX file, but I would recommend Zotero, which generates bibliography entries with the click of a button when you are on the web page of your source. To download Zotero, visit \href{https://www.zotero.org/download/}{the download page}. For some information on how to get started with it, visit \href{https://www.zotero.org/support/start}{the introduction page}. Once you have an account and some sources, you can easily develop a BibTeX file from the sources. In Overleaf, simply go to Project > Add files... > Bibliography. Here, there in option for Zotero, which allows Overleaf to access your Zotero account and pull all of the sources in your Zotero account into one BibTeX file. If this doesn't work, you can also manually generate a BibTeX file in Zotero by selecting the sources you want to include (CTRL + click), right clicking them, and selecting Export Items and then choosing BibTeX for the format.
Once you have a \texttt{.bib} file, the process is quite easy. At the end of the document, you need two commands. The first is \texttt{\textbackslash bibliographystyle\{apalike\}}, which gives an APA-esque format to your references. The other command is \texttt{\textbackslash bibliography\{\}}, which accepts as an input the name of your \texttt{.bib} file. This automatically adds a section at the end of your document called "References". This section is populated with references from your \texttt{.bib} file as you cite them in your document. Citing is easy. Each reference in a \texttt{.bib} file has a name given to it for reference. Zotero automatically generates names for each source based on the author, title, and year. To cite a source at the end of a sentence, simply use \texttt{\textbackslash citep\{\}}, which takes the name of the source as an argument. An example of a citation would be \citep{tennekes_first_1972}. If you were to mention our beloved \citet{tennekes_first_1972} in a sentence, you would simply use the command \texttt{\textbackslash citet} to give the year of publication in parentheses after the names of the authors, as was done in this sentence.
If you want to add a hyperlink to your document, you can do so by using the command \texttt{\textbackslash href\{<URL>\}\{<description>\}}. For example, you can see the documentation for the \texttt{hyperref} package that this command is a part of by clicking \href{https://en.wikibooks.org/wiki/LaTeX/Hyperlinks}{here}.
\vspace{1cm}
\noindent Well, that's all folks. Now you can put LaTeX on your resume ;)
\bibliographystyle{apalike}
\bibliography{Bibliography}
\end{document}