Skip to content

Instantly share code, notes, and snippets.

@cstrachan88
Forked from jhwilson/jhwhw.cls
Last active April 9, 2017 04:12
Show Gist options
  • Save cstrachan88/a6d00217d112f1ce5b6a63c932f4223e to your computer and use it in GitHub Desktop.
Save cstrachan88/a6d00217d112f1ce5b6a63c932f4223e to your computer and use it in GitHub Desktop.
LaTeX class file for math homework
%=====================================================================
% File: mathhw.cls
% Author: Courtney Strachan
% Forked from Justin Wilson's Homework Class (https://gist.github.com/jhwilson/1278588)
%=====================================================================
%=====================================================================
% Packaging
%=====================================================================
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mathhw}[2017/04/08 Math Homework Class]
\LoadClass[letterpaper, 12pt]{article}
\RequirePackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}
\RequirePackage{fancyhdr} % Extensive control of page headers and footers in LaTeX2e
\RequirePackage{ifthen} % Conditional commands in LaTeX documents
%\RequirePackage{empheq} % ...
\RequirePackage{amsmath,amsthm,amssymb} % Math packages (theorem for qed, and symbols for ..)
\RequirePackage{environ} % For Linear systems array
\RequirePackage{array} % For custom matrix type that factors in negative number spacing
%=====================================================================
% Commands
%=====================================================================
% Document Initialization
\setlength{\headheight}{15pt}
\lhead{\@author}\chead{\@title}\rhead{\@date}
\lfoot{}\cfoot{Page \thepage}\rfoot{}
\pagestyle{fancy}
\fancypagestyle{firstpagestyle}
{
\fancyhf{} % clear all header and footer fields
\lhead{\@author \vspace*{2px}}\chead{\textbf{\Large \@title} \vspace*{1px}}\rhead{\@date \vspace*{2px}}
\lfoot{}\cfoot{Page \thepage}\rfoot{}
}
\thispagestyle{firstpagestyle}
% PDF Setup
\ifx\pdfoutput\undefined % LaTeX
\RequirePackage[ps2pdf,bookmarks=true]{hyperref}
\hypersetup{
pdfauthor = {\@author},
pdftitle = {\@title},
pdfcreator = {LaTeX with hyperref package},
pdfproducer = {dvips + ps2pdf}
}
\else % PDFLaTeX
\RequirePackage[pdftex,bookmarks=true]{hyperref}
\hypersetup{
pdfauthor = {\@author},
pdftitle = {\@title},
pdfcreator = {LaTeX with hyperref package},
pdfproducer = {dvips + ps2pdf}
}
\pdfadjustspacing=1
\fi
% Set up counters for problems and subsections
\newcounter{ProblemNum}
\newcounter{SubProblemNum}[ProblemNum]
\newcounter{SubSubProblemNum}[SubProblemNum]
\renewcommand{\theProblemNum}{\arabic{ProblemNum}}
\renewcommand{\theSubProblemNum}{\alph{SubProblemNum}}
\renewcommand{\theSubSubProblemNum}{\roman{SubSubProblemNum}}
\newcommand*{\anyproblem}[1]{\newpage\subsection*{#1}}
\newcommand*{\problem}[1]{\stepcounter{ProblemNum}
\anyproblem{Problem \theProblemNum. \; #1}}
\newcommand*{\anyproblemnb}[1]{\subsection*{#1}}
\newcommand*{\problemnb}[1]{\stepcounter{ProblemNum}
\anyproblemnb{Problem \theProblemNum. \; #1}}
\newcommand*{\soln}[1]{\subsubsection*{#1}}
\newcommand*{\solution}{\soln{Solution}}
\renewcommand*{\part}{\stepcounter{SubProblemNum}
\soln{Part (\theSubProblemNum)}}
\newcommand*{\subpart}{\stepcounter{SubSubProblemNum}
\soln{Subpart \theSubSubProblemNum. }}
\renewcommand{\theenumi}{(\alph{enumi})}
\renewcommand{\labelenumi}{\theenumi}
\renewcommand{\theenumii}{\roman{enumii}}
% Change qed symbol
\renewcommand{\qedsymbol}{\rule{0.7em}{0.7em}}
% Column 'C': Negative number spacing fix in matrices
% i.e., aligns numbers, and adds padding for negative
% http://tex.stackexchange.com/a/178743/106637
\makeatletter
\def\zz\ignorespaces{\@ifnextchar-{}{\phantom{-}}}
\newcolumntype{C}{>{\zz}{c}}
\makeatother
% Allow for \begin{bmatrix}[rrrr]
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother
% Linear systems array
\makeatletter
\newcommand{\LinearSystems@SetupLets}{
\let\col=&
\let\+=+
\let\-=-
\let\===
}
\newcommand{\LinearSystems@SetupCatcodes}{
\catcode`\&=\active
\catcode`\+=\active
\catcode`\-=\active
\catcode`\==\active
\catcode`\/=\active
}
\newcommand{\LinearSystems@Setup}{}
\begingroup
\LinearSystems@SetupCatcodes
\gdef\LinearSystems@Setup{
\LinearSystems@SetupLets
\LinearSystems@SetupCatcodes
\newcommand&[1][0pt]{\col\hspace{##1}\col}
\def+{\col\+{}{}\col}
\def-{\col\-{}{}\col}
\def={\col\={}{}\col}
\def/{\col\/{}{}\col}
}
\endgroup
\NewEnviron{LinearSystems}[1]{\left\{\begin{alignedat}{#1}\BODY\end{alignedat}\right.}
\let\LinearSystems@OriginalBegin\LinearSystems
\def\LinearSystems{\LinearSystems@Setup\LinearSystems@OriginalBegin}
\makeatother
\newcommand{\Span}{\mathrm{Span}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment