Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

KaTeX Supported Functions and Syntax Guide

Tech 1

KaTeX supports a comprehensive set of TeX functions, organized logical. The following sections detail supported features, with examples of syntax and rendering.

Accents and Diacritical Marks

Rendered Code Rendered Code Rendered Code
(a') a' (\tilde{a}) \tilde{a} (\mathring{g}) \mathring{g}
(a'') a'' (\widetilde{ac}) \widetilde{ac} (\overgroup{AB}) \overgroup{AB}
(a^{\prime}) a^{\prime} (\utilde{AB}) \utilde{AB} (\undergroup{AB}) \undergroup{AB}
(\acute{a}) \acute{a} (\vec{F}) \vec{F} (\Overrightarrow{AB}) \Overrightarrow{AB}
(\bar{y}) \bar{y} (\overleftarrow{AB}) \overleftarrow{AB} (\overrightarrow{AB}) \overrightarrow{AB}
(\breve{a}) \breve{a} (\underleftarrow{AB}) \underleftarrow{AB} (\underrightarrow{AB}) \underrightarrow{AB}
(\check{a}) \check{a} (\overleftharpoon{ac}) \overleftharpoon{ac} (\overrightharpoon{ac}) \overrightharpoon{ac}
(\dot{a}) \dot{a} (\overleftrightarrow{AB}) \overleftrightarrow{AB} (\overbrace{AB}) \overbrace{AB}
(\ddot{a}) \ddot{a} (\underleftrightarrow{AB}) \underleftrightarrow{AB} (\underbrace{AB}) \underbrace{AB}
(\grave{a}) \grave{a} (\overline{AB}) \overline{AB} (\overlinesegment{AB}) \overlinesegment{AB}
(\hat{\theta}) \hat{\theta} (\underline{AB}) \underline{AB} (\underlinesegment{AB}) \underlinesegment{AB}
(\widehat{ac}) \widehat{ac} (\widecheck{ac}) \widecheck{ac}

Additional accents work within \text{}:

Rendered Code Rendered Code Rendered Code Rendered Code
(\text{'{a}}) \'{a} (\text{~{a}}) \~{a} (\text{.{a}}) \.{a} (\text{\H{a}}) \H{a}
(\text{`{a}}) \{a}` (\text{={a}}) \={a} (\text{"{a}}) \"{a} (\text{\v{a}}) \v{a}
(\text{^{a}}) \^{a} (\text{\u{a}}) \u{a} (\text{\r{a}}) \r{a}

Delimiters (Parentheses and Brackets)

Rendered Code Rendered Code Rendered Code
(()) () (\lparen\rparen) \lparen\rparen (\lceil\rceil) \lceil\rceil
([]) [] (\lbrack\rbrack) \lbrack\rbrack (\lfloor\rfloor) \lfloor\rfloor
({}) \{\} (\lbrace\rbrace) \lbrace\rbrace (\lmoustache\rmoustache) \lmoustache\rmoustache
(\langle\rangle) \langle\rangle (\lang\rang) \lang\rang (\llbracket\rrbracket) \llbracket\rrbracket
(\vert) \vert (\lvert\rvert) \lvert\rvert (\Vert) \Vert
(\lVert\rVert) \lVert\rVert (\backslash) \backslash (\ulcorner\urcorner) \ulcorner\urcorner

Delimiters can be sized manually or with \left and \right:

  • Manual sizing: \big( \Big( \bigg( \Bigg(
  • Auto-sizing: \left(\LARGE{AB}\right)

Environments

Matrix and array environments:

Environment Rendered Code
matrix (\begin{matrix}a & b \ c & d\end{matrix}) \begin{matrix}a & b \\ c & d\end{matrix}
pmatrix (\begin{pmatrix}a & b \ c & d\end{pmatrix}) \begin{pmatrix}a & b \\ c & d\end{pmatrix}
bmatrix (\begin{bmatrix}a & b \ c & d\end{bmatrix}) \begin{bmatrix}a & b \\ c & d\end{bmatrix}
vmatrix (\begin{vmatrix}a & b \ c & d\end{vmatrix}) \begin{vmatrix}a & b \\ c & d\end{vmatrix}
Bmatrix (\begin{Bmatrix}a & b \ c & d\end{Bmatrix}) \begin{Bmatrix}a & b \\ c & d\end{Bmatrix}
array (\begin{array}{cc}a & b \ c & d\end{array}) \begin{array}{cc}a & b \\ c & d\end{array}

Alignment environments:

Environment Rendered Code
aligned (\begin{aligned}a&=b+c \ d+e&=f\end{aligned}) \begin{aligned}a&=b+c \\ d+e&=f\end{aligned}
gathered (\begin{gathered}a=b \ e=b+c\end{gathered}) \begin{gathered}a=b \\ e=b+c\end{gathered}
cases (x=\begin{cases}a & \text{if } b \ c & \text{if } d\end{cases}) x=\begin{cases}a & \text{if } b \\ c & \text{if } d\end{cases}

Unicode Mathematical Alphabets and Symbols

Supported Unicode alphabets:

Style Supported Characters Code Example
Bold A-Z, a-z, 0-9 \mathbf{Ab0}
Italic A-Z, a-z \mathit{Ab0}
Sans-serif A-Z, a-z, 0-9 \mathsf{Ab0}
Blackboard bold A-Z, k \mathbb{AB}
Fraktur A-Z, a-z \mathfrak{Ab0}
Calligraphic A-Z, 0-9 \mathcal{AB0}

KaTeX renders these alphabets correctly in any mode. Non-Latin scripts (e.g., Brahmic, CJK) are supported but rely on system fonts, potentially causing alignment issues.

Layout

Annotations and Marks

Rendered Code
(\cancel{5}) \cancel{5}
(\bcancel{5}) \bcancel{5}
(\xcancel{ABC}) \xcancel{ABC}
(\sout{abc}) \sout{abc}
(\boxed{\pi=\frac{c}{d}}) \boxed{\pi=\frac{c}{d}}
(\tag{hi} x+y^{2x}) \tag{hi} x+y^{2x}
(\tag*{hi} x+y^{2x}) \tag*{hi} x+y^{2x}

Line Breaking

Inline math breaks after relations or binary operators (e.g., =, +). Prevent breaks with \nobreak or braces: {F=ma}. Allow breaks elsewhere with \allowbreak. Hard breaks: \\ or \newline.

Vertical Layout

Rendered Code Rendered Code
(x_n) x_n (e^x) e^x
(\stackrel{!}{=}) \stackrel{!}{=} (\overset{!}{=}) \overset{!}{=}
(a \atop b) a \atop b (a\raisebox{0.25em}{b}c) a\raisebox{0.25em}{b}c

Overlap and Spacing

Rendered Code
({=}\mathllap{/,}) {=}\mathllap{/\,}
(\mathrlap{,/}{=}) \mathrlap{\,/}{=}
(\left(x^{\smash{2}}\right)) \left(x^{\smash{2}}\right)
(\sqrt{\smash[b]{y}}) \sqrt{\smash[b]{y}}
(\sum\limits_{\mathclap{1\le i\le j\le n}} x_{ij}) \sum_{\mathclap{1\le i\le j\le n}} x_{ij}

Spacing Commands

Command Width Command Width
\, or \thinspace (3/18) em \! or \negthinspace (-3/18) em
\: or \medspace (4/18) em \negmedspace (-4/18) em
\; or \thickspace (5/18) em \negthickspace (-5/18) em
\enspace (1/2) em \quad 1 em
\qquad 2 em ~ non-breaking space
\phantom{content} size of content \hphantom{content} width of content
\vphantom{content} height of content

Logic and Set Symbols

Rendered Code Rendered Code
(\forall) \forall (\exists) \exists
(\in) \in (\notin) \notin
(\subset) \subset (\supset) \supset
(\cup) \cup (\cap) \cap
(\land) \land (\lor) \lor
(\neg) \neg (\implies) \implies

Macro Defiintions

Define macros with \def, \gdef, \newcommand, \renewcommand, or \providecommand:

  • \def\macroName{definition}
  • \newcommand{\macroName}[numArgs]{definition}

Macros accept up to nine arguments (#1 through #9).

Operators

Large Operators

Rendered Code Rendered Code
(\sum) \sum (\prod) \prod
(\int) \int (\bigotimes) \bigotimes
(\bigcup) \bigcup (\bigcap) \bigcap

Binary Operators

Rendered Code Rendered Code
(+) + (-) -
(\times) \times (\div) \div
(\cdot) \cdot (\pm) \pm
(\cap) \cap (\cup) \cup
(\oplus) \oplus (\otimes) \otimes

Fractions and Binomials

Rendered Code
(\frac{a}{b}) \frac{a}{b}
(\tfrac{a}{b}) \tfrac{a}{b}
(\cfrac{a}{1+\cfrac{1}{b}}) \cfrac{a}{1+\cfrac{1}{b}}
(\binom{n}{k}) \binom{n}{k}
({n \choose k}) {n \choose k}

Mathematical Operators

Rendered Code Rendered Code
(\sin) \sin (\cos) \cos
(\log) \log (\lim) \lim
(\det) \det (\gcd) \gcd
(\sup) \sup (\inf) \inf

Roots

  • Square root: \sqrt{x} → (\sqrt{x})
  • nth root: \sqrt[n]{x} → (\sqrt[n]{x})

Relations

Rendered Code Rendered Code
(=) = (<) <
(>) > (\approx) \approx
(\leq) \leq (\geq) \geq
(\subset) \subset (\supset) \supset
(\in) \in (\ni) \ni

Arrows

Rendered Code Rendered Code
(\to) \to (\gets) \gets
(\Rightarrow) \Rightarrow (\Leftarrow) \Leftarrow
(\mapsto) \mapsto (\hookrightarrow) \hookrightarrow

Extensible Arrows

Arrows that stretch with text:

  • \xrightarrow[under]{over} → (\xrightarrow[under]{over})
  • \xleftarrow{text} → (\xleftarrow{text})

Styles, Colors, Sizes, and Fonts

Colors

Set colors with \color, \textcolor, \colorbox, or \fcolorbox:

  • \color{blue} F=ma → (\color{blue} F=ma)
  • \textcolor{#228B22}{F=ma} → (\textcolor{#228B22}{F=ma})
  • \colorbox{aqua}{A} → (\colorbox{aqua}{A})

Fonts

Font Style Code Example Rendered
Roman \mathrm{Ab0} (\mathrm{Ab0})
Bold \mathbf{Ab0} (\mathbf{Ab0})
Italic \mathit{Ab0} (\mathit{Ab0})
Sans-serif \mathsf{Ab0} (\mathsf{Ab0})
Blackboard bold \mathbb{AB} (\mathbb{AB})
Calligraphic \mathcal{AB0} (\mathcal{AB0})

Sizes

Size Command Example
\tiny (\tiny AB)
\small (\small AB)
\normalsize (\normalsize AB)
\large (\large AB)
\huge (\huge AB)

Styles

Style Code Rendered
Display \displaystyle\sum_{i=1}^n (\displaystyle\sum_{i=1}^n)
Text \textstyle\sum_{i=1}^n (\textstyle\sum_{i=1}^n)
Script \scriptstyle x (\scriptstyle x)
Scriptscript \scriptscriptstyle x (\scriptscriptstyle x)

Symbols and Punctuation

Symbol Code Symbol Code
(%) \% (#) \#
(&) \& (_) \_
(\dots) \dots (\cdots) \cdots
(\infty) \infty (\nabla) \nabla
(\angle) \angle (\triangle) \triangle
(\checkmark) \checkmark (\dag) \dag

Units

KaTeX units scale proportional as in TeX, but differ from CSS units. Common units:

  • em: CSS em
  • ex: CSS ex
  • mu: 1/18 CSS em
  • pt: 1/72.27 inch × scaling factors
  • mm, cm, in: metric and imperial units

Scaling factors depend on HTML font size and KaTeX's default magnification (1.21×).

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.