Skip to content

Senior Syntax

Tables

Use $$\begin{array}{column_styles}...\end{array}$$ to create tables.

The column styles can be c, l, or r, which stand for center, left, and right alignment, respectively. You can also use | to add a vertical line.

Rows in the table are separated by \\, and columns by &.

Use \hline to insert a horizontal line before the current row.

  • Example:

    $$
    \begin{array}{c|lcr}
    n & \text{Left} & \text{Center} & \text{Right} \\
    \hline
    1 & 0.24 & 1 & 125 \\
    2 & -1 & 189 & -8 \\
    3 & -20 & 2000 1+10i \\
    \end{array}
    $$
  • Output:

    nLeftCenterRight10.24112521189832020001+10i

Matrices

  • Basic usage

    Use $$\begin{matrix}...\end{matrix}$$ to create matrices. Separate rows with \\ and columns with &.

    • Example:

      $$
      \begin{matrix}
      1 & x & x^2 \\
      1 & y & y^2 \\
      1 & z & z^2 \\
      \end{matrix}
      $$
    • Output:

      1xx21yy21zz2
  • Adding brackets

    To add brackets around matrices, use \left and \right.

    You can also use special matrix types like pmatrix, bmatrix, Bmatrix, vmatrix, or Vmatrix.

    • Example:

      $$
      \begin{pmatrix}
      1 & 2 \\
      3 & 4 \\
      \end{pmatrix}
      $$
      
      $$
      \begin{bmatrix}
      1 & 2 \\
      3 & 4 \\
      \end{bmatrix}
      $$
      
      $$
      \begin{Bmatrix}
      1 & 2 \\
      3 & 4 \\
      \end{Bmatrix}
      $$
      
      $$
      \begin{vmatrix}
      1 & 2 \\
      3 & 4 \\
      \end{vmatrix}
      $$
      
      $$
      \begin{Vmatrix}
      1 & 2 \\
      3 & 4 \\
      \end{Vmatrix}
      $$
    • Output:

      (1234)[1234]{1234}|1234|1234
  • Omitted Elements

    You can use \cdots, \ddots, and \vdots to omit elements in a matrix.

    • Example:

      $$
      \begin{matrix}
      1 & a_1 & a_1^2 & \cdots & a_1^n \\
      1 & a_2 & a_2^2 & \cdots & a_2^n \\
      \vdots & \vdots & \vdots & \ddots & \vdots \\
      1 & a_m & a_m^2 & \cdots & a_m^n \\
      \end{matrix}
      $$
    • Output:

      1a1a12a1n1a2a22a2n1amam2amn
  • Augmented Matrices

    Augmented matrices are created using the array environment.

    • Example:

      $$
      \left[
        \begin{array}{cc|c}
        1 & 2 & 3 \\
        4 & 5 & 6 \\
        \end{array}
      \right]
      $$
    • Output:

      [123456]

Aligned Equations

Sometimes, you may want to align equations, particularly at the equals sign. This can be done using the \begin{align}...\end{align} format, where & is used to specify the alignment.

  • Example:

    $$
    \begin{align}
    \sqrt{37}&=\sqrt{\frac{73^2-1}{12^2}} \\
    &=\sqrt{\frac{73^2}{12^2}\cdot\frac{73^2-1}{73^2}} \\
    &=\sqrt{\frac{73^2}{12^2}}\sqrt{\frac{73^2-1}{73^2}} \\
    &=\frac{73}{12}\sqrt{1-\frac{1}{73^2}} \\
    &\approx\frac{73}{12}\left(1-\frac{1}{2\cdot73^2}\right)
    \end{align}
    $$
  • Output:

    37=7321122=7321227321732=7321227321732=7312117327312(112732)

Piecewise Expressions

When defining a function with multiple cases, use \begin{cases}...\end{cases}. Rows are separated by \\ and & indicates alignment.

  • Example:

    $$
    f(n)=
    \begin{cases}
    n/2,&\text{if $n$ is even} \\
    3n+1,&\text{if $n$ is odd}
    \end{cases}
    $$
  • Output:

    f(n)={n/2,if n is even3n+1,if n is odd

To increase vertical spacing between cases, add \\[2ex] at the end of a row (3ex, 4ex, etc., can also be used, 1ex being the default).

  • Output:

    f(n)={n2,if n is even3n+1,if n is odd

Spacing Issues

There are certain issues in LATEX formulas that don't affect correctness but make the output look unpolished.

  • Avoid using \frac in exponents or integrals

    Using \frac in such expressions reduces clarity. It’s rarely used in professional mathematical typesetting. Instead, / should be used.

    • Example:

      $$
      \begin{array}{c|c}
      \mathrm{Bad} & \mathrm{Better} \\
      \hline \\
      e^{i\frac{\pi}2} & e^{i\pi/2} \\
      \int^\frac\pi2_{-\frac\pi2}\sin x \,dx & \int^{\pi/2}_{\pi/2}\sin x \,dx
      \end{array}
      $$
    • Output:

      BadBettereiπ2eiπ/2π2π2sinxdxπ/2π/2sinxdx
  • Use \mid instead of | as a separator

    When | is used as a separator, there’s an issue with spacing. Use \mid instead.

    • Example:

      $$
      \begin{array}{c|c}
      \mathrm{Bad}&\mathrm{Better}\\
      \hline\\
      \{x|x^2\in\Bbb Z\}&\{x\mid x^2\in\Bbb Z\}
      \end{array}
      $$
    • Output:

      BadBetter{x|x2Z}{xx2Z}
  • Multiple integrals

    For multiple integrals, avoid using \int\int. Instead, use specific commands like \iint, \iiint, etc.

    • Example:

      $$
      \begin{array}{c|c}
      \mathrm{Bad}&\mathrm{Better}\\
      \hline\\
      \int\int_S f(x)\,dy\,dx&\iint_S f(x)\,dy\,dx\\
      \int\int\int_V f(x)\,dz\,dy\,dx&\iiint_V f(x)\,dz\,dy\,dx
      \end{array}
      $$
    • Output:

      BadBetterSf(x)dydxSf(x)dydxVf(x)dzdydxVf(x)dzdydx

In differential expressions, use \, to add a small amount of space; otherwise, LATEX will tightly arrange the terms.

  • Example:

    $$
    \begin{array}{c|c}
    \mathrm{Bad}&\mathrm{Better}\\
    \hline\\
    \iiint_V f(x)dz dy dx&\iiint_V f(x)\,dz\,dy\,dx
    \end{array}
    $$
  • Output:

    BadBetterVf(x)dzdydxVf(x)dzdydx

Continued Fractions

When writing continued fractions, use \cfrac instead of \frac or \over.

  • Example:

    $$
    x=a_0+\cfrac{1^2}{a_1
    +\cfrac{2^2}{a_2
    +\cfrac{3^2}{a^3
    +\cfrac{4^2}{a_4+\cdots}}}}
    $$
  • Output:

    x=a0+12a1+22a2+32a3+42a4+

Systems of Equations

Use \begin{array}...\end{array} and \left\{...\right. to represent systems of equations.

  • Example:

    $$
    \left\{
    \begin{array}{c}
    a_1x+b_1y+c_1z=d_1 \\
    a_2x+b_2y+c_2z=d_2 \\
    a_3x+b_3y+c_3z=d_3
    \end{array}
    \right.
    $$
  • Output:

    {a1x+b1y+c1z=d1a2x+b2y+c2z=d2a3x+b3y+c3z=d3

Alternatively, you can use \begin{cases}...\end{cases} for the same system of equations:

$$
\begin{cases}
a_1x+b_1y+c_1z=d_1 \\
a_2x+b_2y+c_2z=d_2 \\
a_3x+b_3y+c_3z=d_3
\end{cases}
$$

To align equals signs in equations, use \begin{aligned}...\end{aligned}.

  • Example:

    $$
    \left\{
    \begin{aligned}{c}
    a_1x+b_1y+c_1z=d_1 \\
    a_2x+b_2y=d_2 \\
    a_3x+b_3y+c_3z=d_3
    \end{aligned}
    \right.
    $$
  • Output:

    {ca1x+b1y+c1z=d1a2x+b2y=d2a3x+b3y+c3z=d3

If you need to align equations and terms, use \begin{array}{column_styles}...\end{array}.

  • Example:

    $$
    \left\{
    \begin{array}{ll}
    a_1x+b_1y+c_1z&=d_1 \\
    a_2x+b_2y&=d_2 \\
    a_3x+b_3y+c_3z&=d_3
    \end{array}
    \right.
    $$
  • Output:

    {a1x+b1y+c1z=d1a2x+b2y=d2a3x+b3y+c3z=d3

Additional Decorations

  • \overline{A}\;\overline{AA}\;\overline{AAA}

    AAAAAA

  • \underline{B}\;\underline{BB}\;\underline{BBB}

    BBBBBB

  • \widetilde{C}\;\widetilde{CC}\;\widetilde{CCC}

    C~CC~CCC~

  • \widehat{D}\;\widehat{DD}\;\widehat{DDD}

    D^DD^DDD^

  • \fbox{E}\;\fbox{EE}\;\fbox{EEE}

    EEEEEE

  • \underleftarrow{F}\;\underleftarrow{FF}\;\underleftarrow{FFF}

    FFFFFF

  • \underrightarrow{G}\;\underrightarrow{GG}\;\underrightarrow{GGG}

    GGGGGG

  • \underleftrightarrow{H}\;\underleftrightarrow{HH}\;\underleftrightarrow{HHH}

    HHHHHH

  • \overbrace{(n-2)+\overbrace{(n_1)+n+(n+1)}+(n+2)}

    (n2)+(n1)+n+(n+1)+(n+2)

  • \underbrace{(n-2)+\underbrace{(n_1)+n+(n+1)}+(n+2)}

    (n2)+(n1)+n+(n+1)+(n+2)

  • \overbrace and \underbrace can be annotated with superscripts and subscripts, such as \underbrace{a\cdot a\cdots a}_{b_\text{times}}:

    aaabtimes

  • Phonetic symbols, like \check{I}: Iˇ, \acute{J}: J´, \grave{K}: K`.

Commutative Diagrams

Use \begin{CD}...\end{CD} to represent commutative diagrams.

  • Example:

    $$
    \begin{CD}
    A@>a>>B \\
    @VbVV=@VVcV \\
    c@>>d>D
    \end{CD}
    $$
  • Output:

    AaBb=ccdD

In the diagram, @>>> represents a right arrow, @<<< represents a left arrow, @AAA represents an upward arrow, @VVV represents a downward arrow, @= represents a horizontal double line, @| represents a vertical double line, and @. represents no arrow.

  • Example:

    $$
    \begin{CD}
    A@>>>B@>{\text{very long label}}>>C \\
    @.@AAA@|\\
    D@=E@<<<F
    \end{CD}
    $$
  • Output:

    ABvery long labelCD=EF

Colors

There are two ways to color text.

  • \textcolor{color-name}{text}:

    Here, color-name is the system-defined color, and text is the content to be colored.

    For example, \textcolor{hotpink}{E=mc^2}: E=mc2.

  • \textcolor[rgb]{r,g,b}{text}\textcolor[RGB]{R,G,B}{text}:

    In rgb, values range from 0 to 1, and in RGB, values range from 0 to 255.

    For example, \textcolor[rgb]{0.5,0.8,0.7}{E=mc^2}: E=mc2, or \textcolor[RGB]{202,12,22}{E=mc^2}: E=mc2.

You can also define custom colors using \definecolor{ColorName}{rgb}{r,g,b}.

  • Example:

    $$
    \definecolor{mycolor}{rgb}{0.1,0.5,0.8}
    \textcolor{mycolor}{E=mc^2}
    $$
  • Output:

    E=mc2

Highlighting Equations

Use \bbox to highlight an equation.

  • Example:

    \bbox[blue]{\textcolor{white}{e^x=\lim_{n\to\infty}\left(1+\frac{x}{n}\right)^n\qquad(1)}}
  • Output:

    ex=limn(1+xn)n(1)

You can also add padding (similar to padding in CSS) by specifying numerical values.

  • Example:

    \bbox[blue,10px]{\textcolor{white}{e^x=\lim_{n\to\infty}\left(1+\frac{x}{n}\right)^n\qquad(1)}}
  • Output:

    ex=limn(1+xn)n(1)

Borders can also be added.

  • Example:

    \bbox[10px,border:2px solid red]{{e^x=\lim_{n\to\infty}\left(1+\frac{x}{n}\right)^n\qquad(1)}}
  • Output:

    ex=limn(1+xn)n(1)

Additionally, you can set both background color and border at the same time.

  • Example:

    \bbox[10px,hotpink,border:2px dashed blue]{{e^x=\lim_{n\to\infty}\left(1+\frac{x}{n}\right)^n\qquad(1)}}
  • Output:

    ex=limn(1+xn)n(1)