Think of each LaTeX notation command as a building block. A fraction is one block. A square root is another. A subscript, an accent, a pair of auto-sized delimiters — each is its own self-contained block. Individually, they are straightforward. The interesting part is snapping them together.
The key insight is that almost every LaTeX math command accepts an argument in braces, and that argument can itself contain other commands. For example, \sqrt{} expects content between its braces, and that content can be a \frac{}{}, which in turn can contain subscripts or accents. This nesting ability is what lets you build expressions of any complexity. The only requirement is that every opening brace has a matching closing brace and that you keep track of which block you are currently inside.
Working from the Inside Out
Layering Two Features on One Symbol
Building Multi-Layer Expressions
Brace Grouping: The One Rule That Matters Most
The Quadratic Formula from Scratch
Tips for Staying Organized
As expressions grow, keeping your LaTeX source readable becomes just as important as getting the output right. Here are a few habits that help:
Build incrementally. Compile after adding each new layer. Catching a missing brace early is much easier than hunting through a finished expression.
Read braces in pairs. When something looks wrong, count your opening and closing braces. Every { must have exactly one matching }.
Use whitespace freely. LaTeX ignores extra spaces in math mode, so spreading a long expression across multiple lines in your source does not affect the rendered output — but it makes the code much easier for you to read.
These small practices save a surprising amount of debugging time, especially when you are translating a verbal or handwritten formula into LaTeX for the first time. If someone describes an expression in plain English, sketch the nesting structure mentally before typing, then build each layer one at a time.
Conclusion and Next Steps
In this lesson, you learned how to combine subscripts, superscripts, fractions, roots, accents, and auto-sized delimiters into layered compound expressions. The core strategy is to build from the inside out, wrapping each new notation layer around the previous one and always using braces to keep grouping unambiguous.
Up next, you will put these skills to work in hands-on practice. You will layer fractions inside roots with subscripted variables, reconstruct the quadratic formula from scratch, and translate a plain-English description of a complex expression into fully structured LaTeX — proving to yourself that you can build any formula one layer at a time.
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal
Welcome back to Advanced Math Notation! You are now halfway through this six-lesson course. In the first two lessons, you added math accents like a^ and v to your toolkit, then learned how \left and \right scale delimiters to fit tall content. And in the previous course, Writing Math in LaTeX, you worked through fractions, roots, subscripts, superscripts, Greek letters, and common symbols.
Each of those features is powerful on its own, but real mathematics rarely uses just one at a time. A single expression might nest a fraction inside a square root, attach subscripts to the variables, and place an accent on top — all at once. This lesson is about learning to layer multiple notation elements into a single, well-structured expression using correct brace grouping and a clear nesting order.
When faced with a complex expression, the most reliable strategy is to build from the innermost piece outward. Trying to write the entire expression in one pass often leads to mismatched braces or misplaced commands. Starting with the deepest nested element and wrapping each successive layer around it keeps things manageable.
Let's say we want to produce the square root of a fraction with x1 in the numerator and x2 in the denominator. We can build it in three small steps:
Innermost elements first — write the subscripted variables: x_1 and x_2.
Wrap the next layer — place them into a fraction: \frac{x_1}{x_2}.
Wrap the outer layer — put the fraction inside a square root: \sqrt{\frac{x_1}{x_2}}.
The final code and its output:
latex
\sqrt{\frac{x_1}{x_2}}
x2x1
Each step is small and easy to verify on its own. If something looks wrong after adding a layer, you know exactly which layer introduced the problem.
Before tackling large expressions, let's practice combining two notation features on a single symbol. This comes up constantly — a variable that needs both an accent and a subscript, or a subscript and a superscript together.
Accent plus subscript. Accents like \hat apply to the very next token. To write "hat-a sub n," place the accent first and then attach the subscript:
latex
\hat{a}_n
This gives a^n. The accent sits on a, and the subscript n sits at the lower right. If you wanted the accent to span both the letter and its subscript, you would group them: \widehat{a_n}, producing an.
Subscript plus superscript. Attaching both to the same base is simply a matter of placing them one after the other:
latex
x_i^2
This produces xi2. Writing x^2_i gives the same result, but subscript-first is a common convention that many find easier to read in source code. You can even stack all three — accent, subscript, and superscript — on one symbol. For instance, \hat{a}_n^2 renders as a^n2, and every piece lands in its expected position.
Now let's combine more than two elements. Consider the expression "hat-a sub n, squared, inside a fraction, all wrapped in auto-sized parentheses." We build it step by step:
Start with the accented, subscripted, superscripted symbol: \hat{a}_n^2.
Place it as the numerator of a fraction: \frac{\hat{a}_n^2}{b}.
Wrap the fraction in auto-sized parentheses: \left( \frac{\hat{a}_n^2}{b} \right).
latex
\left( \frac{\hat{a}_n^2}{b} \right)
(ba^n2)
Each layer simply wraps around the previous result. The braces define clear boundaries, and \left/\right handle the sizing automatically. This same approach extends to any depth — you could place the entire parenthesized fraction inside a cube root using \sqrt[3]{...}, and LaTeX would render every layer correctly, as long as every brace is matched.
Every nesting issue in LaTeX math ultimately comes down to brace grouping. When a command like \sqrt, \frac, or \hat reads its argument, it grabs either the single next character or the entire group enclosed in { }. Forgetting braces changes the meaning dramatically.
Code
Output
What happened
\sqrt{x_1}
x1
Root covers x1 — correct
\sqrt x_1
x1
Root covers only x; subscript 1 attaches outside
x^{10}
x10
Superscript is the group 10 — correct
x^10
x10
Superscript is only 1; the 0 falls to the baseline
The rule is simple: whenever more than one character belongs to a command's argument, wrap it in braces. When in doubt, adding braces never hurts. Writing \sqrt{x} is just as valid as \sqrt x, but the braced version is always unambiguous.
Let's put everything together with a formula most of us remember from algebra class. The quadratic formula combines a fraction, a square root, a superscript, and the ± symbol — all in one expression. Building it from the inside out:
Discriminant inside the root:\sqrt{b^2 - 4ac}.
Full numerator:-b \pm \sqrt{b^2 - 4ac}.
Fraction with denominator:\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.
The final code:
latex
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
x=2a−b±b2−4ac
Every notation element we have studied plays a role: the superscript in b2, the square root wrapping part of the numerator, and the fraction organizing the entire expression. Notice that because \frac produces tall output, a display-math environment (double dollar signs) is the natural choice here. The inline version x=2a−b±b2−4ac would look cramped inside running text — a good reminder that complex layered expressions almost always belong in display mode.