Skip to content

Instantly share code, notes, and snippets.

@kristi
Created March 13, 2011 18:49
Show Gist options
  • Save kristi/868327 to your computer and use it in GitHub Desktop.
Save kristi/868327 to your computer and use it in GitHub Desktop.
latex math template
\documentclass{article}
\usepackage[margin=1.25in]{geometry}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{amsmath}
\usepackage{amsfonts} % math fonts
\usepackage{amssymb} % extra math symbols
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{verbatim} % \begin{comment} multi-line comments \end{comment}
\usepackage{color} % \textcolor{red}{colorful text}
% Mathtools package
% http://www.tex.ac.uk/ctan/macros/latex/contrib/mh/mathtools.pdf
\mathtoolsset{
showonlyrefs
}
\graphicspath{{./fig/}} % put figures in ./fig
\setlength{\parindent}{0pt} % don't indent paragraphs
\setlength{\parskip}{1ex} % extra space after paragraphs
% New definition of square root, closes over content
% Renames \sqrt as \oldsqrt
\let\oldsqrt\sqrt
% Defines the new \sqrt in terms of the old one
\def\sqrt{\mathpalette\DHLhksqrt}
\def\DHLhksqrt#1#2{%
\setbox0=\hbox{$#1\oldsqrt{#2\,}$}\dimen0=\ht0
\advance\dimen0-0.2\ht0
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%
{\box0\lower0.4pt\box2}}
\renewcommand{\thesubsection}{\thesection.\alph{subsection}}
% Define argmax
\DeclareMathOperator*{\argmax}{arg\,max\,}
\DeclareMathOperator*{\argmin}{arg\,min\,}
\DeclareMathOperator*{\maximize}{maximize\,}
\DeclareMathOperator*{\minimize}{minimize\,}
\DeclareMathOperator*{\subjectto}{subject\,to\,}
\DeclareMathOperator*{\dom}{dom\,}
\DeclareMathOperator*{\range}{range\,}
\newcommand{\vect}[1]{\mathbf{#1}}
\newcommand{\erf}[1]{\operatorname{erf}\left(#1\right)}
\newcommand{\erfc}[1]{\operatorname{erfc}\left(#1\right)}
\newcommand{\erfu}{\erf{\frac{u}{\sqrt{2}}}}
\newcommand{\erfcu}{\erfc{\frac{u}{\sqrt{2}}}}
\newcommand{\mx}[1]{\mathbf{#1}}
\newcommand{\x}{\vect{x}}
\newcommand{\y}{\vect{y}}
\renewcommand{\a}{\vect{a}} % overwrite \a, usually used for accents
\newcommand{\A}{\mx{A}} % matrix A
%\renewcommand{\L}{\mx{L}} % matrix L
\newcommand{\U}{\mx{U}} % matrix U
\newcommand{\real}{\mathbb{R}}
\newcommand{\integer}{\mathbb{Z}}
\renewcommand{\natural}{\mathbb{N}}
\newcommand{\gaussian}{\mathcal{N}}
\renewcommand{\L}{\mathcal{L}}
\renewcommand{\(}{\left(}
\renewcommand{\)}{\right)}
% optimize function
% args: #1 optimization operator
% #2 function to optimize
% #3 constraints (use \\ for a newline between constraints)
% example:
% \optimize{\argmax_{x}}{x^T A x}{x \ge 0 \\ 1^T x = 1}
%
\newcommand{\optimize}[3]{
\begin{alignedat}{2}
& #1
& & \begin{lgathered}[t]#2\end{lgathered} \\
& \subjectto
& & \begin{lgathered}[t]#3\end{lgathered} \\
\end{alignedat}
}
\[ \mu =
\begin{opt}
&\argmax && a\\
&\subjectto && bbb & bbb & d &
\end{opt}
\]
% sqcases
\makeatletter
\newenvironment{sqcases}{%
\matrix@check\sqcases\env@sqcases
}{%
\endarray\right.%
}
\def\env@sqcases{%
\let\@ifnextchar\new@ifnextchar
\left\lbrack
\def\arraystretch{1.2}%
\array{@{}l@{\quad}l@{}}%
}
\makeatother
\newtheorem*{theorem*}{Theorem}
\newtheorem*{lemma*}{Lemma}
\newtheorem*{corollary*}{Corollary}
\newtheorem*{definition*}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{corollary}{Corollary}
\newtheorem{definition}{Definition}
\title{Title}
\author{Name}
\date{March 13, 2011}
\begin{document}
% Start section numbering with 0
%\setcounter{section}{-1}
\maketitle
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment