Skip to content

Instantly share code, notes, and snippets.

@darioseidl
Created March 26, 2016 17:09
Show Gist options
  • Save darioseidl/f692fa69fc77ebf54abc to your computer and use it in GitHub Desktop.
Save darioseidl/f692fa69fc77ebf54abc to your computer and use it in GitHub Desktop.
LaTeX macros
%== setup ======================================================================
% be strict
\RequirePackage[l2tabu, orthodox]{nag}
% document class
\documentclass[a4paper,10pt,titlepage,final]{article}
% bug fixes
\usepackage{fixltx2e}
% font and encoding
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
% language
\usepackage{csquotes}
\usepackage[ngerman,english]{babel}
% microtypography
\usepackage[babel]{microtype}
% math
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
% macro space
\usepackage{xspace}
%== math environments ==========================================================
\newtheorem{claim}{Claim}
\newtheorem*{claim*}{Claim}
\newtheorem{lemma}{Lemma}
\newtheorem*{lemma*}{Lemma}
\newtheorem{corollary}{Corollary}
\newtheorem*{corollary*}{Corollary}
\newtheorem{theorem}{Theorem}
\newtheorem*{theorem*}{Theorem}
%== macros =====================================================================
\newcommand{\var}[1]{\mathit{#1}} % multi-letter variables
\newcommand{\V}[1]{\mathbf{#1}} % vector
\newcommand{\M}[1]{\mathbf{#1}} % matrix
\newcommand{\T}{^\top} % transpose
\newcommand{\C}{\mathbb{C}} % complex numbers
\newcommand{\R}{\mathbb{R}} % real numbers
\newcommand{\Q}{\mathbb{Q}} % rational numbers
\newcommand{\Z}{\mathbb{Z}} % integers
\renewcommand\Re{\operatorname{Re}} % real part
\renewcommand\Im{\operatorname{Im}} % imaginary part
\newcommand{\eps}{\varepsilon} % prefered epsilon symbol
\newcommand{\Iff}{if\textcompwordmark f\xspace} % if and only iff
\newcommand{\Cpp}{C\nolinebreak[4]\raisebox{0.5ex}{\tiny\textbf{++}}} % C++
\DeclareMathOperator{\sgn}{sgn} % sign
\DeclareMathOperator*{\argmin}{arg\,min} % argmax
\DeclareMathOperator*{\argmax}{arg\,max} % argmin
\DeclareMathOperator{\E}{E} % expectation
\DeclareMathOperator{\rank}{rank} % rank
\DeclareMathOperator{\bigO}{\mathcal{O}} % big O(micron)
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert} % abs
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert} % norm
\DeclarePairedDelimiter{\ceil}{\lceil}{\rceil} % ceil
\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor} % floor
% \renewcommand{\d}{\mathrm{d}}
% \newcommand{\dv}[2]{\frac{\d#1}{\d#2}} % derivative
% \newcommand{\pd}[2]{\frac{\partial#1}{\partial#2}} % partial derivative
\useshorthands*{"}
\defineshorthand{"-}{\babelhyphen*{nobreak}} % non-breaking hyphen
%== document ===================================================================
\begin{document}
\begin{tabular}{ll}
\verb|\(name \gets 0\)| & \(name \gets 0\) \\
\verb|\(\var{name} \gets 0\)| & \(\var{name} \gets 0\) \\
\\
\verb|\(\abs{a}\)| & \(\abs{a}\) \\
\verb|\(\norm{a}, \norm{a}_\infty\)| & \(\norm{a}, \norm{a}_\infty\) \\
\verb|\(\ceil{a}, \floor{a}\)| & \(\ceil{a}, \floor{a}\) \\
\\
\verb|\(\Z \subset \Q \subset \R \subset \C\)| & \(\Z \subset \Q \subset \R
\subset \C\)
\\
\verb|\(\Re z, \Im z\)| & \(\Re z, \Im z\) \\
\verb|\(\sgn(x)\)| & \(\sgn(x)\) \\
\verb|\(\argmin(x), \argmax(x)\)| & \(\argmin(x), \argmax(x)\) \\
\verb|\(\Pr[X], \E[X]\)| & \(\Pr[X], \E[X]\) \\
\verb|\(\eps, \epsilon\)| & \(\eps, \epsilon\) \\
\verb|\(\V{x}\T, \rank{\M{A}}\)| & \(\V{x}\T, \rank{\M{A}}\) \\
\verb|\(\bigO(n)\)| & \(\bigO(n), \Omega(n), \Theta(n)\) \\
\\
% \verb|\(\dv{f}{x}, \pd{f}{x}\)| & \(\d{x}, \dv{f}{x}, \pd{f}{x}\) \\
% \\
\verb|A \Iff B| & A \Iff B \\
\verb|C, \Cpp, C++| & C, \Cpp, C++ \\
\end{tabular}
\begin{theorem}A\end{theorem}
\begin{theorem*}A\end{theorem*}
\begin{proof}B\end{proof}
\end{document}
% field
\newcommand{\field}[1]{\mathbb{#1}}
% set of real numbers
\newcommand{\reals}{\field{R}}
% set of integer numbers
\newcommand{\integers}{\field{Z}}
% set of rational numbers
\newcommand{\rationals}{\field{Q}}
% set of positive real numbers
\newcommand{\posreals}{\reals_{>0}}
% set of nonnegative real numbers
\newcommand{\nonnegreals}{\reals_{\ge 0}}
% set of positive integers
\newcommand{\posintegers}{\integers_{>0}}
% set of nonnegative integers
\newcommand{\nonnegintegers}{\integers_{\ge 0}}
% set of positive rationals
\newcommand{\posrationals}{\rationals_{>0}}
% set of nonnegative rationals
\newcommand{\nonnegrationals}{\rationals_{\ge 0}}
% set
\newcommand{\set}[1]{\left\{ #1 \right\}}
% integers from zero to input
\newcommand{\zeroto}[1]{\set{0,\dots,#1}}
% integers from one to input
\newcommand{\oneto}[1]{\left[ #1 \right]}
% the power set of the input set
\newcommand{\powerset}[1]{2^{#1}}
% probability
\renewcommand{\Pr}{\mathbf{P}}
\newcommand{\prob}[1]{\Pr\left[ #1 \right]}
% absolute value; set size; (Euclidean) metric
\newcommand{\abs}[1]{\lvert #1 \rvert}
% (Euclidean) norm
\newcommand{\norm}[1]{\lVert #1 \rVert}
% "given" such as used in conditional probabilities and expectations
\newcommand{\given}{\nonscript\;\middle|\nonscript\;}
% "such that" such as used in the definition of a set
\newcommand{\suchthat}{\mid}
% indicator function (1 if true; 0 if false)
\newcommand{\indicator}[1]{\mathbf{1}\left[ #1\right]}
% vector
\newcommand{\vect}[1]{\boldsymbol{\mathbf{#1}}}
% definition of variable
\newcommand{\defas}{:=}
% space between equation and text
\newcommand{\speqtxt}{\quad}
% space between equation and single period, comma, ...
\newcommand{\speqcom}{\,}
% optimal (expected) revenue
\newcommand{\optr}{\widehat{R}}
%%%%%%%%%%%%%%%%%%%%%%%%%%
% commands for text mode %
%%%%%%%%%%%%%%%%%%%%%%%%%%
% complexity class
\newcommand{\complexity}[1]{\ensuremath{\mathcal{#1}}}
% problem such as Max-Cut
\newcommand{\problem}[1]{\textsc{#1}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment