Hw

LaTeX template for math/cs homework

Category

Math

License

Free to use (MIT)

File

hw_template.tex

hw_template.texRead-only preview
% hw-latex-template is a simple template for writing up your math or CS homework in LaTeX.
% Copyright (C) 2020  Rishi Advani

% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.

% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.

% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <https://www.gnu.org/licenses/>.




\documentclass[letterpaper, 11pt, fleqn]{article}



\newif\ifLM
%\LMtrue  % use `lmodern` fonts instead of `newpx` fonts



%%% Layout and typography %%%

\usepackage{mathtools}  % also loads `amsmath` package
\usepackage{amssymb}
\usepackage{amsthm}  % load before `newpxmath` package

\ifLM
\usepackage{lmodern}
\else
\usepackage[theoremfont, trueslanted, largesc]{newpxtext}  % package author wants this loaded after `babel`, but this doesn't seem necessary
\usepackage[vvarbb, noamssymbols]{newpxmath}  % package author has `fontenc` loaded before this, but it's unclear if this is necessary
\fi

\usepackage[T1]{fontenc}  % allows LaTeX to output non-ASCII characters better; load after fonts if possible
\usepackage[english]{babel}  % sets language to American English
\AddBabelHook{frspacing}{afterextras}{\frenchspacing}  % enables single sentence spacing
%\usepackage{csquotes}  % for formal quotations

\usepackage[hmargin=1.2in, marginparwidth=1in, marginparsep=0.1in, vmargin=1in, headheight=0.6in, headsep=0.3in, footskip=0.5in, heightrounded]{geometry}  % useful for setting page dimensions and layout
%\usepackage{parskip}  % enables alternate paragraph layout
\usepackage{ragged2e}  % adds improved flush/ragged alignment commands
\newcommand{\sidenote}[1]{\marginpar[\RaggedLeft\footnotesize #1]{\RaggedRight\footnotesize #1}}  % use for sidenotes

\usepackage{ftcap}  % fixes table–caption spacing in `article` class
\usepackage[tracking]{microtype}  % improves typographic details (e.g., kerning)
\usepackage{fnpct}  % adjusts kerning of footnote marks (superscripts) before commas or periods



%%% Images %%%

\usepackage{graphicx}  % allows inclusion of images in document
\graphicspath{{./images/}}  % location of images in file system

% Example:
%\begin{figure}[bhpt]
%\centering
%\includegraphics[width=0.8\linewidth]{p1_1}
%\caption{[insert caption]}
%\label{p1_relevantname}
%\end{figure}



%%% Tables %%%

\usepackage{booktabs}
%\usepackage{tabularx}



%%% Math %%%

\allowdisplaybreaks[1]  % allows page breaks within `amsmath` environments; optional value sets permissibility (min=1, max=4)

%\mathchardef\mhyphen="2D  % hyphen for math mode (credit to Gernot Salzer)
\renewcommand*{\emptyset}{\varnothing}  % prettier empty set symbol
\ifLM\newcommand*{\transp}{\mathsf{T}}\fi  % use for matrix transpose

%\usepackage{bm}  % use `\bm` for bold math symbols

% Use `\phanrel` to insert an invisible relation operator to align an equation split across two lines.
\newcommand*{\phanrel}{\mathrel{\phantom{=}}}
% Example:
%\begin{align*}
%	&\phanrel \text{a very long expression} \\
%	&= \text{another long expression}
%\end{align*}

\newcommand*{\Complex}{\mathbb{C}}
\newcommand*{\Reals}{\mathbb{R}}
\newcommand*{\Rationals}{\mathbb{Q}}
\newcommand*{\Integers}{\mathbb{Z}}
\newcommand*{\Naturals}{\mathbb{N}}

\DeclareMathOperator{\E}{\mathbb{E}}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}

% Use `\set` for set notation. Optional size argument accepted.
\DeclarePairedDelimiterX\set[1]\lbrace\rbrace{\mkern1.5mu\def\suchthat{\;\delimsize|\;}#1\mkern1.5mu}
% Example:
%\[\set[\bigg]{\frac{x^2}{2} \suchthat x > 0}\]



%%% Graphs %%%

\usepackage{xcolor}  % enables teal color for `listings` package; load before `tikz` package
%\usepackage{tikz}
%\usetikzlibrary{babel, positioning}



%%% Algorithms %%%

\usepackage{algorithm}  % enables floating of algorithms
\usepackage{algpseudocode}  % also loads `algorithmicx` package; use `noend` option to supress block ending lines
\newcommand*{\algorithmautorefname}{Algorithm}  % for `hyperref` package's autoref macro

% Use `\LongState` to replace `\State` when the contents of the line overflow. This preserves the indentation level of the first line. Inspired by a macro designed by TeX.SX user Werner.
\newcommand*{\LongState}[2]{\State\parbox[t]{\dimexpr\linewidth-\dimexpr\algorithmicindent*#1}{#2\strut}}
% Example:
%\LongState{2}{very long line that needs to be indented 2 levels}

%\usepackage{fancyvrb}
\usepackage{listings}
\renewcommand*{\lstlistingname}{Algorithm}
\lstset{
	tabsize=4,
	language=Python,
	frame=single,
	morekeywords={True,False},
	commentstyle=\color{gray},
	keywordstyle=\color{blue},
	stringstyle=\color{teal},
	basicstyle=\small\ttfamily,
	showstringspaces=false,
	rulecolor=\color{black}
}

% Example:
%\begin{lstlisting}[title=My Title, label=my_label, float=bhpt]
%	print("Hello World!")
%\end{lstlisting}



%%% Fancy header %%%

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{Rishi Advani}  % TODO update
\fancyhead[C]{MATH 101 --- Homework 1}  % TODO update
\fancyhead[R]{January 10, 1938}  % TODO update
\fancyfoot{}
%\fancyfoot[L]{Collaborators: N/A}
%\renewcommand*{\footrulewidth}{0.5pt}  % uncomment if you have collaborators



%%% Miscellaneous %%%

% Use `\isitdefined` to check if a command is defined.
\newcommand*{\isitdefined}[1]{\%\% command `#1' does \ifcsname#1\endcsname\else NOT \fi exist \%\%}
% Example:
%\isitdefined{potato}



%%% Load last %%%

\usepackage[colorlinks, allcolors=blue]{hyperref}  % enables hyperlinks; load before `ellipsis` package
\usepackage{ellipsis}  % adjusts spacing of ellipses before punctuation



\begin{document}

% TODO remove  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{sample_input}  % only needed for this template
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}
Preview
Hw preview
Hw LaTeX Template | Bibby | Bibby AI