Skip to content

Instantly share code, notes, and snippets.

@alexandrehuat
Last active January 23, 2019 18:33
Show Gist options
  • Save alexandrehuat/8e6f5d412de4859fbe04d896423e2822 to your computer and use it in GitHub Desktop.
Save alexandrehuat/8e6f5d412de4859fbe04d896423e2822 to your computer and use it in GitHub Desktop.
My LaTeX macros
\usepackage{todonotes}
%%% Maths commands
\usepackage{amsmath,amssymb,amsthm,mathtools,cool}
% Naturals, reals, etc.
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\I}{\mathbb{I}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\mvar}[1]{\mathit{#1}} % format for math variables
\newcommand{\pldr}{{\boldsymbol{\cdot}}} % place holder for indicating any mathematical symbol (e.g., function \f(\plder) will render f(.))
\DeclarePairedDelimiter{\abs}\lvert\rvert % absolute value
\DeclarePairedDelimiter{\card}\lvert\rvert % cardinal of a set
\DeclarePairedDelimiter{\ceil}\lceil\rceil % ceil function
\DeclarePairedDelimiter{\floor}\lfloor\rfloor % floor function
% Vectors, matrices, etc.
\newcommand{\mvec}[1]{\mathbf{#1}} % renders a vector
\newcommand{\mmat}[1]{\mathbf{#1}} % renders a matrix
\newcommand{\mtr}[1]{{#1}^{\operatorname{T}}} % transpose
\newcommand{\ones}{\mmat{1}} % matrix/vector full of ones, e.g., \ones_{n \times p}
\newcommand{\zeros}{\mmat{0}} % idem with zeros
\newcommand{\eye}{\mmat{I}} % identity matrix
\DeclarePairedDelimiter{\norm}\lVert\rVert % norm of a vector, etc.
% Symbols associated with probabilities
\newcommand{\given}{\nonscript\,\delimsize\vert\nonscript\,\mathopen{}} % use \given, not \mid, \vert, etc., to put a vertical bar '|' in a declared paired delimiter defined below (e.g., \Set{x_i \given i < 9} will render to {x_i | i < 9} with the good spacing and adaptative height)
% Declared PairedDelimiterX are special delimiters (parentheses, brackets, or anything actually) that have a shortcut for adaptative resizing.
% PairedDelimiterXPP are the same but with a symbol before the delimiter.
% Use the starred version to activate adaptative resizing.
% Example : Before, to write a scaled set you'd have done $\left\{ \frac{1}{n} \right\}$. Instead, now use $\Set*{\frac{1}{n}}$. If you don't want the delimiters of the set to be resized, just use $\Set{\frac{1}{n}}$.
\DeclarePairedDelimiterX{\parn}[1](){#1} % parenthesis usable with \given
\DeclarePairedDelimiterX{\Set}[1]\{\}{#1} % set of formula #1 --> {#1}
\DeclarePairedDelimiterXPP{\Proba}[1]{\operatorname{Pr}}(){}{#1} % probability of formula #1 --> Pr(#1)
\DeclarePairedDelimiterXPP{\Ev}[2]{\operatorname{E}_{#2}}[]{}{#1} % expected value of formula #1 according to variable #2 --> E_{#2}(#1)
\DeclarePairedDelimiterXPP{\Var}[2]{\operatorname{Var}_{#2}}[]{}{#1} % variance of formula #1 according to variable #2 --> Var_{#2}(#1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment