Skip to content

Instantly share code, notes, and snippets.

@markvdw
Last active August 31, 2018 18:17
Show Gist options
  • Save markvdw/3af518bc3fca9f85315b072cdcd91577 to your computer and use it in GitHub Desktop.
Save markvdw/3af518bc3fca9f85315b072cdcd91577 to your computer and use it in GitHub Desktop.
Some mathematical commands for latex.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{MarkMathCmds}
[2013/07/26 v1.00 MarkMathCms]
\usepackage{xspace}
\usepackage{amssymb}
\usepackage{cancel}
\newcommand\ccancel[2][red]{\renewcommand\CancelColor{\color{#1}}\cancel{#2}}
\newcommand\ccancelto[2][red]{\renewcommand\CancelColor{\color{#1}}\cancelto{#2}}
% Linear algebra
\newcommand{\transpose}{^\mathrm{\textsf{\tiny T}}}
\newcommand{\norm}[1]{\lvert #1\rvert}
\DeclareMathOperator{\Tr}{Tr}
\newcount\colveccount
\newcommand*\colvec[1]{
\global\colveccount#1
\begin{bmatrix}
\colvecnext
}
\def\colvecnext#1{
#1
\global\advance\colveccount-1
\ifnum\colveccount>0
\\
\expandafter\colvecnext
\else
\end{bmatrix}
\fi
}
\newcommand{\diag}{\mathrm{diag}}
\newcommand{\quadform}[2][]{{#2}\transpose{#1}{#2}}
% \DeclareMathOperator{\Tr}{Tr}
% \newcommand{\Tr}[1]{\mathrm{Tr}\left[#1\right]}
\newcommand{\kron}{\otimes}
\newcommand{\hadamard}{\circ}
\DeclareMathOperator{\mkvec}{vec}
\newcommand{\detbar}[1]{\left\vert#1\right\vert}
\newcommand{\inv}{^{-1}}
% Sets
\newcommand{\Reals}{\mathbb{R}}
\newcommand{\SetSize}[1]{\lvert #1\rvert}
% Calculus
\newcommand{\calcd}[1][]{\mathrm{d}#1\xspace}
\newcommand{\deriv}[2][]{\frac{\mathrm{d}#1}{\mathrm{d}#2}}
\newcommand{\pderiv}[2][]{\frac{\partial#1}{\partial#2}}
\newcommand{\pderivtwo}[2][]{\frac{\partial^2#1}{\partial{#2}^2}}
\newcommand{\LapTrans}{\mathcal{L}}
% Functions
\DeclareMathOperator*{\argmin}{\arg\!\min}
\DeclareMathOperator*{\argmax}{\arg\!\max}
% Probability operators
\newcommand{\ExpSymb}{\mathbb{E}}
\newcommand{\Exp}[2]{\ExpSymb_{#1}\left[#2\right]}
\newcommand{\Expint}[3][]{\int {#2} \left[ {#3} \right] \calcd{#1}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\GP}{\mathcal{GP}}
\newcommand{\FromDist}{\sim}
\newcommand{\KL}[2]{\mathrm{KL}\left[ {#1} || {#2} \right]}
\newcommand{\KLint}[3]{\int #1 \log \left( \frac{#1}{#2} \right) \calcd{#3}}
\newcommand{\entropy}[1]{\mathcal{H}\left( #1 \right)}
\newcommand{\given}{\,|\,}
% Probability distributions
\newcommand{\NormDist}[1]{\mathcal{N}\left({#1}\right)}
\newcommand{\WishDist}[1]{\mathcal{W}\left({#1}\right)}
\newcommand{\UnifDist}{\mathcal{U}}
% Probability distribution functions
\newcommand{\NormPdf}[3]{(2\pi)^{-\frac{D}{2}}\detbar{#3}^{-1}
\exp\left(-\frac{1}{2} \quadform[#3^{-1}]{(#1-#2)} \right)}
% Vectors
\newcommand{\va}{\mathbf{a}}
\newcommand{\vb}{\mathbf{b}}
\newcommand{\vd}{\mathbf{d}}
\newcommand{\vf}{\mathbf{f}}
\newcommand{\vt}{\mathbf{t}}
\newcommand{\vg}{\mathbf{g}}
\newcommand{\vk}{\mathbf{k}}
\newcommand{\vm}{\mathbf{m}}
\newcommand{\vp}{\mathbf{p}}
\newcommand{\vs}{\mathbf{s}}
\newcommand{\vect}{\mathbf{t}}
\newcommand{\vu}{\mathbf{u}}
\newcommand{\vv}{\mathbf{v}}
\newcommand{\vw}{\mathbf{w}}
\newcommand{\vx}{\mathbf{x}}
\newcommand{\vy}{\mathbf{y}}
\newcommand{\vz}{\mathbf{z}}
\newcommand{\vzeta}{\boldsymbol{\zeta}}
\newcommand{\vtheta}{\boldsymbol{\theta}}
\newcommand{\vepsilon}{\boldsymbol{\epsilon}}
\newcommand{\vmu}{\boldsymbol{\mu}}
\newcommand{\vphi}{\boldsymbol{\phi}}
% Symbols referring to stuff
\newcommand{\data}{\mathcal{D}}
% Computer science
\newcommand{\BigO}{\mathcal{O}}
% General typesetting
\let\originalleft\left
\let\originalright\right
\renewcommand{\left}{\mathopen{}\mathclose\bgroup\originalleft}
\renewcommand{\right}{\aftergroup\egroup\originalright}
\endinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment