Skip to content

Instantly share code, notes, and snippets.

@stevenbell
Created September 4, 2019 16:39
Show Gist options
  • Save stevenbell/7b5271e6d0dc0c2373a9183dd8acdbaa to your computer and use it in GitHub Desktop.
Save stevenbell/7b5271e6d0dc0c2373a9183dd8acdbaa to your computer and use it in GitHub Desktop.
LaTeX class for homework
% Class for homework which allows answers to be embedded and removed
\ProvidesClass{homework}
\LoadClass{article}
% Used for creating environment which can show/hide content
\usepackage{environ}
% Margin setup
\usepackage{geometry}
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\usepackage{xcolor}
\definecolor{answercolor}{RGB}{10, 50, 80}
\definecolor{tacolor}{RGB}{10, 80, 20}
\newcommand{\points}[1]{[#1\,pt\ifnum1=#1\relax\else{s}\fi]}
% If the 'answer' argument is specified, set the 'answer' flag true
\newif\ifanswer
\answerfalse
\DeclareOption{answer}{
\answertrue
}
% Build the answer environment. If the 'answer' flag is true, then include
% the content in the environment. If not, then just include a vertical space.
\NewEnviron{answer}[1][1in]{
\ifanswer
\vspace{1ex}
\color{answercolor} % Automatically closes
\BODY
\vspace{1ex}
\else
\vspace{#1}
\fi
}
% Page breaks which only apply for answerspace
\newcommand{\qnewpage}{\ifanswer\else\newpage\fi}
% tainfo environment which encapsulates information for TAs that's
% not an answer. Rubrics, common gotchas, etc.
\NewEnviron{tainfo}{
\ifanswer
\color{tacolor} % Automatically closes
\parindent=3em
\BODY
\fi
}
\ProcessOptions\relax
% Setup for problem headings
\newcounter{ProblemCounter}
\newcommand{\problem}[1][]{
\refstepcounter{ProblemCounter}
\vspace{2ex}
\textbf{\large{Problem \theProblemCounter: #1}}
\nopagebreak
}
% Title setup
\newcommand\duedate[1]{\newcommand\@duedate{#1}}
\renewcommand{\maketitle}{%
\thispagestyle{empty}%
\ifanswer
% Not sure why we don't get a proper space here
\begin{center}\LARGE{\@title \, solutions}\end{center}%
\else
Name: \rule{2in}{0.5pt}
%\hfill
%Lab section/TA: \rule{2in}{0.5pt}
\vspace{1ex}
\ifdefined\@duedate
\begin{center}\LARGE{\@title} \\ \large{Due \@duedate}\end{center}%
\else
\begin{center}\LARGE{\@title}\end{center}%
\fi
\fi
}
\newcommand{\hint}[1]{\textit{Hint: #1}}
\endinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment