Skip to main content
v2026.11,986 entries · CC-BY 4.0

LaTeX amsmath Guide: Setup, Environments and Syntax

Configure the LaTeX amsmath package for research papers. Master package options, align, gather, multline, matrix environments, and custom math operators.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

The LaTeX amsmath package is the foundational extension developed by the American Mathematical Society for typesetting complex mathematical formulas, multi-line equation derivations, and structured matrix systems in scientific publications. Maintained as a standard component of the LaTeX distribution by the LaTeX Project, amsmath replaces fragile legacy structures like eqnarray with robust environments such as align, gather, multline, and cases, ensuring standardized typography across peer-reviewed research.

What it is used for in research

In academic writing across mathematics, physics, engineering, statistics, and computer science, mathematical notation communicates the core theoretical models and empirical derivations of a study. Standard base LaTeX provides elementary mathematical typesetting capabilities through inline delimiters and the basic equation display environment. However, when researchers construct complex mathematical proofs, systems of coupled differential equations, or multi-step statistical derivations, base LaTeX encounters severe typographic limitations.

Historically, researchers relied on the standard LaTeX eqnarray environment to format multi-line calculations. The eqnarray command suffers from well-documented flaws: it enforces inconsistent, disproportionately wide horizontal spacing around relational operators, frequently permits equation numbers to collide directly with lengthy formulas without automatic suppression or shifting, and lacks semantic flexibility for grouped systems. To overcome these deficiencies, the American Mathematical Society (AMS) developed AMS-LaTeX in the late 1980s and 1990s, led by Michael Downes and Frank Mittelbach. The core mathematical macros were unified into the amsmath package, which has since been adopted as a mandatory requirement by major academic publishers including Elsevier, Springer Nature, IEEE, and the Society for Industrial and Applied Mathematics (SIAM).

In contemporary research workflows, amsmath is used for several critical typesetting tasks:

  • Precise Multi-Line Alignment: The package provides specialized display structures, including align for equations aligned at relation symbols (such as equality or inequality signs), gather for consecutive centered equations without horizontal alignment, and multline for long single formulas that span multiple physical lines.
  • Subordinate and Nested Systems: Researchers can nest inner structures like split, aligned, and gathered within primary equation environments. This allows authors to maintain a single global equation number for a multi-step algebraic derivation, or cross-reference individual sub-equations using the companion align and aligned environments.
  • Matrix and Vector Typography: Through built-in matrix environments—including matrix, pmatrix, bmatrix, vmatrix, and Vmatrix—authors produce matrices with appropriate brackets, determinants, and norms without manually coding coordinate arrays. For specialized tabular math structures, see the companion guide to LaTeX matrix environments.
  • Piecewise Definitions and Conditional Logic: The cases environment formats piecewise functions, boundary conditions, and decision trees using a unified, scalable left brace, detailed further in our overview of the cases environment for piecewise functions.
  • Semantic Operator Declaration: The DeclareMathOperator and operatorname commands generate custom mathematical operators with the correct upright font and contextual kerning matching standard operators like sine, limit, and logarithm.
  • Flexible Equation Cross-Referencing: The package introduces eqref, which automatically encloses equation references in standardized parentheses, ensuring consistency across journal articles regardless of local punctuation habits.

How to install or access it

The amsmath package is licensed under the LaTeX Project Public License (LPPL 1.3c) and is included as a standard, pre-installed component of the LaTeX required bundle. Consequently, researchers working in modern TeX distributions do not need to execute external downloads or package management operations to access the core software.

The package is universally accessible across the primary TeX ecosystems:

  • TeX Live (Linux and Windows): Distributed as part of the core collection-latex scheme, maintained annually by the TeX Users Group (TUG).
  • MacTeX (macOS): Included in the default full installation for macOS systems, accessible through TeXShop, VS Code, and terminal engines.
  • MiKTeX (Windows and Linux): Packaged in the fundamental MiKTeX installation. If a minimal MiKTeX installation is used, the package manager retrieves amsmath automatically from CTAN upon encountering the declaration.
  • Cloud TeX Platforms (Overleaf): Pre-installed and maintained across all active TeX Live image versions on cloud platforms.

To load the package into a research manuscript, insert the package declaration in the document preamble prior to the begin{document} command:

documentclass[11pt,a4paper]{article}
usepackage{amsmath}
usepackage{amssymb} % Recommended companion for AMS mathematical symbols

When loading amsmath, authors can supply optional parameters to modify global layout, tag alignment, and operator limit rules across the entire document:

  • fleqn: Left-aligns all displayed equations with a fixed indentation from the left margin, rather than centering them horizontally on the page. While this option can also be declared in documentclass, passing it to amsmath enforces flush-left alignment across all AMS display structures.
  • leqno: Places all equation numbers and labels on the left margin rather than the standard right margin (reqno).
  • centertags: The default setting, which centers equation numbers vertically relative to the total height of split or multi-line equations.
  • tbtags: “Top-or-bottom tags.” Forces equation numbers to align vertically with the bottom line (when equation numbers are on the right) or with the top line (when equation numbers are on the left) of a multi-line derivation.
  • intlimits: Forces integration limits for single and multiple integrals (int, iint, iiint) to appear directly above and below the integral symbol in display mode, overriding the standard side-subscript convention (nointlimits).
  • sumlimits: Enforces limits above and below summation-type operators (sum, prod, coprod) in display equations (enabled by default).
  • namelimits: Positions subscripts directly beneath named operator limits such as lim, max, min, and inf in displayed equations (enabled by default).

An example preamble utilizing custom layout parameters appears as follows:

usepackage[leqno,intlimits,tbtags]{amsmath}

Step-by-step instructions

To implement amsmath in a scientific research paper, execute the following numbered steps. This workflow covers establishing the preamble, writing aligned derivations, splitting long formulas, formatting piecewise functions, and defining custom mathematical operators.

  1. Establish the Document Preamble and Load Packages:

    Open your LaTeX source file (for example, manuscript.tex) in your text editor or TeX IDE. At the top of the file, specify the document class and include amsmath alongside companion symbol packages.

    documentclass[12pt]{article}
    usepackage{amsmath}
    usepackage{amssymb}
    usepackage{amsthm}
    
  2. Typeset Single-Line Numbered and Unnumbered Display Equations:

    To produce a single-line displayed formula with an automatic reference tag, use the equation environment. To suppress the equation number, use the unstarred equation* environment or insert nonumber prior to the line closure.

    begin{equation}
      E = mc^2 label{eq:einstein}
    end{equation}
    
    begin{equation*}
      F = ma
    end{equation*}
    
  3. Format Multi-Line Systems with Aligned Equality Signs:

    When presenting multi-step algebraic reductions or simultaneous equations, use the align environment. Place an ampersand (&) immediately before the alignment anchor (typically the equals sign or inequality symbol), and terminate each line with a double backslash (\). The final line of the environment must not end with a double backslash.

    begin{align}
      nabla times mathbf{E} &= -frac{partial mathbf{B}}{partial t} label{eq:faraday} \
      nabla times mathbf{B} &= mu_0 mathbf{J} + mu_0 varepsilon_0 frac{partial mathbf{E}}{partial t} label{eq:ampere}
    end{align}
    

    To suppress numbering on a specific row while preserving numbers on subsequent rows, append nonumber before the line break. For extensive algebraic proofs, consult our dedicated guide on multiline equation formatting in LaTeX.

  4. Break Extended Equations Using the Split Environment:

    When a single mathematical expression exceeds the text column width, place the split environment inside a parent equation environment. The split structure aligns subordinate rows while assigning exactly one equation number to the entire composite block.

    begin{equation}
    begin{split}
      f(x) &= a_0 + sum_{n=1}^{infty} left( a_n cosfrac{npi x}{L} + b_n sinfrac{npi x}{L} right) \
           &= a_0 + a_1 cosfrac{pi x}{L} + b_1 sinfrac{pi x}{L} + a_2 cosfrac{2pi x}{L} + cdots
    end{split} label{eq:fourier}
    end{equation}
    
  5. Declare Custom Semantic Operators in the Preamble:

    Standard mathematical writing requires operators such as “argmin”, “rank”, or “diag” to appear in upright Roman font with proper horizontal spacing. Never typeset these as math variables using textit or raw text. Declare custom operators in the preamble using DeclareMathOperator (for standard inline operators) or DeclareMathOperator* (for operators that accept subscript limits directly underneath in display mode).

    % In the preamble:
    DeclareMathOperator{rank}{rank}
    DeclareMathOperator*{argmax}{arg,max}
    
    % In the document body:
    begin{equation}
      hat{theta} = argmax_{theta in Theta} mathcal{L}(theta; mathbf{y})
    end{equation}
    
  6. Cross-Reference Equations with Standardized Parentheses:

    Reference labeled equations in your narrative using the eqref macro. Unlike the standard LaTeX ref command, eqref automatically wraps the target counter in parentheses, producing “(1)” instead of “1”.

    As demonstrated in Equation~eqref{eq:einstein} and derived in eqref{eq:fourier}, the energy equivalence holds.
    

Output and how to read it

When compiling a LaTeX manuscript containing amsmath markup, the underlying TeX engine (such as pdfLaTeX, XeLaTeX, or LuaLaTeX) translates the mathematical macros into precise bounding boxes, baseline calculations, and font glyphs. Verifying the visual and structural output ensures compliance with journal submission criteria.

When inspecting the compiled PDF document, authors should verify four visual and structural characteristics:

  • Horizontal Alignment Uniformity: In align and aligned blocks, all specified relational markers (such as =, le, or rightarrow) must align along an identical vertical axis. Check that ampersands are positioned immediately preceding the relation symbol rather than after it, preventing asymmetric white space.
  • Vertical Centering of Equation Numbers: In split and gathered environments under the default centertags setting, confirm that the equation tag sits precisely halfway between the top and bottom lines of the block. If tbtags was enabled, confirm that the tag sits flush with the final line (for right-hand tags) or top line (for left-hand tags).
  • Operator Font Geometry and Kerning: Check that custom operators declared via DeclareMathOperator render in upright Roman type with standardized thin spaces (thinspace) separating them from preceding and succeeding mathematical variables. Verify that limit arguments placed under DeclareMathOperator* shift beneath the operator name in display mode rather than displaying as trailing subscripts.
  • Equation Number Spacing and Margin Constraints: Verify that lengthy mathematical expressions do not overlap the equation tag in the right margin. If an equation approaches the margin, amsmath shifts the equation number downward to a separate line to prevent visual collision. If an overfull horizontal box warning (Overfull hbox) is reported in the compilation log, break the line earlier using split or multline.

The companion dataset below systematically compares the structural characteristics, numbering behaviors, and alignment paradigms of all core display environments provided by amsmath.

Troubleshooting

Because amsmath modifies the low-level math parsing mechanisms of LaTeX, syntax discrepancies that pass undetected in plain text environments trigger explicit compilation errors. The following solutions resolve the most frequent issues encountered in research manuscripts:

  • Package amsmath Error: Erroneous nesting of equation structures:

    Cause: An author placed a top-level display math environment (such as align, gather, or alignat) inside an existing display math block, such as $$...$$, [...], or begin{equation}.

    Fix: Top-level environments manage their own display math mode. Remove the outer equation or [...] wrapper completely. If an aligned multi-line expression is required inside an equation block (for example, to share a single equation number), replace the outer align with the subordinate aligned or split environment.

  • Runaway argument? / Paragraph ended before align* was complete:

    Cause: A blank line (paragraph break) was accidentally inserted inside an amsmath display environment. In LaTeX, display math environments cannot contain empty lines or par tokens.

    Fix: Remove all empty lines inside the environment. If visual code separation is needed for readability, use TeX comment markers (%) on otherwise empty lines.

  • LaTeX Error: Command iint already defined (or iiint):

    Cause: A collision occurred between amsmath and an external symbol package (such as txfonts, pxfonts, wasysym, or esint) that also defines multiple integral symbols.

    Fix: Ensure that usepackage{amsmath} is loaded before any other mathematical font or symbol packages. If using esint for specialized integral signs, load it after amsmath, or pass the nointegrals option to conflicting packages.

  • Misplaced or Missing Alignment Ampersands:

    Cause: Omitting the ampersand (&) on one row of an align environment causes LaTeX to treat the line as unanchored, producing irregular horizontal displacement and unexpected column shifts.

    Fix: Verify that every line in an align block contains exactly the same number of ampersands. For a single column of aligned equations, ensure each line has exactly one ampersand preceding the relation symbol.

  • Incorrect Equation Reference Numbers with label:

    Cause: Placing the label{...} command outside the display environment, or placing it after the double backslash (\) on the final line, attaches the label to the following section counter rather than the equation counter.

    Fix: Always place label{...} inside the environment immediately preceding the \ or immediately before end{...} on the final line.

Free alternatives

While amsmath is the established industry standard for mathematical typesetting in LaTeX, several complementary packages, extensions, and modern alternatives exist across the open-source TeX ecosystem. Researchers can select between lightweight built-in tools, modern extensions that build on top of amsmath, and Unicode-native compilation engines.

The table below summarizes the primary free alternatives and companion extensions available for mathematical typesetting in LaTeX:

Tool or Package Distribution / Maintainer Primary Purpose Key Advantage over Base amsmath Compatibility Notes
mathtools LaTeX Project / Morten Høgholm Direct extension and enhancement overlay for amsmath Provides paired delimiters (DeclarePairedDelimiter), prescript commands, and fine tag adjustments Loads amsmath automatically; fully backward compatible with all amsmath environments
empheq Morten Høgholm / TeX Live Visual emphasis and boxing of multi-line equations Enables color boxing, side-notes, and decorative braces around align and gather blocks Requires amsmath and mathtools; extends standard AMS display syntax
breqn Will Robertson / LaTeX Project Automatic line-breaking of complex displayed formulas Breaks long formulas across multiple lines automatically without manual \ line breaks Experimental; can conflict with complex AMS sub-environments and packages modifying math codes
unicode-math Will Robertson / CTAN Native Unicode OpenType mathematical typesetting Directly accesses thousands of Unicode math symbols using XeLaTeX and LuaLaTeX engines Replaces traditional TeX font encodings; designed for LuaLaTeX and XeLaTeX workflows
Base LaTeX Math LaTeX Base Distribution Minimal built-in mathematical notation Zero package dependencies; built into core TeX format files Lacks align, gather, and cases; eqnarray produces flawed horizontal spacing

For most scientific researchers, the recommended best practice is not to replace amsmath, but rather to load mathtools, which transparently imports amsmath while offering refined delimiter controls and structural extensions.

Frequently asked questions

How do I install or load amsmath in LaTeX?

The amsmath package is included by default in all standard TeX distributions, including TeX Live, MacTeX, and MiKTeX. You do not need to install external files. Simply add usepackage{amsmath} to your document preamble before the begin{document} declaration.

What is the difference between align and aligned in amsmath?

The align environment is a top-level display math environment that creates an independent display equation block and automatically numbers each line. The aligned environment is an inner, subordinate environment designed to be nested inside an existing math block, such as an equation environment or matrix brackets, allowing multiple lines to share a single equation number.

Why should I avoid eqnarray in modern LaTeX?

The legacy eqnarray environment produces excessively wide, inconsistent horizontal spacing around equals signs and relation operators. Furthermore, eqnarray frequently allows equation labels to overlap lengthy mathematical formulas without automatic line shifting, whereas amsmath display environments calculate bounding boxes dynamically to prevent collisions.

How do I suppress equation numbers on specific lines in amsmath?

To suppress the equation number on an individual line within an align or gather environment, insert the nonumber command immediately before the double backslash line break. To suppress equation numbers across the entire environment, use the starred variant, such as align* or gather*.

How can I define a custom operator like argmax or trace in amsmath?

Add DeclareMathOperator{operatorname_name}{text} to your preamble, such as DeclareMathOperator{argmax}{arg,max} or DeclareMathOperator{tr}{tr}. This ensures the operator typesets in upright Roman font with correct thin mathematical kerning matching standard functions like sin and log.

Can amsmath handle piecewise functions and conditional brackets?

Yes. The amsmath package provides the cases environment, which automatically renders an appropriately sized left curly brace and establishes a two-column layout for mathematical definitions and their corresponding conditions or constraints.

Sources

  • American Mathematical Society and The LaTeX Project. User’s Guide for the amsmath Package (Version 2.1). Comprehensive TeX Archive Network (CTAN). https://ctan.org/pkg/amsmath (accessed 2026-11-16).
  • Downes, Michael, and Barbara Beeton. Short Math Guide for LaTeX (Version 2.0). American Mathematical Society and CTAN. https://ctan.org/pkg/short-math-guide (accessed 2026-11-16).
  • The LaTeX Project Team. amsmath: AMS Mathematical Facilities for LaTeX. CTAN Package Catalogue. https://ctan.org/pkg/amsmath (accessed 2026-11-16).
  • American Mathematical Society. AMS Author Resource Center: AMS-LaTeX Technology and Guidelines. https://www.ams.org/publications/authors/tex/amslatex (accessed 2026-11-16).
  • Overleaf. Aligning Equations with amsmath. Overleaf Documentation. https://www.overleaf.com/learn/latex/Aligning_equations_with_amsmath (accessed 2026-11-16).

Data: amsmath Display Environments: Alignment, Numbering, and Syntax Structure

Comparative specifications of display math environments provided by the LaTeX amsmath package, compiled from the AMS User's Guide (amsldoc) and the Short Math Guide for LaTeX.

amsmath Display Environments: Alignment, Numbering, and Syntax Structure
Environment NameScope TypeDefault NumberingUnnumbered Star VariantAlignment SyntaxPrimary Scientific Use Case
equationTop-level displaySingle number centeredYes (equation*)No alignment point (single centered line)Single-line standalone formulas and mathematical definitions
alignTop-level displayNumbered per rowYes (align*)Single ampersand (&) per row at relation symbolMulti-step mathematical proofs and derivations with aligned equality signs
gatherTop-level displayNumbered per rowYes (gather*)No alignment point (each line centered independently)Consecutive related equations requiring no common horizontal anchor
multlineTop-level displaySingle number on final lineYes (multline*)First line left-aligned, middle centered, last right-alignedSingle formulas exceeding text column width that require multi-line breaking
flalignTop-level displayNumbered per rowYes (flalign*)Ampersands expand to fill full margin-to-margin widthParallel equation pairs stretched across the full width of the text column
alignatTop-level displayNumbered per rowYes (alignat*)Requires explicit argument specifying number of alignment pairsMulti-column equation blocks with precise control over horizontal inter-column gaps
splitSubordinate (inner)Inherits parent equation numberNo (controlled by parent)Single ampersand (&) per row at relation symbolBreaking long expressions across lines within an equation or gather block
alignedSubordinate (inner)Inherits parent equation numberNo (controlled by parent)Single ampersand (&) per row at relation symbolMulti-line aligned blocks nested inside matrices, equations, or cases
gatheredSubordinate (inner)Inherits parent equation numberNo (controlled by parent)No alignment point (each line centered independently)Centered multi-line blocks nested within larger compound formulas or brackets
casesSubordinate (inner)Inherits parent equation numberNo (controlled by parent)Two columns separated by single ampersand (&)Piecewise functions, boundary values, and conditional mathematical definitions

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about LaTeX amsmath Guide: Setup, Environments and Syntax

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →