% preamble.tex — shared LaTeX setup for the HAHACS lab journal.
%
% Intent: a reader in 2030 picks up this journal and can rebuild the
% work from scratch.  This file defines the visual vocabulary — code
% listings, figures, callouts — that each dated entry uses.

\documentclass[11pt, letterpaper]{article}

% --- Page geometry ------------------------------------------------------------
\usepackage[margin=1in, headheight=15pt]{geometry}
\usepackage{parskip}           % blank line between paragraphs; no indent
\usepackage{microtype}

% --- Fonts --------------------------------------------------------------------
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{inconsolata}       % monospaced font for code

% --- Math ---------------------------------------------------------------------
\usepackage{amsmath, amssymb, amsthm, mathtools}
\usepackage{siunitx}
\sisetup{detect-all, per-mode=symbol}

% --- Graphics -----------------------------------------------------------------
\usepackage{graphicx}
\graphicspath{{./figures/}{../docs/figures/}}
\usepackage{caption}
\captionsetup{font=small, labelfont=bf}

% --- Code listings ------------------------------------------------------------
\usepackage{listings}
\usepackage{xcolor}

% Palette
\definecolor{code-bg}{HTML}{F7F7F2}
\definecolor{code-rule}{HTML}{D0D0C8}
\definecolor{code-comment}{HTML}{708070}
\definecolor{code-keyword}{HTML}{0050A0}
\definecolor{code-string}{HTML}{A04060}
\definecolor{code-number}{HTML}{806010}

\lstdefinelanguage{Julia}%
  {morekeywords={abstract,break,case,catch,const,continue,do,else,elseif,%
      end,export,false,for,function,immutable,import,importall,if,in,%
      macro,module,otherwise,quote,return,struct,switch,true,try,type,%
      typealias,using,while,mutable,global,local,let,primitive,where},%
   sensitive=true,%
   morecomment=[l]\#,%
   morecomment=[n]{\#=}{=\#},%
   morestring=[s]{"}{"},%
   morestring=[m]{'}{'},%
  }

\lstdefinestyle{labstyle}{
  backgroundcolor=\color{code-bg},
  basicstyle=\ttfamily\small,
  breaklines=true,
  breakatwhitespace=false,
  captionpos=b,
  commentstyle=\color{code-comment}\itshape,
  frame=single,
  framerule=0.5pt,
  rulecolor=\color{code-rule},
  keywordstyle=\color{code-keyword}\bfseries,
  numberstyle=\tiny\color{code-comment},
  showspaces=false,
  showstringspaces=false,
  showtabs=false,
  stringstyle=\color{code-string},
  tabsize=2,
  numbers=left,
  numbersep=6pt,
  xleftmargin=14pt
}
\lstset{style=labstyle}

\lstdefinestyle{terminal}{
  backgroundcolor=\color{black!90},
  basicstyle=\ttfamily\small\color{green!80!white},
  commentstyle=\color{white!60},
  frame=none,
  numbers=none,
  breaklines=true,
  xleftmargin=0pt
}

% --- Callout boxes ------------------------------------------------------------
\usepackage[most]{tcolorbox}

\newtcolorbox{limitation}[1][]{%
  colback=red!5!white,
  colframe=red!55!black,
  title=\textbf{Limitation},
  fonttitle=\bfseries,
  boxrule=0.6pt,
  arc=2pt,
  left=6pt, right=6pt, top=4pt, bottom=4pt,
  #1
}

\newtcolorbox{derivation}[1][]{%
  colback=blue!3!white,
  colframe=blue!40!black,
  title=\textbf{Derivation},
  fonttitle=\bfseries,
  boxrule=0.6pt,
  arc=2pt,
  left=6pt, right=6pt, top=4pt, bottom=4pt,
  #1
}

\newtcolorbox{deadend}[1][]{%
  colback=gray!8!white,
  colframe=gray!50!black,
  title=\textbf{Dead end},
  fonttitle=\bfseries,
  boxrule=0.5pt,
  arc=2pt,
  borderline west={2pt}{0pt}{gray!40},
  left=6pt, right=6pt, top=4pt, bottom=4pt,
  #1
}

\newtcolorbox{decision}[1][]{%
  colback=green!3!white,
  colframe=green!35!black,
  title=\textbf{Decision},
  fonttitle=\bfseries,
  boxrule=0.6pt,
  arc=2pt,
  left=6pt, right=6pt, top=4pt, bottom=4pt,
  #1
}

% TODO-for-A-pass marker: highlighted so we can find them for later deep-pass.
\newcommand{\apass}[1]{%
  {\fboxsep=2pt\colorbox{orange!20}{\textbf{[A-pass]}}\,\textit{#1}}
}

% --- Session header ----------------------------------------------------------
% Usage: \session{2026-04-17}{afternoon, ~5 hr}{summary line}
\newcommand{\session}[3]{%
  \noindent\rule{\linewidth}{0.8pt}
  \vspace{2pt}
  \noindent\textbf{\Large Session: #1} \hfill \textit{#2}\par
  \vspace{2pt}
  \noindent\emph{#3}\par
  \vspace{4pt}
  \noindent\rule{\linewidth}{0.4pt}
  \vspace{6pt}
}

% --- Code macros --------------------------------------------------------------
\newcommand{\juliafile}[2][]{\lstinputlisting[language=Julia,caption={#2},#1]{#2}}
\newcommand{\matlabfile}[2][]{\lstinputlisting[language=Matlab,caption={#2},#1]{#2}}
\newcommand{\pyfile}[2][]{\lstinputlisting[language=Python,caption={#2},#1]{#2}}

% --- Cross-reference helpers --------------------------------------------------
\usepackage[colorlinks=true, linkcolor=blue!50!black, citecolor=blue!40!black,
            urlcolor=teal!60!black]{hyperref}
\usepackage{bookmark}
\usepackage{cleveref}

% --- Headers & footers --------------------------------------------------------
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{HAHACS lab journal}
\fancyhead[R]{\leftmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.3pt}

% --- A small quiet easter egg for anyone who greps the preamble ---------------
% "Looks ordinary on the surface but is something else underneath."
% — the name behind Split. Keep the journal honest; under every summary
%   there's a derivation; under every derivation there's a doubt.
