\documentclass{article}

%% The document is divided into the Preamble and the Body.

%% Important special characters:
%% - '%' (percent) marks a comment to the end of the line
%% - '\' (backslash) begins a command
%% - '{' and '}' are grouping characters
%% See the Body of this document for more details and discussion.

%% ============================================================
%% PREAMBLE

%% The Preamble is where you import packages, configure document settings, and
%% define "commands" (aka, "macros")

%% ----------------------------------------
%% Package imports

%% Some useful basic packages.
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{xspace}

%% This "import" reconfigures the document to add space in between paragraphs
%% and remove paragraph horizontal indentation.
\usepackage[parfill]{parskip}

%% ----------------------------------------
%% Macro definitions

%% Some commands (aka macros) that I (ryanc) defined to help writing math
%% involving sets, logic, etc. Most of these must be used in math mode only.

%% Macros for names of sets (naturals, integers, rationals, reals, ...)
%% These can be used in both math mode and text mode.
\newcommand\NN{\ensuremath{\mathbb{N}}\xspace}
\newcommand\ZZ{\ensuremath{\mathbb{Z}}\xspace}
\newcommand\QQ{\ensuremath{\mathbb{Q}}\xspace}
\newcommand\RR{\ensuremath{\mathbb{R}}\xspace}
\newcommand\RRnn{\ensuremath{\mathbb{R}^{\geq 0}}\xspace}
\newcommand\RRplus{\ensuremath{\mathbb{R}^{+}}\xspace}

%% Literal sets and set-builder notation. Math-mode only.
\newcommand\set[1]{\left\{#1\right\}}
\newcommand\suchthat{~\middle|~} % must be used within \set{}

%% Set operations. Math-mode only.
\newcommand\cardinalityof[1]{\left|#1\right|}
\newcommand\powersetof[1]{\mathcal{P}(#1)}
\newcommand\setcomplementof[1]{\overline{#1}}

%% Style as set name, relation name, predicate names, and object names.
%% Can be used in both math mode and text mode.
\newcommand\sn[1]{\textit{#1}}
\newcommand\rn[1]{\textit{#1}}
\newcommand\pn[1]{\textrm{#1}}
\newcommand\ob[1]{\textsf{#1}}

%% Define a new abbreviation for a set name, etc.
\newcommand\newrn[2]{\newcommand{#1}{\rn{#2}\xspace}}
\newcommand\newsn[2]{\newcommand{#1}{\sn{#2}\xspace}}
\newcommand\newpn[2]{\newcommand{#1}{\pn{#2}\xspace}}
\newcommand\newob[2]{\newcommand{#1}{\ob{#2}\xspace}}

%% Define abbreviations for the "objects" T and F.
\newob{\obT}{T}
\newob{\obF}{F}

%% Logical operators, to match \land, \lor, \lnot
\newcommand\limplies{\Rightarrow}
\newcommand\lequiv{\Leftrightarrow}

%% ----------------------------------------
%% Set document information

%% These change what \maketitle in the body produces.
%% If you are using this file as a template, you should replaces these.
\title{{\LaTeX} Demo and Template}
\author{Ryan Culpepper}
\date{3 February 2024}

%% This is the end of the Preamble.

\begin{document}
%% ============================================================
%% BODY

%% This inserts the title, author, and date configured in the preamble.
\maketitle

This is an example document intended to illustrate some features of \LaTeX.

You should read this document by looking at the source code and the \textsc{pdf}
at the same time. The rendered document will make little sense by itself.

You can also use it as a template for your homework submissions.

Before we start, you need to be aware that {\LaTeX} treats many common
characters specially in source code. Here's a list:
\begin{itemize}

\item \verb|~| means insert an extra space.

  Normally, {\LaTeX} collapses multiple     spaces        into a single space,
  but you can use \verb|~| to insert non-collapsing~~~ horizontal~~~~~~~~~~ space.

  Write \verb|$\sim$| if you need to insert a literal $\sim$ character. \\
  If you write \verb|\~|, it will put a tilde over the next \~character.

\item \verb|#| is special. It is used to represent arguments in macro definitions.

  Write \verb|\#| if you need to insert a literal \# character.

\item \verb|$| starts and ends math mode.

  Write \verb|\$| if you need to insert a literal \$ character.

\item \verb|%| starts a comment until the end of the line.

  Write \verb|\%| if you need to insert a literal \% character.

\item \verb |^| makes a superscript in math mode. It is not allowed in text mode.

  Write \verb|\^{}| to insert a literal \^{} character. \\
  If you write \verb|\^| by itself, it will put a circumflex over the next \^character.

\item \verb|&| is used to separate array elements, table elements, etc.

  Write \verb|\&| to insert a literal \& character.

\item \verb|_| makes a subscript in math mode, like $x_0$; it is not allowed in
  text mode. Add grouping around multi-character subscripts: $x_{123}$, not
  $x_123$.

  Write \verb|\_| to insert a literal \_ character.

\item \verb|<| and \verb|>| in text mode typeset strangely in some {\LaTeX}/font
  engines. They typeset as $<$ and $>$ in math mode.

\end{itemize}

Beware: \verb|\verb| is a weird command, useful mainly for talking about
{\LaTeX} within {\LaTeX}. I need it for this document, but you should avoid it.

Braces {by {themselves}} just {indicate {grouping}}; they must match, but they
are not printed. {Some \tiny changes} end when the current group ends.

\section{Math Mode}

Use \verb|$| to enter single-line math mode: $x^2 + y^2 = 0$.

Use \verb|\[| and \verb|\]| to enter and exit ``display-math'' mode:
\[
x^2 + y^2 = 0
\]
You can also use the \verb|align*| environment for multi-line displayed math:
\begin{align*}
  %% Write & where you want each line to be aligned with other lines
  %% (usually before the = sign). Write \\ between lines.
  %% You cannot leave a blank line (a paragraph skip) inside of {align*}.
  f(x) &= x^2 + y^2
  \\
  f(0) &= 0
  \\
  b &= (a+1)(a-1)
  \\
  &= a^2 - 1
  \\
  &\leq a^2
\end{align*}

The \verb|{align*}| environment is also useful for showing calculations along
with short justifications:
\begin{align*}
  & (x + 9)(x - 2) + 3(x + 14) \\
  &= x^2 - 2x + 9x - 18 + 3(x + 14)     \tag*{by FOIL} \\
  &= x^2 + 7x - 18 + 3x + 42            \tag*{simplify} \\
  &= x^2 + 10x + 24                     \tag*{simplify} \\
  &= (x + 4) (x + 6)                    \tag*{factor}
\end{align*}



Other useful symbols: $1 \neq 2$, $3 \leq 4$, $5 \geq 4$.

\subsection{Sets}

The most important set is the empty set, $\emptyset$. After that, the next most
important is the set of natural numbers, $\NN$. (If you don't include my macro
definitions from the Preamble, you can write this as $\mathbb{N}$, but you still
need the \verb|\usepackage{amssymb}| declaration.) Then $\QQ$, $\RR$, and so on.

The Cartesian product is written $A \times B$.

The powerset of $A$ is written $\powersetof{A}$, if you use my macro
definition. It's a command that takes an argument; you must write the argument
in braces. Similarly, complement is written $\setcomplementof{A}$ or $\overline{A}$.

You can write a literal set like $\{1,2,3\}$, but it's easy to forget the
backslashes and write ${1,2,3}$ by mistake. I prefer to write
$\set{1,2,3}$. (Again, \verb|\set| is a command that takes an argument. It just
takes one; the commas are treated as ordinary text.) The macro scales the braces
automatically: $\set{10^2, a_0, \frac{1}{4}}$ but
\[
\set{10^2, a_0, \frac{1}{4}}
\]

You can also use \verb|\set| to write set-builder expressions. For example:
\[
\set{ x^2 \suchthat x \in \RR }
\]
or $\set{ n^2 \suchthat n \in \NN,~ n < 10 }$. Notice I used \verb|~| to put
some extra space after the comma, to make it look better.

The Preamble defines styles for using whole words as set names and for
typesetting ``object'' names:
\begin{align*}
  \sn{Color} &= \set{ \ob{red}, \ob{blue}, \ob{green} }
  \\
  \sn{City} &= \set{ \ob{Boston}, \ob{Worcester}, \ob{Lowell} }
\end{align*}

Other symbols: $x \in S$, $S \subseteq T$, $S \subset T$. \\
(Beware, $\subseteq$ is ``subset'', and $\subset$ is ``proper subset''!)

\subsection{Logic}

Use \obT and \obF for the truth values, true and false.

Commands for the logical connectives:
\begin{center}
\begin{tabular}{lc}
  \textbf{Connective} & \textbf{Example}
  \\ \hline
  Conjunction & $P \land Q$  % \land = logical and (builtin)
  \\
  Disjunction & $P \lor Q$   % \lor = logical or (builtin)
  \\
  Implication & $P \limplies Q$ % (defined in preamble)
  \\
  Biconditional & $P \lequiv Q$ % (defined in preamble)
  \\
  Negation    & $\lnot P$    % (builtin)
\end{tabular}
\end{center}

The quantifiers are written $\forall$ and $\exists$, as in
\[
\forall n \in \NN,~ \exists p \in \NN,~ n < p
\]
I think the commas here benefit from some extra space too.



\newpage
\section{Wrap Up}

I recommend forcing a new page for each separate problem on your homework
submission. Remember that you must tell Gradescope where to find the answer to
each sub-problem in your \textsc{pdf} document.

Some final advice:
\begin{enumerate}
\item Writing {\LaTeX} takes time. Start early.
\item Always read the rendered document to make sure that it actually says what
  you intended to say.
\end{enumerate}


%% ============================================================
%% END OF DOCUMENT
\end{document}

%% You can actually put \end{document} anywhere after \begin{document}, and
%% latex will ignore everything after that. It can be useful when you're trying
%% to find the source of an error, if latex doesn't give you a useful line
%% number: put \end{document} somewhere in the middle of your document (between
%% paragraphs), and if the error disappears, then the error is somewhere after
%% that. You can gradually move the \end{document} down one paragraph at a time
%% to find out where it is.
