% ══════════════════════════════════════════════════════════════════════════════
%  manifold.sty  —  Manifold Mathematics Monograph Series
%  Version 1.0  ·  July 2026
%
%  Usage:
%    \documentclass[11pt,a4paper]{article}
%    \usepackage{manifold}
%    \manifoldheader{Topic Title}        % sets running header
%    \begin{document}
%    \manifoldtitle{Topic Title}         % full title page
%       {Subtitle / description line}
%       {200+ Problems with Complete Solutions}
%       {Keyword One $\cdot$ Keyword Two $\cdot$ Keyword Three}
%       {Keyword Four $\cdot$ Keyword Five $\cdot$ Keyword Six}
%    ...
%    \manifoldcolophon                    % closing footer
%    \end{document}
%
% ══════════════════════════════════════════════════════════════════════════════
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{manifold}[2026/07/22 v1.0 Manifold Mathematics house style]

% ─── Options ─────────────────────────────────────────────────────────────────
\newif\if@manifoldspacing  \@manifoldspacingfalse
\DeclareOption{spacing}{\@manifoldspacingtrue}
\DeclareOption*{\PackageWarning{manifold}{Unknown option '\CurrentOption'}}
\ProcessOptions\relax

% ═══════════════════════════════════════════════════════════════════════════════
%  1.  REQUIRED PACKAGES
% ═══════════════════════════════════════════════════════════════════════════════
\RequirePackage[margin=1in,headheight=14pt]{geometry}
\RequirePackage{amsmath,amssymb,amsthm,mathrsfs}
\RequirePackage{enumitem}
\RequirePackage{titlesec}
\RequirePackage{fancyhdr}
\RequirePackage{xcolor}
\RequirePackage{hyperref}
\RequirePackage{tcolorbox}
\RequirePackage{etoolbox}            % for \ifdef, \patchcmd, etc.
\RequirePackage{graphicx}

% optional spacing
\if@manifoldspacing
  \RequirePackage{setspace}
  \setstretch{1.10}
\fi

% ═══════════════════════════════════════════════════════════════════════════════
%  2.  COLOUR PALETTE
% ═══════════════════════════════════════════════════════════════════════════════
%     Deep Indigo   #1B1464   —  titles, section rules, primary accent
%     Slate Grey    #4A5568   —  subtitles, secondary text
%     Teal          #0D9488   —  subsections, links, exam badges
%     Warm Gold     #D4A843   —  strategy boxes, decorative rules
%     Solution Green#2E7D32   —  solution labels
%     Light Cream   #FDF8F0   —  background tints (optional)
%     Soft Red      #C0392B   —  warnings, common-trap headers

\definecolor{deepindigo}{HTML}{1B1464}
\definecolor{slategrey}{HTML}{4A5568}
\definecolor{teal}{HTML}{0D9488}
\definecolor{warmgold}{HTML}{D4A843}
\definecolor{solngreen}{HTML}{2E7D32}
\definecolor{lightcream}{HTML}{FDF8F0}
\definecolor{softred}{HTML}{C0392B}

% ═══════════════════════════════════════════════════════════════════════════════
%  3.  HYPERREF CONFIGURATION
% ═══════════════════════════════════════════════════════════════════════════════
\hypersetup{
  colorlinks  = true,
  linkcolor   = deepindigo,
  urlcolor    = teal,
  citecolor   = deepindigo,
  pdfauthor   = {Manifold Mathematics},
  pdfcreator  = {Manifold Mathematics Monograph Series},
}

% ═══════════════════════════════════════════════════════════════════════════════
%  4.  SECTION / HEADING FORMATTING
% ═══════════════════════════════════════════════════════════════════════════════
\titleformat{\section}
  {\Large\bfseries\color{deepindigo}}{}{0em}{}[\color{deepindigo}\titlerule]
\titleformat{\subsection}
  {\large\bfseries\color{teal}}{}{0em}{}
\titleformat{\subsubsection}
  {\normalsize\bfseries\color{slategrey}}{}{0em}{}

% ═══════════════════════════════════════════════════════════════════════════════
%  5.  HEADER / FOOTER  (fancyhdr)
% ═══════════════════════════════════════════════════════════════════════════════
\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{\textit{\small Manifold Mathematics}}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}

% \manifoldheader{Topic} — sets the left running head
\newcommand{\manifoldheader}[1]{%
  \fancyhead[L]{\textit{#1 --- A Complete Problem Compendium}}%
}

% ═══════════════════════════════════════════════════════════════════════════════
%  6.  THEOREM-LIKE ENVIRONMENTS
% ═══════════════════════════════════════════════════════════════════════════════
\theoremstyle{definition}
\newtheorem{problem}{Problem}[section]
\newtheorem{definition}{Definition}[section]
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}{Proposition}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{corollary}{Corollary}[section]
\newtheorem{remark}{Remark}[section]
\newtheorem{example}{Example}[section]

% solution environment: green label + tombstone
\newenvironment{solution}{%
  \par\noindent\textcolor{solngreen}{\textbf{Solution.}}\quad
}{%
  \hfill$\blacksquare$\medskip
}

% ═══════════════════════════════════════════════════════════════════════════════
%  7.  STRATEGY / HIGHLIGHT BOXES  (tcolorbox)
% ═══════════════════════════════════════════════════════════════════════════════

% Generic strategy box  \begin{strategybox}{Title} ... \end{strategybox}
\newtcolorbox{strategybox}[1]{%
  colback   = warmgold!10,
  colframe  = deepindigo,
  title     = {\textbf{#1}},
  fonttitle = \bfseries,
}

% Exam-specific boxes
\newtcolorbox{gatebox}[1][GATE MA / IIT-JAM]{%
  colback=warmgold!10, colframe=deepindigo, title={\textbf{#1}}
}
\newtcolorbox{netbox}[1][CSIR-NET]{%
  colback=teal!10, colframe=teal, title={\textbf{#1}}
}
\newtcolorbox{phdbox}[1][TIFR / ISI / PhD Entrances]{%
  colback=deepindigo!10, colframe=deepindigo, title={\textbf{#1}}
}

% Warning / trap box
\newtcolorbox{trapbox}[1][Common Trap]{%
  colback=softred!8, colframe=softred, title={\textbf{#1}}
}

% Gold rule box (decorative)
\newtcolorbox{goldbox}[1]{%
  colback=warmgold!10, colframe=warmgold, title={\textbf{#1}}
}

% ═══════════════════════════════════════════════════════════════════════════════
%  8.  MATH SHORTCUTS
% ═══════════════════════════════════════════════════════════════════════════════

% ── Blackboard-bold ──
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\F}{\mathbb{F}}
\newcommand{\T}{\mathbb{T}}           % torus / unit circle

% ── Delimiters ──
\newcommand{\ip}[2]{\langle #1,\, #2 \rangle}       % inner product
\newcommand{\norm}[1]{\| #1 \|}                      % norm
\newcommand{\abs}[1]{| #1 |}                         % absolute value
\newcommand{\floor}[1]{\lfloor #1 \rfloor}
\newcommand{\ceil}[1]{\lceil #1 \rceil}

% ── Operators ──
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\nul}{null}
\DeclareMathOperator{\spn}{span}
\DeclareMathOperator{\range}{range}
\DeclareMathOperator{\im}{Im}
\DeclareMathOperator{\re}{Re}
\DeclareMathOperator{\Ker}{ker}
\DeclareMathOperator{\codim}{codim}
\DeclareMathOperator{\conv}{conv}
\DeclareMathOperator{\ext}{ext}
\DeclareMathOperator{\sgn}{sgn}
\DeclareMathOperator{\diam}{diam}
\DeclareMathOperator{\supp}{supp}
\DeclareMathOperator{\Id}{Id}
\DeclareMathOperator{\spec}{spec}      % spectrum
\DeclareMathOperator{\esssup}{ess\,sup}

% ── Arrows / convergence ──
\newcommand{\wto}{\xrightharpoonup{w}}               % weak convergence
\newcommand{\wstarto}{\xrightharpoonup{w^*}}          % weak-star convergence
\newcommand{\into}{\hookrightarrow}                   % embedding
\newcommand{\onto}{\twoheadrightarrow}                % surjection
\newcommand{\isom}{\cong}                             % isomorphism

% ── Spaces (calligraphic / script) ──
\newcommand{\calB}{\mathcal{B}}       % Borel σ-algebra, or bounded operators
\newcommand{\calL}{\mathcal{L}}       % space of operators
\newcommand{\calM}{\mathcal{M}}       % measures
\newcommand{\calH}{\mathcal{H}}       % Hilbert space
\newcommand{\calF}{\mathcal{F}}       % generic family / filter

% ── Dual space ──
\newcommand{\dual}[1]{#1^{*}}         % X^*
\newcommand{\ddual}[1]{#1^{**}}       % X^{**}
\newcommand{\ann}[1]{#1^{0}}          % annihilator

% ═══════════════════════════════════════════════════════════════════════════════
%  9.  TITLE PAGE COMMAND
% ═══════════════════════════════════════════════════════════════════════════════
%
%  \manifoldtitle{Main Title}{Exam Line}{Problem Count}{Detail Line 1}{Detail Line 2}
%
\newcommand{\manifoldtitle}[5]{%
  \begin{titlepage}
  \centering
  \vspace*{3cm}
  {\Huge\bfseries\color{deepindigo} #1}\\[1cm]
  {\Large\color{slategrey} A Complete Problem Compendium for}\\[6pt]
  {\Large\color{teal}\bfseries
     CSIR-NET $\cdot$ NBHM $\cdot$ GATE MA $\cdot$ IIT-JAM\\[4pt]
     TIFR $\cdot$ ISI $\cdot$ CMI $\cdot$ PhD Entrances}\\[1.5cm]
  \rule{0.6\textwidth}{0.4pt}\\[1cm]
  {\large #3}\\[0.5cm]
  {\large\color{slategrey} #4}\\[4pt]
  {\large\color{slategrey} #5}\\[2cm]
  {\color{warmgold}\rule{0.3\textwidth}{1pt}}\\[0.5cm]
  {\small\scshape Manifold Mathematics}\\[0.3cm]
  {\small\color{slategrey} Monograph Series}\\[1cm]
  {\small\the\year}
  \end{titlepage}
}

% ═══════════════════════════════════════════════════════════════════════════════
%  10.  COLOPHON / CLOSING FOOTER
% ═══════════════════════════════════════════════════════════════════════════════
\newcommand{\manifoldcolophon}{%
  \vfill
  \begin{center}
    \rule{0.3\textwidth}{0.4pt}\\[0.3cm]
    {\small\scshape Manifold Mathematics}\\[0.2cm]
    {\footnotesize\color{slategrey}
      \copyright\ \the\year.\ All rights reserved.}
  \end{center}
}

% ═══════════════════════════════════════════════════════════════════════════════
%  11.  EXAM-SOURCE BADGE
% ═══════════════════════════════════════════════════════════════════════════════
%  \examsource{CSIR-NET, GATE MA}  →  italic grey line under section title
\newcommand{\examsource}[1]{%
  \par\noindent{\itshape\color{slategrey}Source style: #1.}\medskip
}

% ═══════════════════════════════════════════════════════════════════════════════
%  12.  ANSWER KEY TABLE HELPER
% ═══════════════════════════════════════════════════════════════════════════════
%  Use inside a table environment:
%    \ansrow{1}{(A)}{6}{$\sqrt{3}$}
\newcommand{\ansrow}[4]{#1 & #2 & #3 & #4 \\}

% ═══════════════════════════════════════════════════════════════════════════════
%  13.  PROBLEM-COUNT TABLE
% ═══════════════════════════════════════════════════════════════════════════════
\newenvironment{problemcount}{%
  \begin{center}
  \renewcommand{\arraystretch}{1.3}
  \begin{tabular}{|l|c|}
  \hline
  \textbf{Category} & \textbf{Count} \\\hline
}{%
  \hline
  \end{tabular}
  \end{center}
}

% ═══════════════════════════════════════════════════════════════════════════════
%  14.  DUAL NORM TABLE (reusable)
% ═══════════════════════════════════════════════════════════════════════════════
\newcommand{\dualnormtable}{%
  \begin{center}
  \renewcommand{\arraystretch}{1.4}
  \begin{tabular}{|c|c|c|}
  \hline
  \textbf{Primal $\norm{\cdot}_p$}
    & \textbf{Dual $\norm{\cdot}_q$\;($\frac{1}{p}+\frac{1}{q}=1$)}
    & $\norm{f}$ \\\hline
  $\norm{\cdot}_1$       & $\norm{\cdot}_\infty$ & $\max_i|a_i|$ \\
  $\norm{\cdot}_2$       & $\norm{\cdot}_2$      & $\sqrt{\sum a_i^2}$ \\
  $\norm{\cdot}_\infty$  & $\norm{\cdot}_1$      & $\sum|a_i|$ \\
  $\norm{\cdot}_p$       & $\norm{\cdot}_q$      & $(\sum|a_i|^q)^{1/q}$ \\
  \hline
  \end{tabular}
  \end{center}
}

% ═══════════════════════════════════════════════════════════════════════════════
%  15.  DUAL IDENTIFICATION TABLE (reusable)
% ═══════════════════════════════════════════════════════════════════════════════
\newcommand{\dualidtable}{%
  \begin{center}
  \renewcommand{\arraystretch}{1.4}
  \begin{tabular}{|l|l|l|l|}
  \hline
  \textbf{Space $X$} & \textbf{$\dual{X}$} & \textbf{$\ddual{X}$}
    & \textbf{Reflexive?} \\\hline
  $\R^n$                        & $\R^n$            & $\R^n$            & Yes \\
  $\ell^p$ ($1<p<\infty$)       & $\ell^q$          & $\ell^p$          & Yes \\
  $\ell^1$                      & $\ell^\infty$     & $\mathrm{ba}(\N)$ & No \\
  $c_0$                         & $\ell^1$          & $\ell^\infty$     & No \\
  $\ell^\infty$                 & $\mathrm{ba}(\N)$ & ---               & No \\
  $L^p(\mu)$ ($1<p<\infty$)     & $L^q(\mu)$        & $L^p(\mu)$        & Yes \\
  $L^1(\mu)$                    & $L^\infty(\mu)$   & $\supsetneq L^1$  & No \\
  $C(K)$                        & $\calM(K)$        & $\supsetneq C(K)$ & No \\
  Hilbert $H$                   & $H$               & $H$               & Yes \\
  \hline
  \end{tabular}
  \end{center}
}

\endinput
