\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{preamble}[2026/05/08 STAT 571 lecture notes preamble]

% Engine: lualatex (also compiles under pdflatex with this all-legacy stack).

% ------- Encoding & geometry -------
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, margin=2.5cm, top=2.6cm, bottom=2.6cm, headheight=14pt]{geometry}

% ------- Math packages -------
\usepackage{amsmath, amsthm, amssymb}   % amssymb gives \blacksquare etc.
\usepackage{mathtools}
\usepackage{bm}

% ------- Fonts (Baskervaldx + newtxmath; LaTeX Companion recipe) -------
% Body: Baskervaldx with old-style figures.
% Math: newtxmath tuned to Baskervaldx; vvarbb gives the variant blackboard.
% Cal:  Boondox-O (open-style calligraphic) via mathalfa.
% Sans: Cabin. Mono: Inconsolata.
\usepackage[osf]{Baskervaldx}
\usepackage[baskervaldx, vvarbb]{newtxmath}
\usepackage[cal=boondoxo]{mathalfa}
\usepackage[scaled=0.95]{cabin}
\usepackage[varqu, varl, scaled=0.93]{inconsolata}
\linespread{1.06}
\usepackage{microtype}

% Empty set: rebind \emptyset to \varnothing.
\let\emptyset\varnothing

% ------- Graphics & TikZ -------
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, shapes.geometric, calc, fit,
                decorations.pathreplacing, decorations.pathmorphing}
\usepackage{tikz-cd}
\usepackage{caption}
\captionsetup{font=small, labelfont={sf,bf}, labelsep=period, justification=centering}
% Stable image search paths so lectures can write \includegraphics{page-NN-img-KK.jpg}
\graphicspath{
  {./figures/lec1-4/}
  {./figures/lecs5-13/}
  {./figures/}
}

% ------- Layout -------
\usepackage{titlesec}
\usepackage{titling}
\usepackage[bottom]{footmisc}
\usepackage{enumitem}
\setlist{itemsep=2pt, topsep=4pt}
\setlength{\parskip}{4pt plus 1pt minus 0pt}
\setlength{\parindent}{0pt}

% ------- Colour palette (matched to UNSW MATH3901 reference) -------
\usepackage{xcolor}
\definecolor{linkblue}{HTML}{00007B}
\definecolor{deepnavy}{HTML}{1F2D5A}
\definecolor{defheaderbg}{HTML}{1F2D5A}     % navy header for definitions
\definecolor{defbodybg}{HTML}{E8EEF8}        % pale blue body
\definecolor{thmheaderbg}{HTML}{8A4B0A}      % warm brown header for theorems
\definecolor{thmbodybg}{HTML}{FBF1DC}        % cream body
\definecolor{lemheaderbg}{HTML}{0F5C5A}      % teal header for lemmas/props
\definecolor{lembodybg}{HTML}{E4F1EF}        % pale teal body
\definecolor{exampleblue}{HTML}{2A5DB0}
\definecolor{remarkgray}{HTML}{4A4A4A}
% --- highlighters from scratch.org ---
\definecolor{highlightred}{HTML}{B22222}
\definecolor{highlightblue}{HTML}{0000FF}
\definecolor{notegray}{HTML}{7F807F}
\definecolor{highlightsalmon}{HTML}{F08080}
\definecolor{highlightgreen}{HTML}{006400}

% ------- Hyperlinks & cross-refs -------
\usepackage[colorlinks=true,linkcolor=linkblue,citecolor=linkblue,urlcolor=linkblue]{hyperref}
\usepackage[capitalise,noabbrev]{cleveref}
% All tcolorbox theorem-like envs share the counter `tcb@cnt@definition`.
% Without this, \cref{thm:foo} prints "?? N.M" and emits an "unknown
% reference format" warning. We use sentence-case names by suffix on the
% label, but the shared counter forces a single fallback name; "Result"
% reads naturally regardless of which env was tagged.
\crefname{tcb@cnt@definition}{Result}{Results}
\Crefname{tcb@cnt@definition}{Result}{Results}

% ------- Section title styling (sans-serif navy, like the reference) -------
\titleformat{\section}
  {\sffamily\Large\bfseries\color{deepnavy}}
  {\thesection}{0.6em}{}
\titleformat{\subsection}
  {\sffamily\large\bfseries\color{deepnavy}}
  {\thesubsection}{0.5em}{}
\titleformat{\subsubsection}
  {\sffamily\normalsize\bfseries\color{deepnavy}}
  {\thesubsubsection}{0.4em}{}

% ------- Coloured theorem/definition boxes (tcolorbox) -------
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems, breakable}

\tcbset{
  basebox/.style={
    enhanced, breakable,
    arc=0pt, outer arc=0pt,
    boxrule=0pt, titlerule=0pt,
    left=10pt, right=10pt, top=6pt, bottom=6pt,
    toptitle=4pt, bottomtitle=4pt, lefttitle=10pt,
    fonttitle=\sffamily\bfseries,
    coltitle=white,
    before skip=8pt, after skip=8pt,
  }
}

% IMPORTANT: the 4th argument to \newtcbtheorem is an *auto-prepended*
% label prefix. So `\begin{definition}{Title}{foo}` produces label
% "def:foo"; cross-refer to it with \cref{def:foo}.
% DO NOT include the prefix in the env's label arg, or you'll get
% "def:def:foo" and \cref will break.
\newtcbtheorem[number within=section]{definition}{Definition}{
  basebox, colback=defbodybg, colframe=defbodybg, colbacktitle=defheaderbg,
}{def}

\newtcbtheorem[use counter from=definition]{theorem}{Theorem}{
  basebox, colback=thmbodybg, colframe=thmbodybg, colbacktitle=thmheaderbg,
}{thm}

\newtcbtheorem[use counter from=definition]{lemma}{Lemma}{
  basebox, colback=lembodybg, colframe=lembodybg, colbacktitle=lemheaderbg,
}{lem}

\newtcbtheorem[use counter from=definition]{proposition}{Proposition}{
  basebox, colback=lembodybg, colframe=lembodybg, colbacktitle=lemheaderbg,
}{prop}

\newtcbtheorem[use counter from=definition]{corollary}{Corollary}{
  basebox, colback=lembodybg, colframe=lembodybg, colbacktitle=lemheaderbg,
}{cor}

% ------- Example environment: blue left bar (scratch.org style) -------
\usepackage{mdframed}
\newmdenv[
  leftline=true, rightline=false, topline=false, bottomline=false,
  linewidth=3pt, linecolor=exampleblue,
  innerleftmargin=10pt, innerrightmargin=0pt,
  innertopmargin=2pt, innerbottommargin=2pt,
  skipabove=6pt, skipbelow=6pt
]{examplebox}

\newcounter{example}[section]
\renewcommand{\theexample}{\thesection.\arabic{example}}
\newenvironment{example}[1][]{%
  \refstepcounter{example}%
  \begin{examplebox}%
    {\sffamily\bfseries\color{exampleblue}$\blacksquare$~Example~\theexample\ifx\\#1\\\else\ (#1)\fi.}\,%
}{\end{examplebox}}

% Remark: italic body, sans-serif gray header (no box)
\newtheoremstyle{remarkstyle}
  {4pt}{4pt}{}{}{\sffamily\bfseries\color{remarkgray}}{.}{ }{}
\theoremstyle{remarkstyle}
\newtheorem{remark}{Remark}[section]

% Note (margin-style commentary) — also boxless, smaller
\newtheoremstyle{notestyle}
  {3pt}{3pt}{\small}{}{\sffamily\bfseries\color{remarkgray}}{.}{ }{}
\theoremstyle{notestyle}
\newtheorem{note}{Note}[section]

% Proof: keep amsthm default but tweak qed
\renewcommand{\qedsymbol}{$\blacksquare$}

% ------- Headers / footers -------
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\sffamily\small\nouppercase{\leftmark}}
\fancyhead[R]{\sffamily\small\thepage}
\fancyfoot[R]{\sffamily\small\itshape A.B}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}}

% ------- Math macros (mostly inherited from scratch.org) -------
\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{\C}{\mathbb{C}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
% caligraphic versions (avoid clash with single-letter \A, \B, etc.)
\newcommand{\Fcal}{\mathcal{F}}
\newcommand{\Gcal}{\mathcal{G}}
\newcommand{\Acal}{\mathcal{A}}
\newcommand{\Bcal}{\mathcal{B}}
\newcommand{\Ccal}{\mathcal{C}}
\newcommand{\Dcal}{\mathcal{D}}
\newcommand{\Ecal}{\mathcal{E}}
\newcommand{\Mcal}{\mathcal{M}}
\newcommand{\Ncal}{\mathcal{N}}
\newcommand{\Ocal}{\mathcal{O}}
\newcommand{\Pcal}{\mathcal{P}}
\newcommand{\Lcal}{\mathcal{L}}
\newcommand{\Scal}{\mathcal{S}}
\newcommand{\Rcal}{\mathcal{R}}
\newcommand{\Tcal}{\mathcal{T}}
\newcommand{\Vcal}{\mathcal{V}}
\newcommand{\Wcal}{\mathcal{W}}
\newcommand{\Xcal}{\mathcal{X}}
\newcommand{\Ycal}{\mathcal{Y}}
\newcommand{\Zcal}{\mathcal{Z}}
% Blackboard SET letters for product-measure spaces (Kashlak §2.4 convention:
% (X, X-cal, mu) and (Y, Y-cal, nu) where the bold letter is the set and the
% calligraphic letter is the sigma-field).
\newcommand{\Xset}{\mathbb{X}}
\newcommand{\Yset}{\mathbb{Y}}
\newcommand{\Zset}{\mathbb{Z}}
\newcommand{\indic}{\mathbf{1}}
\DeclareMathOperator{\sgn}{sgn}
\DeclareMathOperator*{\esssup}{ess\,sup}
\DeclareMathOperator*{\essinf}{ess\,inf}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}

% Inline highlight macros (from scratch.org)
\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}}

\endinput
