% Preamble for MATH5975 Introduction to Stochastic Analysis Notes
\documentclass[a4paper, 11pt]{article}

% Encoding and fonts (LuaLaTeX)
\usepackage{fontspec}

% Page geometry - tighter spacing to match original
\usepackage[a4paper, top=2cm, left=1cm, right=1cm]{geometry}

% Colors
\usepackage[dvipsnames]{xcolor}
\definecolor{linkblue}{HTML}{00007B}
\definecolor{exampleblue}{HTML}{4169E1}
\definecolor{highlightred}{HTML}{B22222}
\definecolor{highlightblue}{HTML}{0000FF}
\definecolor{notegray}{HTML}{7F807F}
\definecolor{highlightsalmon}{HTML}{F08080}
\definecolor{highlightgreen}{HTML}{006400}
\definecolor{examplebarbg}{rgb}{0.255, 0.41, 0.884}

% Mathematics
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{thmtools}
\usepackage{mathrsfs}
\usepackage{bm}

% Headers and footers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\textit{Melantha Wang}}
\rhead{\thepage}
\renewcommand{\headrulewidth}{0pt}

% Hyperlinks
\usepackage[colorlinks=true, linkcolor=linkblue, citecolor=linkblue, urlcolor=linkblue]{hyperref}

% Lists
\usepackage[shortlabels]{enumitem}

% Graphics and diagrams
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{caption}
\usetikzlibrary{arrows.meta, positioning, shapes.geometric, calc}

% Boxes for examples
\usepackage{mdframed}

% Footnotes
\usepackage[bottom]{footmisc}

% Tighter spacing
\usepackage{parskip}
\setlength{\parskip}{0pt plus 1pt}

% Section heading styles
\usepackage{titlesec}
\titleformat{\section}
  {\normalfont\normalsize\centering}
  {\thesection}
  {1em}
  {\scshape}
\titleformat{\subsection}
  {\normalfont\bfseries\fontsize{12}{14.4}\selectfont}
  {\thesubsection}
  {1em}
  {}
\titleformat{\subsubsection}
  {\normalfont\bfseries}
  {\thesubsubsection}
  {1em}
  {}

% -------------------------------------------------------
% Theorem environments
% -------------------------------------------------------
% Italic body style (for theorem-like environments)
\newtheoremstyle{italicbody}%
  {3pt}{3pt}%
  {\itshape}{}%
  {\bfseries}{.}%
  { }{}

% Upright body style (for definition-like environments)
\newtheoremstyle{uprightbody}%
  {3pt}{3pt}%
  {}{}%
  {\bfseries}{.}%
  { }{}

% Theorem environments with italic body, each with own counter
\theoremstyle{italicbody}
\newtheorem{theorem}{Theorem}[subsection]
\newtheorem{lemma}{Lemma}[subsection]
\newtheorem{corollary}{Corollary}[subsection]
\newtheorem{proposition}{Proposition}[subsection]

% Definition-like environments with upright body, each with own counter
\theoremstyle{uprightbody}
\newtheorem{definition}{Definition}[subsection]
\newtheorem{examplesinner}{Examples}[subsection]
\newtheorem{remark}{Remark}[subsection]

% Result environment (from exercise)
\newtheorem{result}{Result}[subsection]

% -------------------------------------------------------
% Examples environment with blue left border bar
% -------------------------------------------------------
\newmdenv[
  leftline=true,
  rightline=false,
  topline=false,
  bottomline=false,
  linewidth=3pt,
  linecolor=examplebarbg,
  innerleftmargin=10pt,
  innerrightmargin=0pt,
  innertopmargin=2pt,
  innerbottommargin=2pt,
  skipabove=3pt,
  skipbelow=3pt
]{examplebox}

\newenvironment{examples}[1][]{%
  \begin{examplebox}%
  \refstepcounter{examplesinner}%
  {\color{exampleblue}\sffamily\bfseries Examples~\theexamplesinner\ifx\\#1\\\else\ (#1)\fi.}\,%
}{%
  \end{examplebox}%
}

% Fix duplicate hyperref destinations across sections
\renewcommand{\theHtheorem}{\thesection.\thesubsection.\arabic{theorem}}
\renewcommand{\theHlemma}{\thesection.\thesubsection.\arabic{lemma}}
\renewcommand{\theHcorollary}{\thesection.\thesubsection.\arabic{corollary}}
\renewcommand{\theHproposition}{\thesection.\thesubsection.\arabic{proposition}}
\renewcommand{\theHdefinition}{\thesection.\thesubsection.\arabic{definition}}
\renewcommand{\theHexamplesinner}{\thesection.\thesubsection.\arabic{examplesinner}}
\renewcommand{\theHremark}{\thesection.\thesubsection.\arabic{remark}}
\renewcommand{\theHresult}{\thesection.\thesubsection.\arabic{result}}

% -------------------------------------------------------
% Custom commands
% -------------------------------------------------------
\newcommand{\E}{\mathbb{E}}
\newcommand{\Var}{\operatorname{Var}}
\newcommand{\Cov}{\operatorname{Cov}}
\renewcommand{\P}{\mathbb{P}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathcal{N}}
\newcommand{\F}{\mathcal{F}}
\newcommand{\G}{\mathcal{G}}
\newcommand{\A}{\mathcal{A}}
\newcommand{\B}{\mathcal{B}}
\newcommand{\Sc}{\mathcal{S}^c}
\newcommand{\Lp}{\mathcal{L}}
\newcommand{\indic}{\mathbf{1}}
\DeclareMathOperator{\sgn}{sgn}

% Color highlight commands for math terms
\newcommand{\hblue}[1]{{\color{highlightblue}#1}}
\newcommand{\hred}[1]{{\color{highlightred}#1}}
\newcommand{\hgray}[1]{{\color{notegray}#1}}
\newcommand{\hsalmon}[1]{{\color{highlightsalmon}#1}}
\newcommand{\hgreen}[1]{{\color{highlightgreen}#1}}

% Tombstone for proofs
\renewcommand{\qedsymbol}{$\blacksquare$}
