Skip to main content

Math macro command for latex support in markdown

Number and Arrays

command visualization comment
a a A scalar
\va a A vector, additionally 0,1,μ,ν,θ for \vzero, \vone, \vmu, \vnu, \vtheta
\mA A A matrix
\tA A A tensor
\mI_n In Identity matrix with n rows and n columns
\mI I Identity matrix with dimensionality implied by context
\ve^{(i)} e(i) Standard basis vector [0,,0,1,0,,0] with a 1 at position i
\text{diag}(\va) diag(a) A square, diagonal matrix with diagonal entries given by a
\ra a A scalar-valued random variable
\rva a A vector-valued random variables
\rmA A A matrix-valued random varialbes

Sets and Graphs

Command Visualization Comment
\sA A A set
Note: the command covers sA to sZ but don't no sE since it's expectation
\R R The set of real numbers
{0, 1} 0,1 The set containing 0 and 1
{0, 1, \dots, n} 0,1,,n The set of all integers between 0 and n
[a, b] [a,b] The real interval including a and b
(a, b] (a,b] The real interval excluding a but including b
\sA \backslash \sB AB Set subtraction, i.e., the set containing the elements of A not in B
\gG G A graph

Indexing

Command Visualization Comment
\eva_i ai Element i of vector a, with indexing starting at 1
\eva_{-i} ai All elements of vector a except for element i
\emA_{i,j} Ai,j Element i,j of matrix A
\mA_{i, :} Ai,: Row i of matrix A
\mA_{:, i} A:,i Column i of matrix A
\etA_{i, j, k} Ai,j,k Element (i,j,k) of a 3-D tensor A
\tA_{:, :, i} A:,:,i 2-D slice of a 3-D tensor
\erva_i ai Element i of the random vector a

Linear Algebra Operators

Command Visualization Comment
\mA^\top A Transpose of matrix A
\mA^+ A+ Moore-Penrose pseudoinverse of A
\mA \odot \mB AB Element-wise (Hadamard) product of A and B
\mathrm{det}(\mA) det(A) Determinant of A
\sign(x) sign(x) Sign of a variable x
\Tr \mA Tr(A) Trace of a matrix A

Calculus

Command Visualization Comment
\diff y / \diff x dy/dx Derivative of y with respect to x
\frac{\partial y}{\partial x} yx Partial derivative of y with respect to x
\nabla_\vx y xy Gradient of y with respect to x
\nabla_\mX y Xy Matrix derivatives of y with respect to X
\nabla_\tX y Xy Tensor containing derivatives of y with respect to X
\frac{\partial f}{\partial \vx} fx Jacobian matrix JRm×n of f:RnRm
\nabla_\vx^2 f(\vx)\text{ or }\mH(f)(\vx) x2f(x) or H(f)(x) The Hessian matrix of f at input point x
\int f(\vx) d\vx f(x)dx Definite integral over the entire domain of x
\int_\sS f(\vx) d\vx Sf(x)dx Definite integral with respect to x over the set S

Probabilities

Command Visualization Comment
\ra \bot \rb ab The random variables a and b are independent
\ra \bot \rb \mid \rc abc They are conditionally independent given c
P(\ra) P(a) A probability distribution over a discrete variable
p(\ra) p(a) A probability distribution over a continuous variable, or a variable of unspecified type
\ra \sim P aP Random variable a has distribution P
\E_{\rx \sim P} [ f(x) ] \text{ or } \E f(x) ExP[f(x)] or Ef(x) Expectation of f(x) with respect to P(x)
\Var(f(x)) Var(f(x)) Variance of f(x) under P(x)
\Cov(f(x), g(x)) Cov(f(x),g(x)) Covariance of f(x) and g(x) under P(x)
H(\rx) H(x) Shannon entropy of the random variable x
\KL(P \Vert Q) DKL(PQ) Kullback-Leibler divergence of P and Q
\mathcal{N}(\vx ; \vmu , \mSigma) N(x;μ,Σ) Gaussian distribution over x with mean μ and covariance Σ

Functions

Command Visualization Comment
f: \sA \rightarrow \sB f:AB The function f with domain A and range B
f \circ g fg Composition of the functions f and g
f(\vx ; \vtheta) f(x;θ) A function of x parametrized by θ. Sometimes written as f(x) to simplify notation
\log x logx Natural logarithm of x
\sigma(x) σ(x) Logistic sigmoid, 11+exp(x)
\zeta(x) ζ(x) Softplus, log(1+exp(x))
\Vert \vx \Vert_p xp Lp norm of x
\Vert \vx \Vert x L2 norm of x
x^+ x+ Positive part of x, i.e., max(0,x)
\bm{1}_\mathrm{condition} 1condition Is 1 if the condition is true, 0 otherwise

Custom Commands special

Command Visualization Comment
\bm{#1} x Bold symbol, e.g., x
\sign sign operator, Sign , sign
\Tr Tr operator Trace, Tr
\E E Expectation, E
\KL DKL Kullback-Leibler divergence, DKL
\NormalDist N Gaussian distribution, N
\diag diag Diagonal matrix, diag
\Ls L Loss function, L
\R R Real number set, R
\emp p~ Empirical distribution, p~
\lr α Learning rate, α
\reg λ Regularization coefficient, λ
\rect rectifier Rectifier activation, rectifier
\softmax softmax Softmax function, softmax
\sigmoid σ Sigmoid function, σ
\softplus ζ Softplus function, ζ
\Var Var Variance, Var
\standarderror SE Standard error, SE
\Cov Cov Covariance, Cov
\tran Transpose operator,
\inv 1 Inverse operator, 1
\diff d Differential operator, d

Reference

  • Ian Goodfellow's ML book: https://github.com/goodfeli/dlbook_notation/blob/master/notation_example.pdf
  • MathJax: https://docs.mathjax.org/en/latest/input/tex/macros.html