\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{zine}[2024/04/02 A class for Anarchist Zines!]

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions\relax

% SETUP ---------------------------------------------

\LoadClass[12pt]{book}
\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage{graphicx, parskip, fancyhdr, titlesec, listings, color, hyperref}
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}

\lstset{
  backgroundcolor=\color{white},   % choose the background color
  basicstyle=\ttfamily\footnotesize,
  commentstyle=\itshape,
  numberstyle=\tiny,
  identifierstyle=\ttfamily,
  columns=fullflexible,
  keepspaces=true,
  breaklines=true,                 % automatic line breaking only at whitespace
  showtabs=false,
  showspaces=false,
  showstringspaces=false,
  captionpos=b,                    % sets the caption-position to bottom
  commentstyle=\color{mygreen},    % comment style
  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
  keywordstyle=\color{blue},       % keyword style
  stringstyle=\color{mymauve},     % string literal style
}

% FONT ---------------------------------------------
\RequirePackage{ebgaramond}
\RequirePackage{lmodern}

% SIZE, MARGINS: -----------------------------------
\RequirePackage[paperheight=8.5in,
            paperwidth=5.5in,
            left=0.75in,
            right=0.75in,
            top=0.9in,
            bottom=1in]{geometry}

% SPACING -------------------------------------------
\setlength\parindent{0pt} %remove paragraph indentations

% remove spacing for lists
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{-2pt}}

% MISC STYLING: -----------------------------------------
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering

\hypersetup{hidelinks} % Remove box around links.

% HEADERS -----------------------------------------------
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[RE]{\thepage}
\fancyfoot[LO]{\thepage}
\renewcommand{\headrule}


% MAKE FRONT COVER --------------------------------------
\newcommand{\frontcover}{%
 \begin{titlepage}
    \begin{center}
      \includegraphics[width=3.5in]{\thecoverimage}
      \lineskip 1em%
      {\Huge\@title} \\
      \vfill
    \end{center}
 \end{titlepage}
\addtocounter{page}{-1}%
}

% MAKE MAIN CONTENT  ------------------------------------
%\input{markdown}
\titlespacing\numberless{0pt}{14pt}{4pt}
\titlespacing\section{0pt}{14pt}{4pt}
\titlespacing\subsection{0pt}{14pt}{4pt}
\titlespacing\subsubsection{0pt}{14pt}{4pt}


% MAKE BACK COVER ---------------------------------------

\newcommand{\backcover}{
\newpage
% null is needed for vfill to work
\null
% remove page numbering from back cover
\pagestyle{empty}
\centering
\vfill
\includegraphics[width=0.5in]{chaos.png}
{\par\skip Printed on \today{} by \@author}
}


% HELPER FUNCTIONS ---------------------------------

% note: perhaps these should be a package.

\NewDocumentCommand\coverimage{m}{
  \newcommand{\thecoverimage}{#1}
}

\NewDocumentCommand\logo{m}{
  \newcommand{\thelogo}{#1}
}
