Skip to main content

LaTex Notation and Cheat Sheet

This notation guide is inspired by Deep Learning by Ian Goodfellow, Yoshua Bengio and Aaron Courville whilst trying to stay short and compatible with KaTeX (Docusaurus support) and MathJax (Jupyter Notebook support). This page is also meant as a cheat sheet for me on latex structures such as matrices etc.

Numbers and Arrays

If we wanted tensors to also be bold we would have to write \mathsf{\boldsymbol{A}} which is sadly not nice and short.

DescriptionCodeExample
Scalar (integer or real)a=2aa
Vector, lowercase italic bold\boldsymbol{a}a\boldsymbol{a}
Matrix, uppercase italic bold\boldsymbol{A}A\boldsymbol{A}
Tensor, uppercase sans-serif\mathsf{A}A\mathsf{A}
Identity matrix with nn rows and nn columns\boldsymbol{I}_nIn\boldsymbol{I}_n
Identity matrix with implied dimensionality\boldsymbol{I}I\boldsymbol{I}
Square diagonal matrix with elements along main diagonal given by a\boldsymbol{a}\text{diag}(\boldsymbol{a})diag(a)\text{diag}(\boldsymbol{a})

Indexing

DescriptionCodeExample
Element ii of vector a\boldsymbol{a}, with indexing starting at 1a_iaia_i
All elements of vector a\boldsymbol{a} except for element iia_{-i}aia_{-i}
Element i,ji,j of matrix A\boldsymbol{A}, with ii corresponding to the row index and jj the column indexA_{i,j} or a_{ij}Ai,jA_{i,j} or aija_{ij}
Row ii of matrix A\boldsymbol{A}\boldsymbol{A}_{i,:}Ai,:\boldsymbol{A}_{i , :}
Column jj of matrix A\boldsymbol{A}\boldsymbol{A}_{:,j}A:,j\boldsymbol{A}_{: , j}

Linear Algebra Operations

DescriptionCodeExample
Tranpose of matrix A\boldsymbol{A}\boldsymbol{A}^TAT\boldsymbol{A}^T
Moore-Penrose pseudoinverse of matrix A\boldsymbol{A}\boldsymbol{A}^\daggerA\boldsymbol{A}^\dagger
Hadamard (element-wise) product of A\boldsymbol{A} and B\boldsymbol{B}\boldsymbol{A} \odot boldsymbol{B}AB\boldsymbol{A} \odot \boldsymbol{B}
Determinant of matrix A\boldsymbol{A}\text{det}(\boldsymbol{A})det(A)\text{det}(\boldsymbol{A})
Trace of matrix A\boldsymbol{A}\text{tr}(\boldsymbol{A})tr(A)\text{tr}(\boldsymbol{A})

Sets and Graphs

DescriptionCodeExample
SetAAA
Set of natural numbers, including 00\Bbb{N}=\{0,1,2,3,...\}N={0,1,2,3,...}\Bbb{N}=\{0,1,2,3,...\}
Set of integer numbers\Bbb{Z}Z\Bbb{Z}
Set of rational numbers\Bbb{Q}Q\Bbb{Q}
Set of irrational numbers\Bbb{I}I\Bbb{I}
Set of real numbers\Bbb{R}R\Bbb{R}
Set of complex numbers\Bbb{C}C\Bbb{C}