\documentclass[lettersize]{article}

% EXTERNAL LIBRARIES ----------------------------------------------------------
% document
\usepackage[includeheadfoot, margin=0.8in]{geometry} % for margin adjustment
\usepackage[utf8]{inputenc} % for UTF-8 input in the document
\usepackage{parskip} % for no ident at the beginning of a paragraph
\usepackage{fancyhdr} % for the header
\usepackage{titlesec} % for custom spacing between section headings and text
\usepackage[fontsize=10]{scrextend} % for adjusting the font size
% graphics
\usepackage{graphicx} % for figures
\usepackage{float} % for embedding figures in text better
\usepackage{caption} % for equations in captions (fractions specifically)
% better environments
\usepackage{amsmath} % for more equation symbols
\usepackage{amssymb} % for more equation symbols
\usepackage{fancyvrb} % for a better verbatim environment (Verbatim)
\usepackage{enumitem} % for a better enumeration environment
% tables
\usepackage{multirow} % for multi-row tables
\usepackage{siunitx} % for table floating point alignment in a column
\usepackage{xcolor} % for colorful table cells
\usepackage{units} % for colorful table cells
% interactive document
\usepackage{url} % for weblinks in text and clickable table of contents
% code in the article
\usepackage{algorithmicx} % for nice pseudocode
\usepackage{listings} % for code listings
\usepackage{color} % for custom color in code listings
\usepackage{hyperref}
% -----------------------------------------------------------------------------

% FIGURE, TABLE, EQUATION CONFIG ----------------------------------------------
% reduces the font on captions for figures
\captionsetup[figure]{font=footnotesize}
\captionsetup[table]{font=footnotesize}
\numberwithin{equation}{section}
% -----------------------------------------------------------------------------

% HEADER CONFIG ---------------------------------------------------------------
\fancyhf{}
\pagestyle{fancy}
\lhead{Left header}
\chead{Center header}
\rhead{Right header}
\cfoot{\thepage}
\rfoot{Right footer}
\renewcommand{\headrulewidth}{0.4pt}
\VerbatimFootnotes % to allow verbatim in footnotes
% -----------------------------------------------------------------------------

% LINE SPACING CONFIG ---------------------------------------------------------
\setlist{nosep} % reduce the spacing between list elements
\linespread{1.6} % double space is 1.6, 1.3 is single space
% -----------------------------------------------------------------------------

% CODE LISTING CONFIG ---------------------------------------------------------
\definecolor{mykeyword}{rgb}{0,0.6,0}
\definecolor{mycomment}{rgb}{0,0.6,0.9}
\definecolor{mynumber}{rgb}{0.5,0.5,0.5}
\definecolor{mystring}{rgb}{1,0,0}

\lstset{
  language=Matlab,
  backgroundcolor=\color{gray!40},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
  breaklines=true,                 % sets automatic line breaking
  captionpos=t,                    % sets the caption-position to bottom
  commentstyle=\color{mycomment},    % comment style
  frame=single,	                   % adds a frame around the code
  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
  keywordstyle=\color{mykeyword},       % keyword style
  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)
  numbersep=5pt,                   % how far the line-numbers are from the code
  numberstyle=\color{mynumber}, % the style that is used for the line-numbers
  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
  showstringspaces=false,          % underline spaces within strings only
  showtabs=false,                  % show tabs within strings adding particular underscores
  stringstyle=\color{mystring},     % string literal style
  tabsize=2,	                   % sets default tabsize to 2 spaces
  morecomment=[s]{\%\{}{\%\}},
  morekeywords={continue,switch,case,otherwise,try,catch},
  %title=\lstname                   % show the filename of files included with \lstinputlisting; also try caption instead of title
}
% -----------------------------------------------------------------------------

% START OF BIBLIOGRAPHY CONFIG ------------------------------------------------
\usepackage[superscript]{cite}
\makeatletter 
\renewcommand\@biblabel[1]{#1.} 
\makeatother
\let\oldthebibliography\thebibliography
\let\endoldthebibliography\endthebibliography
\renewenvironment{thebibliography}[1]{
 \begin{oldthebibliography}{#1}
 \setlength{\itemsep}{0em}
 \setlength{\parskip}{0em}
}
{
 \end{oldthebibliography}
}
\renewcommand\refname{\hfil References}
\bibliographystyle{naturemag}
% -----------------------------------------------------------------------------

% TITLE PAGE CONFIG -----------------------------------------------------------
\title{}
\author{}
\date{\today}
% -----------------------------------------------------------------------------

% Custom spacing for sections -------------------------------------------------
\titlespacing{\section}{0pt}{0pt}{0pt}
\titlespacing{\subsection}{0pt}{0pt}{0pt}
\titlespacing{\subsubsection}{0pt}{0pt}{0pt}
% -----------------------------------------------------------------------------


% START OF DOCUMENT -----------------------------------------------------------
\begin{document}
%\clearpage\maketitle % clears the page's style and prints the title
%\tableofcontents % prints the table of contents for sections

%\newpage % request a new page after printing the title
\section{Introduction}
To write text, just write text.
\subsection{You can have subsections}
\subsubsection{You can have sub-subsections}

\underline{Get a underline} with \verb|\underline{}|, \textbf{bold text} with
\verb|\textbf{}| and \emph{italics with} \verb|\emph{}|.

\verb|\\| gives you a new \\ line.

\section{Lists}

Bullet point list
\begin{itemize}
\item First item
\item Second item
\begin{itemize}
\item First sub-item
\item Second sub-item
\end{itemize}
\item Third item
\end{itemize}

Numbered lists
\begin{enumerate}
\item First item
\item Second item
\begin{enumerate}
\item First sub-item
\item Second sub-item
\end{enumerate}
\item Third item
\end{enumerate}

\section{Mathematics}


% open the equation environment
\begin{equation}
text doesn't work like text in math environment
\end{equation}
but you can use \verb|\text{}|
\begin{equation}
\pi \approx 3.14 \text{ this is a very crude approximation}
\end{equation}

\begin{equation}
A x = b
\end{equation}

\begin{equation}
\frac{\sqrt{1 + \frac{df}{dx}}}{2} = 20.0 \text{ adding text}
\end{equation}

% add star to the equation environment to suppress the number
\begin{equation*}
a = b
\end{equation*}

Another math environment (doesn't print number by default)
\[
\alpha = 2
\]

You can also use equations in text like $x = 2$. Text continues afterwards.
Delta in second order polynomials is given by $\Delta = \frac{-b \pm \sqrt{b^2 -
4 a c}}{2}$.

You can also align equations
% this is also a math environment
\begin{align}
a &= 2 \\
  &= 3 \\
  &= 4 \nonumber \\
  &= 17 \\
  &= c
\end{align}

Matrices are also easy to write
\begin{equation}
A = \begin{bmatrix} % b stands for brackets matrix, p parentheses
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix} = I
\end{equation}

Subscript and superscript, use curly braces
\[ x_{ijk} = 5 \times 10^{-17} \]
here I forgot curly braces
\[ x_ijk = 5 \times 10^-17 \]

\[
a(x) = \begin{cases}
-\infty \text{ if } x > 0 \\
1 \text{ otherwise}
\end{cases}
\]

\section{Tables}

Tabular environment within table environment
% option H forces the table to be displayed HERE
% normally figures and tables float around 
% and are displayed where it best fits the formatting
\begin{table}[H] 
\centering
\begin{tabular}{ c || c | c | c | c | c}
$x$ & 1 & 2 & 3 & 4 & 5 \\ \hline
$y$ & 1 & 4 & 9 & 16 & 25 \\
\end{tabular}
\end{table}

A weird table
\begin{table}[H]
\centering
\begin{tabular}{| l | c | r}
Left aligned & center aligned & right aligned \\ \hline
another cell & $a = \frac{1}{2}$ & \\ \hline \hline \hline \hline
a & hello & b \\
\end{tabular}
\end{table}

\section{Figures}
\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{figures/color_rand.png}
\caption{This is a figure}
\end{figure}

\section{Minipage}
\begin{minipage}{0.47\textwidth}
Divide the page 
\end{minipage}
% horizontal fill push the right minipage to the right, left to left
% essentially centers the minipages
\hfill 
\begin{minipage}{0.47\textwidth}
into two parts
\end{minipage}

\begin{minipage}{0.31\textwidth}
or
\end{minipage}
\hfill 
\begin{minipage}{0.31\textwidth}
three
\end{minipage}
\hfill 
\begin{minipage}{0.31\textwidth}
parts
\end{minipage}

Advanced examples
\begin{figure}[H]
\centering
\begin{minipage}{0.47\textwidth}
\includegraphics[width=\textwidth]{figures/bw_rand.png}
\caption{The grayscale image example.}
\end{minipage}
\hfill
\begin{minipage}{0.47\textwidth}
\includegraphics[width=\textwidth]{figures/color_rand.png}
\caption{The color image example.}
\label{fig:color}
\end{minipage}
\end{figure}

\section{Referencing}
\label{sec:referencing}
Add \verb|\label{}| to equations, figures, tables, sections.

You can then reference a section, like section \ref{sec:referencing}, or Figure
\ref{fig:color} or equation (\ref{eq:ein}).


\begin{equation}
e = m c^2
\label{eq:ein}
\end{equation}

It'll give you click-able links if you're using the \verb|hyperref| package.

\section{Typesetting Code}
Use either the \verb|lstlisting| package
\begin{lstlisting}
function it = fractal(c)
  z = 0;
  it = 0;
  while abs(z) <= 2.0
    z = z^2 + c;
    it = it + 1;
    if it == 100
      it = 0;
      break;
    end
  end
end
\end{lstlisting}
or use the verbatim environment
\begin{verbatim}
function it = fractal(c)
  z = 0;
  it = 0;
  while abs(z) <= 2.0
    z = z^2 + c;
    it = it + 1;
    if it == 100
      it = 0;
      break;
    end
  end
end
\end{verbatim}

The vebatim environment can also be used in line with \verb&\verb||&.
\footnote{Inline \verb|verb| works with a pair of the same symbol to bound
whatever is inside.}

\section{Citing}

You can simply cite papers using \verb|\cite{}|\cite{mb}.
 
% use the biblio.bib file for bibliography
\bibliography{biblio.bib}{} % print the bibliography
\end{document}
