Spacing

  • Spaces are often ignored when typing KaTEX in either inline or display mode.
  • P( x ) = x^2 - x + 1
  • To format spaces, we use escape characters and specific commands for that.
    • For example, using \, will allow us to space our characters by em space:
  • Here’s an example of different spacing commands and their equivalent units.
CommandAlternate CommandWidthExampleOutput
\,\thinspace em spacea \,\, b
\> or \:\medspace em spacea \>\: b
\;\thickspace em spacea \;\; b
\enspace em spacea \enspace b
\quad em spacea \quad b
\qquad em spacea \qquad b

Negative Spacing

  • Negative spacing allows you to remove spacing between two characters
    • a \negthinspace b displays as
CommandWidthExampleOutput
\negthinspace em space(a + b) \negthinspace (b + a)
\negmedspace em space(a + b) \negmedspace (b + a)
\negthickspace em space(a + b) \negthickspace (b + a)

Custom Spacing

  • Aside from predefined spacing commands, KaTEX also supports custom spacing with KaTEX units using the command \hspace{length}.

  • a \hspace{10ex} b

  • The length argument accepts any positive or negative spacing values, or in terms of other units such as the CSS em, or CSS ex.

    • You may want to see here for more precise units that are natively supported by KaTEX.

Text

  • If we want to display text in math mode, we would use the \text{} command.
    • Anything displayed inside the \text command will be displayed as normal text.
\frac{1}{(ax +b)(cx + d)} = \frac{A}{ax + b} + \frac{B}{cx + d} \qquad \text{Partial Fraction Decomposition}