Display math puts an equation on its own line, centred and set at full size, so sums and fractions are not squeezed into the line height. Use \[ ... \] for a single unnumbered equation, the equation environment when you need a number to refer to, and amsmath's align when several lines should line up.
All ways to write it
\[ ... \]an unnumbered equation on its own centred lineNo package needed\begin{equation} ... \end{equation}a numbered equationNo package needed\begin{equation*} ... \end{equation*}the same without the numberPackage: amsmath\begin{align} a &= b \\ c &= d \end{align}several lines lined up at the &, each numberedPackage: amsmath\begin{gather} ... \end{gather}several centred lines with no alignmentPackage: amsmath\tag{1}a custom label in place of the automatic numberPackage: amsmath$$ ... $$plain TeX display math; works, but \[ ... \] is preferred in LaTeXNo package needed
Commands marked with a package need that \usepackage line in a LaTeX document.
Example
\begin{align}
(a + b)^2 &= (a + b)(a + b) \\
&= a^2 + 2ab + b^2
\end{align}Two lines aligned at the equals sign, the usual way to show the steps of a derivation.
Questions
What is the difference between inline and display math?
Inline math ($...$ or \(...\)) sits inside a sentence and is shrunk to fit the line: limits go beside a sum and fractions get smaller. Display math gets its own centred line at full size. Use display math for any equation the reader needs to study.
Should I use $$ ... $$ or \[ ... \]?
Use \[ ... \] in LaTeX documents. $$ is plain TeX: it still works, but it can leave uneven space around the equation and ignores options such as fleqn. Markdown, Jupyter and many web tools accept $$, which is why it shows up so often online.
How do I number an equation and refer to it?
Use the equation environment and add \label{eq:energy} inside it, then write \eqref{eq:energy} (amsmath) or \ref{eq:energy} in the text. Use equation* or \[ ... \] when you do not want a number, and \tag{A} for a label of your own. KaTeX-based tools number equations and accept \tag, but not \label or \eqref.
How do I write an equation over several lines?
Use amsmath's align. End each line with \\ and put & before the symbol the lines should line up on, usually the equals sign. align* drops the numbers, and \nonumber removes the number from a single line.
Do equation and align work in KaTeX and Confluence?
Yes, in display mode. KaTeX renders equation, align, gather and their starred forms, so in Confluence put them in a block math macro, not an inline one.
Using display math in Confluence
Confluence Cloud has no built-in LaTeX. With LaTeX Math for Confluence you add a math macro to any page, type \[ ... \] and it renders inline or as a block, with a live preview while you edit. Every command on this page renders there without extra packages.