ea-hwtp.sty
% ea-hwtp.sty - A LaTeX style file for homework assignments
% Author: Evan Angelone
% Description: Provides environments and commands for student homework submissions

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ea-hwtp}[2026/01/01 Homework Template Package]
\@twosidetrue

%% ============================================
%% Package Options
%% ============================================
\newif\if@microtype
\@microtypefalse  % Default: microtype off

\newif\if@showsolutions
\@showsolutionstrue  % Default: show solutions

\DeclareOption{microtype}{\@microtypetrue}
\DeclareOption*{%
	\edef\@eahwtp@curopt{\CurrentOption}%
	\def\@eahwtp@shst{showsolutions=true}%
	\def\@eahwtp@shsf{showsolutions=false}%
	\ifx\@eahwtp@curopt\@eahwtp@shst
		\@showsolutionstrue
	\else\ifx\@eahwtp@curopt\@eahwtp@shsf
		\@showsolutionsfalse
	\else
		\PackageWarning{ea-hwtp}{Unknown option '\CurrentOption'}%
	\fi\fi
}
\ProcessOptions\relax

%% ============================================
%% Required Packages
%% ============================================
\RequirePackage[nosumlimits]{amsmath}
\RequirePackage{amssymb}
\RequirePackage{amsthm}
%% On LaTeX 2026-06-01+ aliascnt is a shim over the kernel's \newcounteralias
%% and warns that it is obsolete. The shim still works; silence that one line.
\let\ea@PackageWarning\PackageWarning
\let\PackageWarning\@gobbletwo
\RequirePackage{aliascnt}
\let\PackageWarning\ea@PackageWarning
\RequirePackage[dvipsnames, x11names, svgnames]{xcolor}
\RequirePackage{etoolbox}
\RequirePackage{fancyhdr}
\RequirePackage[margin=1in]{geometry}
\RequirePackage{setspace}
    \setdisplayskipstretch{1}
\RequirePackage[most]{tcolorbox}

%% Conditionally load microtype
\if@microtype
    \RequirePackage[%
        activate=true,
        tracking=true,
        kerning=true
    ]{microtype}
\fi

%% ============================================
%% Color Definitions
%% ============================================
\definecolor{linkblue}{RGB}{20, 72, 140}
\definecolor{urlmagenta}{RGB}{128, 0, 128}
\definecolor{exercisecolor}{RGB}{63, 101, 118}
\definecolor{solutioncolor}{RGB}{126, 138, 101}
\definecolor{GGHeader}{RGB}{58, 59, 60}
\definecolor{GGBold}{RGB}{26, 23, 24}
\definecolor{GGText}{RGB}{47, 47, 48}
\definecolor{Eggshell}{RGB}{240, 240, 239}

%% ============================================
%% Default Text and Bold Colors
%% ============================================
\AtBeginDocument{%
	\color{GGText}% Set default text color
}

% Redefine \bfseries to include color
\let\oldtextbf\textbf
\renewcommand{\textbf}[1]{{\bfseries\color{GGBold}#1}}

% Redefine \emph to include color
\let\oldemph\emph
\renewcommand{\emph}[1]{{\itshape\color{GGBold}#1}}

% For section headers
\RequirePackage{titlesec}
\titleformat{\section}
	{\normalfont\Large\bfseries\color{GGHeader}}{\thesection}{1em}{}
\titleformat{\subsection}
	{\normalfont\large\bfseries\color{GGHeader}}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
	{\normalfont\normalsize\bfseries\color{GGHeader}}{\thesubsubsection}{1em}{}

%% ============================================
%% Internal Storage Commands
%% ============================================
\newcommand{\@hwname}{}
\newcommand{\@hwdate}{\today}
\newcommand{\@hwcourse}{}
\newcommand{\@hwtitle}{Homework}
\renewcommand{\and}{%
	\unskip, % comma separator
}

%% User-facing commands to set metadata
\newcommand{\name}[1]{\renewcommand{\@hwname}{#1}}
\renewcommand{\date}[1]{\renewcommand{\@hwdate}{#1}}
\newcommand{\course}[1]{\renewcommand{\@hwcourse}{#1}}
\newcommand{\homework}[1]{\renewcommand{\@hwtitle}{#1}}

%% ============================================
%% Hyperref Configuration (loaded last for compatibility)
%% ============================================
\AtEndPreamble{%
	\RequirePackage{hyperref}
	\hypersetup{
		colorlinks=true,
		linkcolor=red,
		citecolor=green,
		urlcolor=magenta,
		filecolor=cyan,
		pdftitle={\@hwtitle},
		pdfauthor={\@hwname},
		pdfsubject={\@hwcourse},
		pdfcreator={LaTeX with ea-hwtp.sty},
	}
}

%% ============================================
%% Title Config
%% ============================================

\renewcommand{\@maketitle}{%
	\noindent
	{\Large\bfseries\color{GGBold}\@hwtitle}
	\hfill
	{\color{GGHeader}\@hwcourse}
	\hfill
	{\color{GGHeader}\@hwname}
	\hfill
	{\slshape\color{GGHeader}\@hwdate}
	\bigskip
}

\let\oldmaketitle\maketitle
\renewcommand{\maketitle}{\oldmaketitle\thispagestyle{empty}}

%% ============================================
%% Theorem-like Environments (Numbered)
%% ============================================
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]

\newaliascnt{lemma}{theorem}
\newtheorem{lemma}[lemma]{Lemma}
\aliascntresetthe{lemma}

\newaliascnt{corollary}{theorem}
\newtheorem{corollary}[corollary]{Corollary}
\aliascntresetthe{corollary}

\newaliascnt{proposition}{theorem}
\newtheorem{proposition}[proposition]{Proposition}
\aliascntresetthe{proposition}

\newaliascnt{conjecture}{theorem}
\newtheorem{conjecture}[conjecture]{Conjecture}
\aliascntresetthe{conjecture}

\newaliascnt{claim}{theorem}
\newtheorem{claim}[claim]{Claim}
\aliascntresetthe{claim}

\theoremstyle{definition}
\newaliascnt{definition}{theorem}
\newtheorem{definition}[definition]{Definition}
\aliascntresetthe{definition}

\newaliascnt{example}{theorem}
\newtheorem{example}[example]{Example}
\aliascntresetthe{example}

\newaliascnt{notation}{theorem}
\newtheorem{notation}[notation]{Notation}
\aliascntresetthe{notation}

\theoremstyle{remark}
\newaliascnt{remark}{theorem}
\newtheorem{remark}[remark]{Remark}
\aliascntresetthe{remark}

\newaliascnt{note}{theorem}
\newtheorem{note}[note]{Note}
\aliascntresetthe{note}

%% \autoref names: hyperref supplies only \theoremautorefname
\providecommand*{\lemmaautorefname}{Lemma}
\providecommand*{\corollaryautorefname}{Corollary}
\providecommand*{\propositionautorefname}{Proposition}
\providecommand*{\conjectureautorefname}{Conjecture}
\providecommand*{\claimautorefname}{Claim}
\providecommand*{\definitionautorefname}{Definition}
\providecommand*{\exampleautorefname}{Example}
\providecommand*{\notationautorefname}{Notation}
\providecommand*{\remarkautorefname}{Remark}
\providecommand*{\noteautorefname}{Note}
\providecommand*{\exerciseautorefname}{Exercise}

%% ============================================
%% Exercise Environment
%% ============================================
\newcounter{exercise}[section]
\renewcommand{\theexercise}{\thesection.\arabic{exercise}}

% Reset counter format if no sections are used
\AtBeginDocument{%
	\@ifundefined{c@section}{}{%
		\ifnum\value{section}=0
			\renewcommand{\theexercise}{\arabic{exercise}}
		\fi
	}
}

\newenvironment{exercise}[1][]{%
	\refstepcounter{exercise}%
	\par\medskip\noindent
	\ifx\\#1\\%
		\markright{Exercise~\theexercise\ Solution}%
		\textbf{Exercise~\theexercise.}%
	\else
		\markright{#1\ Solution}%
		\textbf{#1.}%
	\fi
	\quad
}{\par}

\newenvironment{exercise*}[1][]{%
	\par\medskip\noindent
	\ifx\\#1\\%
		\textbf{Exercise.}%
	\else
		\textbf{#1.}%
	\fi
	\quad
}{\par}


\RequirePackage{enumitem}
\setlist[enumerate]{
    label=(\alph*),
    ref=(\alph*),
	labelsep=10pt,
	itemsep=0pt,
	parsep=2pt,
	topsep=3pt
}

\setlist[itemize]{
	labelsep=10pt,
	itemsep=0pt,
	parsep=2pt,
	topsep=2pt
}

%% ============================================
%% Solution Environment (breakable colored box)
%% ============================================
\newtcolorbox{solution}{
	breakable,
	enhanced,
	parbox=false,
	colback=Eggshell!40,
	colframe=Eggshell!60,
	colupper=GGText,
	boxrule=1pt,
	arc=3pt,
	left=4pt,
	right=4pt,
	top=4pt,
	bottom=4pt,
	before skip=\bigskipamount,
	after skip=\bigskipamount,
	title={\textbf{Solution}},
	attach title to upper={\qquad}
}

\if@showsolutions\else
	\renewenvironment{solution}{\setbox\z@\vbox\bgroup}{\egroup}
\fi

%% ============================================
%% Proof Environment (redefine for consistency)
%% ============================================
\renewenvironment{proof}[1][Proof]{%
	\par\pushQED{\qed}%
	\normalfont \topsep6\p@\@plus6\p@\relax
	\trivlist
	\item[\hskip\labelsep\itshape #1\@addpunct{.}]\ignorespaces
}{%
	\popQED\endtrivlist\@endpefalse
}

\newenvironment{proof*}[1][Proof]{%
	\par
	\normalfont \topsep6\p@\@plus6\p@\relax
	\trivlist
	\item[\hskip\labelsep\itshape #1\@addpunct{.}]\ignorespaces
}{%
	\endtrivlist\@endpefalse
}

%% ============================================
%% Header/Footer Configuration
%% ============================================
	\pagestyle{fancy}
	\fancyhf{}
	\fancyhead[C]{\footnotesize\sffamily\color{GGHeader}\rightmark}
	\fancyhead[L]{\footnotesize\sffamily\color{GGHeader}\MakeUppercase{\@hwtitle}}
	\fancyhead[R]{\footnotesize\sffamily\color{GGHeader}\@hwname}
	\fancyfoot[RO,LE]{\footnotesize\sffamily\color{GGHeader}\thepage}
	\renewcommand{\headrulewidth}{0pt}
	\renewcommand{\footrulewidth}{0pt}

%% ============================================
%% Convenience Commands
%% ============================================
% Common math operators
\DeclareMathOperator{\Ima}{Im}
\DeclareMathOperator{\Ker}{Ker}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator{\sgn}{sgn}

% Shorthand for common sets
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\F}{\mathbb{F}}

% Paired delimiters (requires mathtools if you want auto-sizing)
\newcommand{\abs}[1]{\left|#1\right|}
\newcommand{\norm}[1]{\left\|#1\right\|}
\newcommand{\inner}[1]{\left\langle #1 \right\rangle}
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
\newcommand{\ceil}[1]{\left\lceil #1 \right\rceil}

\endinput