%% modernclassnotes.sty
%% Copyright 2026 Modern Class Notes Project
%%
%% Package extension for modernclassnotes style integration in standard
%% article, report, or book classes.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{modernclassnotes}[2026/08/04 v1.1.0 Modern Class Notes Package]

% -------------------------------------------------------------------
% Package Options & Key-Value Handling
% -------------------------------------------------------------------
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
  family=mcn,
  prefix=mcn@
}

\DeclareStringOption[notes]{mode}        % notes, handout, worksheet, chapternotes
\DeclareStringOption[ocean]{palette}     % ocean, midnight, nord, emerald, burgundy, amethyst, purple, mono
\DeclareStringOption[default]{font}      % default, palatino, charter, sans/helvet, kpfonts, pagella, sourceserif, fira, libertine, utopia
\DeclareBoolOption[true]{showsolutions}  % show/hide solutions in worksheets
\DeclareBoolOption[true]{parskip}        % toggle paragraph spacing
\DeclareBoolOption[false]{official}      % include prof and institution in footer if true

\ProcessKeyvalOptions*

% -------------------------------------------------------------------
% Core Dependencies
% -------------------------------------------------------------------
%\RequirePackage[utf8]{inputenc} % not needed when using xelatex / modern LaTeX2e
\RequirePackage[T1]{fontenc}
\RequirePackage{xcolor}
\RequirePackage{geometry}
\RequirePackage{amsmath,amssymb,amsthm}
\RequirePackage{fancyhdr}
\RequirePackage{etoolbox}
\RequirePackage{listings}
\RequirePackage{caption}
\RequirePackage{booktabs}
\RequirePackage{array}
\RequirePackage{iftex}
\RequirePackage{verbatim}
\RequirePackage{xparse}    % for \NewDocumentCommand
\IfFileExists{enumitem.sty}{\RequirePackage{enumitem}}{}

\ifmcn@parskip
  \RequirePackage{parskip}
\fi

% Geometry configuration
\geometry{a4paper, top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm, headheight=28pt, headsep=15pt}

% -------------------------------------------------------------------
% Itemize bullet point symbols config
% -------------------------------------------------------------------
\renewcommand{\labelitemi}{$\bullet$}
\renewcommand{\labelitemii}{$\circ$}
\renewcommand{\labelitemiii}{$\blacksquare$}
\renewcommand{\labelitemiv}{$\diamond$}

% -------------------------------------------------------------------
% Font Selection Presets
% -------------------------------------------------------------------
% Default Latin Modern / Computer Modern
\RequirePackage{lmodern}
% font option override: kpfonts
\expandafter\ifstrequal\expandafter{\mcn@font}{kpfonts}{%
  \IfFileExists{kpfonts.sty}{\RequirePackage{kpfonts}}{}%
}{}
% font option override: pagella
\expandafter\ifstrequal\expandafter{\mcn@font}{pagella}{%
  \IfFileExists{tgpagella.sty}{\RequirePackage{tgpagella}}{\RequirePackage{mathpazo}}%
}{}
% font option override: sourceserif
\expandafter\ifstrequal\expandafter{\mcn@font}{sourceserif}{%
  \IfFileExists{sourceserifpro.sty}{%
    \RequirePackage{sourceserifpro}%
  }{%
    \IfFileExists{sourcesanspro.sty}{\RequirePackage{sourcesanspro}}{}%
  }%
  \IfFileExists{newtxmath.sty}{\RequirePackage{newtxmath}}{}%
}{}
% font option override: charter
\expandafter\ifstrequal\expandafter{\mcn@font}{charter}{%
  \IfFileExists{charter.sty}{\RequirePackage{charter}}{}%
  \IfFileExists{newtxmath.sty}{\RequirePackage{newtxmath}}{}%
}{}
% font option override: helvet / sans
\expandafter\ifstrequal\expandafter{\mcn@font}{helvet}{%
  \IfFileExists{helvet.sty}{\RequirePackage{helvet}}{}%
  \renewcommand{\familydefault}{\sfdefault}%
  \IfFileExists{newtxmath.sty}{\RequirePackage{newtxmath}}{}%
}{}
\expandafter\ifstrequal\expandafter{\mcn@font}{sans}{%
  \IfFileExists{helvet.sty}{\RequirePackage{helvet}}{}%
  \renewcommand{\familydefault}{\sfdefault}%
  \IfFileExists{newtxmath.sty}{\RequirePackage{newtxmath}}{}%
}{}
% font option override: fira
\expandafter\ifstrequal\expandafter{\mcn@font}{fira}{%
  \IfFileExists{FiraSans.sty}{\RequirePackage[sfdefault]{FiraSans}}{\renewcommand{\familydefault}{\sfdefault}}%
  \IfFileExists{FiraMono.sty}{\RequirePackage{FiraMono}}{}%
}{}
% font option override: libertine
\expandafter\ifstrequal\expandafter{\mcn@font}{libertine}{%
  \IfFileExists{libertine.sty}{\RequirePackage{libertine}}{}%
}{}
% font option override: utopia
\expandafter\ifstrequal\expandafter{\mcn@font}{utopia}{%
  \IfFileExists{utopia.sty}{\RequirePackage{utopia}}{}%
}{}

% Color Palette Presets
% Default: Ocean Palette
\definecolor{mcnPrimary}{HTML}{005F73}
\definecolor{mcnSecondary}{HTML}{0A9396}
\definecolor{mcnAccent}{HTML}{94D2BD}
\definecolor{mcnBg}{HTML}{F4F7F6}
\definecolor{mcnText}{HTML}{1D2D35}
\definecolor{mcnBoxBg}{HTML}{EAF4F4}
\definecolor{mcnBorder}{HTML}{CCE3DE}
% palette option override: midnight
\expandafter\ifstrequal\expandafter{\mcn@palette}{midnight}{%
  \definecolor{mcnPrimary}{HTML}{1D2D44}
  \definecolor{mcnSecondary}{HTML}{3A86EF}
  \definecolor{mcnAccent}{HTML}{F72585}
  \definecolor{mcnBg}{HTML}{F8F9FA}
  \definecolor{mcnText}{HTML}{212529}
  \definecolor{mcnBoxBg}{HTML}{EDF2F7}
  \definecolor{mcnBorder}{HTML}{CBD5E0}
}{}
% palette option override: nord
\expandafter\ifstrequal\expandafter{\mcn@palette}{nord}{%
  \definecolor{mcnPrimary}{HTML}{2E3440}
  \definecolor{mcnSecondary}{HTML}{88C0D0}
  \definecolor{mcnAccent}{HTML}{B48EAD}
  \definecolor{mcnBg}{HTML}{F8F9FB}
  \definecolor{mcnText}{HTML}{3B4252}
  \definecolor{mcnBoxBg}{HTML}{ECEFF4}
  \definecolor{mcnBorder}{HTML}{D8DEE9}
}{}
% palette option override: emerald
\expandafter\ifstrequal\expandafter{\mcn@palette}{emerald}{%
  \definecolor{mcnPrimary}{HTML}{1B4332}
  \definecolor{mcnSecondary}{HTML}{2D6A4F}
  \definecolor{mcnAccent}{HTML}{52B788}
  \definecolor{mcnBg}{HTML}{F4F9F5}
  \definecolor{mcnText}{HTML}{1A2E26}
  \definecolor{mcnBoxBg}{HTML}{E8F5E9}
  \definecolor{mcnBorder}{HTML}{C8E6C9}
}{}
% palette option override: burgundy
\expandafter\ifstrequal\expandafter{\mcn@palette}{burgundy}{%
  \definecolor{mcnPrimary}{HTML}{5C061C}
  \definecolor{mcnSecondary}{HTML}{9D0208}
  \definecolor{mcnAccent}{HTML}{DC2F02}
  \definecolor{mcnBg}{HTML}{FAF4F5}
  \definecolor{mcnText}{HTML}{2B0D12}
  \definecolor{mcnBoxBg}{HTML}{F7EBEF}
  \definecolor{mcnBorder}{HTML}{E8C5CE}
}{}
% palette option override: amethyst
\expandafter\ifstrequal\expandafter{\mcn@palette}{amethyst}{%
  \definecolor{mcnPrimary}{HTML}{3A0CA3}
  \definecolor{mcnSecondary}{HTML}{7209B7}
  \definecolor{mcnAccent}{HTML}{4361EE}
  \definecolor{mcnBg}{HTML}{F8F7FF}
  \definecolor{mcnText}{HTML}{1D1A2E}
  \definecolor{mcnBoxBg}{HTML}{F0EEFD}
  \definecolor{mcnBorder}{HTML}{D7D2FA}
}{}
% palette option override: mono
\expandafter\ifstrequal\expandafter{\mcn@palette}{mono}{%
  \definecolor{mcnPrimary}{HTML}{212529}
  \definecolor{mcnSecondary}{HTML}{495057}
  \definecolor{mcnAccent}{HTML}{6C757D}
  \definecolor{mcnBg}{HTML}{FAFAFA}
  \definecolor{mcnText}{HTML}{212529}
  \definecolor{mcnBoxBg}{HTML}{F1F3F5}
  \definecolor{mcnBorder}{HTML}{CED4DA}
}{}
% palette option override: purple
\expandafter\ifstrequal\expandafter{\mcn@palette}{purple}{%
  \definecolor{mcnPrimary}{HTML}{560073}
  \definecolor{mcnSecondary}{HTML}{5D0A96}
  \definecolor{mcnAccent}{HTML}{A294D2}
  \definecolor{mcnBg}{HTML}{F4F4F7}
  \definecolor{mcnText}{HTML}{331D35}
  \definecolor{mcnBoxBg}{HTML}{F0EAF4}
  \definecolor{mcnBorder}{HTML}{D4CCE3}
}{}

\definecolor{mcnTheorem}{HTML}{023E8A}
\definecolor{mcnTheoremBg}{HTML}{EDF4FC}
\definecolor{mcnDefinition}{HTML}{0077B6}
\definecolor{mcnDefinitionBg}{HTML}{EAF6FB}
\definecolor{mcnExample}{HTML}{2B9348}
\definecolor{mcnExampleBg}{HTML}{EEF8F1}
\definecolor{mcnRemark}{HTML}{555555}
\definecolor{mcnRemarkBg}{HTML}{F5F5F5}
\definecolor{mcnWarning}{HTML}{D90429}
\definecolor{mcnWarningBg}{HTML}{FDE8EA}
\definecolor{mcnTip}{HTML}{E07A5F}
\definecolor{mcnTipBg}{HTML}{FDF2EF}

% Metadata macros
\newcommand{\mcn@course}{}
\newcommand{\mcn@coursecode}{}
\newcommand{\mcn@professor}{}
\newcommand{\mcn@institution}{}
\newcommand{\mcn@term}{}
\newcommand{\mcn@docsubtitle}{}

\newcommand{\course}[1]{\renewcommand{\mcn@course}{#1}}
\newcommand{\coursecode}[1]{\renewcommand{\mcn@coursecode}{#1}}
\newcommand{\professor}[1]{\renewcommand{\mcn@professor}{#1}}
\newcommand{\institution}[1]{\renewcommand{\mcn@institution}{#1}}
\newcommand{\term}[1]{\renewcommand{\mcn@term}{#1}}
\newcommand{\docsubtitle}[1]{\renewcommand{\mcn@docsubtitle}{#1}}

% -------------------------------------------------------------------
% Lecture Tracking System
% -------------------------------------------------------------------
\newcounter{lecture}
\newcommand{\lecture}[3][]{% [date]{number}{title}
  \setcounter{lecture}{#2}\addtocounter{lecture}{-1}\refstepcounter{lecture}%
  \def\mcn@currentlecture{Lecture #2: #3}%
  \par\vspace{1.2em}%
  \noindent
  \fcolorbox{mcnSecondary}{mcnBoxBg}{%
    \begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}%
      \vspace{6pt}%
      \noindent\hspace{8pt}%
      \begin{minipage}{\dimexpr\linewidth-16pt\relax}%
        {\raggedright
          {\small\sffamily\bfseries\color{mcnSecondary} LECTURE #2 \ifx&#1&\else\hfill #1\fi}\par\vspace{2pt}%
          {\Large\sffamily\bfseries\color{mcnPrimary} #3}\par
        }%
      \end{minipage}%
      \vspace{6pt}%
    \end{minipage}%
  }%
  \addcontentsline{toc}{section}{Lecture #2: #3}%
  \par\vspace{0.8em}%
}

% -------------------------------------------------------------------
% Chapter Tracking System
% -------------------------------------------------------------------
\newcounter{chapter}

\NewDocumentCommand{\chapter}{m m g}{%  % #1=number, #2=title, #3=objectives (optional)
  \setcounter{chapter}{#1}%
  \def\mcn@currentlecture{Chapter #1: #2}%
  \par\vspace{1.2em}%
  \noindent
  \fcolorbox{mcnSecondary}{mcnBoxBg}{%
    \begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}%
      \vspace{6pt}%
      \noindent\hspace{8pt}%
      \begin{minipage}{\dimexpr\linewidth-16pt\relax}%
        {\raggedright
          {\small\sffamily\bfseries\color{mcnSecondary} CHAPTER #1}\par\vspace{2pt}%
          {\Large\sffamily\bfseries\color{mcnPrimary} #2}\par
        }%
        % ---------- Optional objectives ----------
        \IfValueT{#3}{%
          \par\vspace{-6pt}% space before separator
          {\color{mcnBorder}\rule{\linewidth}{0.5pt}}% separator line (0.5pt elegant)
          \par\vspace{0pt}% space after separator
          \@ifpackageloaded{enumitem}{%
            \begin{enumerate}[
                label=\color{mcnPrimary}\arabic*.,
                nosep,
                leftmargin=*,
                after=\vspace{-\topsep}
              ]%
              \forcsvlist{\mcn@objective@item}{#3}%
            \end{enumerate}%
          }{%
            \begin{enumerate}%
              \setlength{\itemsep}{1pt}%
              \setlength{\parskip}{0pt}%
              \setlength{\parsep}{0pt}%
              \forcsvlist{\mcn@objective@item}{#3}%
            \end{enumerate}%
          }%
          \vspace{0pt}% space after objectives
        }%
        % -----------------------------------------
      \end{minipage}%
      \vspace{6pt}%
    \end{minipage}%
  }%
  \par
  \@ifpackageloaded{hyperref}{\phantomsection}{}
  \addcontentsline{toc}{section}{Chapter #1: #2}%
  \par\vspace{0.3em}%
}
\newcommand{\mcn@objective@item}[1]{\item \textcolor{mcnSecondary}{#1}}

\newcommand{\subchapter}[2]{% {section}{title}
  \par\vspace{0.5em}%
  \noindent
  {\raggedright\large\sffamily\bfseries\color{mcnPrimary}%
    \makebox[2.5em][l]{\thechapter.#1}#2\par}%
  \vspace{-1.1em}% adjust to bring rule closer
  \noindent{\color{mcnBorder}\rule{\linewidth}{2pt}}%
  \vspace{-0.3em}% adjust spacing after rule
  \par
  \phantomsection
  \addcontentsline{toc}{subsection}{%
    \texorpdfstring{%
      \makebox[3em][l]{\thechapter.#1}#2%
    }{%
      \thechapter.#1\ #2%
    }%
  }%
}

% Callout box core macro
\newcommand{\mcn@callout}[5]{% {BorderColor}{BgColor}{Label}{Icon/Prefix}{Content}
  \par\addvspace{0.8em}%
  \noindent
  \fcolorbox{#1}{#2}{%
    \begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}%
      \vspace{6pt}%
      \noindent\hspace{8pt}%
      \begin{minipage}{\dimexpr\linewidth-16pt\relax}%
        {\sffamily\bfseries\color{#1}#4 #3}\par\vspace{4pt}%
        \color{mcnText}#5%
      \end{minipage}%
      \vspace{6pt}%
    \end{minipage}%
  }%
  \par\addvspace{0.8em}%
}

% Pedagogical Environments
\newcounter{mcnTheoremCount}
\newcounter{mcnDefCount}
\newcounter{mcnExampleCount}
\newcounter{mcnExerciseCount}

\newenvironment{theorem}[1][]{%
  \refstepcounter{mcnTheoremCount}%
  \def\mcn@title{Theorem \themcnTheoremCount\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnTheorem}{mcnTheoremBg}{\mcn@title}{[THM]}{\usebox{\mcn@box}}%
}

\newenvironment{lemma}[1][]{%
  \refstepcounter{mcnTheoremCount}%
  \def\mcn@title{Lemma \themcnTheoremCount\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnTheorem}{mcnTheoremBg}{\mcn@title}{[LEM]}{\usebox{\mcn@box}}%
}

\newenvironment{proposition}[1][]{%
  \refstepcounter{mcnTheoremCount}%
  \def\mcn@title{Proposition \themcnTheoremCount\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnTheorem}{mcnTheoremBg}{\mcn@title}{[PROP]}{\usebox{\mcn@box}}%
}

\newenvironment{corollary}[1][]{%
  \refstepcounter{mcnTheoremCount}%
  \def\mcn@title{Corollary \themcnTheoremCount\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnTheorem}{mcnTheoremBg}{\mcn@title}{[COR]}{\usebox{\mcn@box}}%
}

\newenvironment{definition}[1][]{%
  \refstepcounter{mcnDefCount}%
  \def\mcn@title{Definition \themcnDefCount\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnDefinition}{mcnDefinitionBg}{\mcn@title}{[DEF]}{\usebox{\mcn@box}}%
}

\newenvironment{example}[1][]{%
  \refstepcounter{mcnExampleCount}%
  \def\mcn@title{Example \themcnExampleCount\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnExample}{mcnExampleBg}{\mcn@title}{[EX]}{\usebox{\mcn@box}}%
}

\newenvironment{remark}[1][]{%
  \def\mcn@title{Remark\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnRemark}{mcnRemarkBg}{\mcn@title}{[REM]}{\usebox{\mcn@box}}%
}

\newenvironment{warning}[1][]{%
  \def\mcn@title{Warning\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnWarning}{mcnWarningBg}{\mcn@title}{[!]}{\usebox{\mcn@box}}%
}

\newenvironment{tip}[1][]{%
  \def\mcn@title{Pro Tip\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnTip}{mcnTipBg}{\mcn@title}{[*]}{\usebox{\mcn@box}}%
}

\newenvironment{takeaways}{%
  \def\mcn@title{Key Takeaways}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnPrimary}{mcnBoxBg}{\mcn@title}{[KEY]}{\usebox{\mcn@box}}%
}

\newenvironment{exercise}[1][]{%
  \refstepcounter{mcnExerciseCount}%
  \def\mcn@title{Exercise \themcnExerciseCount\ifx&#1&\else\ (#1)\fi}%
  \begin{lrbox}{\mcn@box}%
  \begin{minipage}{\dimexpr\linewidth-24pt\relax}%
}{%
  \end{minipage}%
  \end{lrbox}%
  \mcn@callout{mcnSecondary}{mcnBoxBg}{\mcn@title}{[EXR]}{\usebox{\mcn@box}}%
}

\newenvironment{solution}{%
  \ifmcn@showsolutions
    \par\vspace{0.4em}%
    \noindent{\sffamily\bfseries\color{mcnSecondary}Solution:}\par\vspace{0.2em}%
  \else
    \expandafter\comment
  \fi
}{%
  \ifmcn@showsolutions
    \par\vspace{0.6em}%
  \else
    \expandafter\endcomment
  \fi
}

\newsavebox{\mcn@box}

% Standard Proof environment wrapper
\renewenvironment{proof}[1][Proof]{%
  \par\vspace{0.4em}%
  \noindent{\sffamily\bfseries\color{mcnPrimary}#1:}\quad\ignorespaces
}{%
  \hfill$\blacksquare$\par\vspace{0.6em}%
}

% -------------------------------------------------------------------
% Code Snippets & Listings Integration
% -------------------------------------------------------------------
\lstset{
  basicstyle=\small\ttfamily\color{mcnText},
  keywordstyle=\bfseries\color{mcnPrimary},
  stringstyle=\color{mcnExample},
  commentstyle=\itshape\color{mcnRemark},
  numbers=left,
  numberstyle=\tiny\color{gray},
  stepnumber=1,
  numbersep=8pt,
  backgroundcolor=\color{mcnBoxBg},
  showstringspaces=false,
  tabsize=2,
  breaklines=true,
  breakatwhitespace=false,
  frame=single,
  rulecolor=\color{mcnBorder},
  xleftmargin=12pt,
  framexleftmargin=12pt
}

\newenvironment{codebox}[1][Code Snippet]{%
  \par\vspace{0.5em}%
  \noindent{\small\sffamily\bfseries\color{mcnPrimary}#1}\par\vspace{0.3em}%
}{%
  \par\vspace{0.5em}%
}

\endinput
