How to write fractions and superscripts in LaTeX: Detailed explanation of frac usage
Explain clearly how to write \frac fractions in LaTeX, as well as the rules for superscript and subscript ^ and _, including how to type the upper left corner subscript. Provides compilation steps and troubleshooting methods for common errors, suitable for readers who need basic scores and indices.
Key points of this article
- Fractions are written using \frac{numerator}{denominator}. Both the numerator and the denominator must be placed in curly braces. If one is missing, a typographical error will occur.
- Use ^ for superscript and _ for subscript. If there is more than one character, curly braces must be added, otherwise only the first character will enter the superscript or subscript.
- The upper left corner subscript needs to first place an empty {} as the base, and then write the superscript and subscript in sequence. It cannot be written directly in front of the symbol.
- If the fraction within a line appears small, you can use \dfrac instead; for a formula on a separate line, \frac can usually be used directly.
- After compilation, check the curly braces, superscript and subscript ranges, and fraction line sizes one by one. When reporting an error, first look at the content near the error line number.
If you are writing a paper, lecture notes or exercises, and type fractions, squares or subscripts in LaTeX for the first time, you will probably be stuck by a few rules: \frac requires two sets of curly braces. When the superscript is a series of numbers, only the first one is included in the superscript, and you don’t know where to put the upper left corner annotation like the atomic number. These problems are very common, but official documents are scattered, and the fragments found often only give one line of code, without clearly explaining why it is written this way.
This article only talks about three things: how to write fractions using \frac, how to write superscripts and subscripts using ^ and _, and how to deal with the situation where the upper left corner subscript is written in front of the symbol. After reading this, you should be able to independently write formulas with fractions and exponents, and know where to look when compiling errors. The examples in this article can all be reproduced in a standard LaTeX environment.
If your formula needs to be edited or converted to Word, or the entire LaTeX source code needs to be translated, the end of the article will briefly explain how OmniDoc related functions can help.
How to enter the score? Use \frac to conclude in one sentence
To enter fractions in LaTeX, use \frac{numerator}{denominator}, with both arguments enclosed in curly braces. Whether you need to replace it with \dfrac or \tfrac depends on whether the formula is sandwiched in the middle of a sentence or on its own line.
| your situation | Recommended practices | reason |
|---|---|---|
| Simple fractions, such as one-half | \frac{1}{2} | Directly, the two curly brackets hold the numerator and denominator respectively. |
| Sandwiched in the middle of the sentence, the fraction seems too small | \dfrac{a}{b} (requires amsmath package) | Inline fractions are reduced by default, \dfrac forces a larger display style |
| Formulas on separate lines | \frac{a}{b} can | Fractions in independent formulas default to normal size |
| There are scores within scores | Add curly braces at each level, such as \frac{\frac{a}{b}}{c} | When the nesting level is not enclosed in curly braces, the typesetting results are easily misaligned. |
Before you start: Confirm these points first
There are several judgments before taking action that will directly affect the results. Spending a few minutes to confirm can save a lot of troubleshooting time.
- Confirm whether the amsmath macro package is required. \frac is a core command of LaTeX and can be used directly; however, \dfrac and \tfrac belong to the amsmath macro package and can only be used after adding \usepackage{amsmath} in the preamble.
- Confirm formula environment. Inline formulas are wrapped with a pair of dollar signs, and formulas on a separate line are often wrapped with \[ and \]. Different environments have different default sizes for fractions and subscripts, so the same formula may look different in the two environments.
- Confirm compilation method. The formula itself has little to do with the compiler, but if there is Chinese in the document, you need to use a compilation method that supports Chinese, such as XeLaTeX or LuaLaTeX, otherwise the Chinese may not be displayed properly.
- Confirm formula source. When you copy formulas from a web page or someone else's document, backslashes, braces, and superscript symbols may be lost or distorted. If the result is wrong, first compare it character by character with the original source code.
- Confirm output usage. If the result is only for reading, just view the PDF directly; if you want to change it to Word format to continue editing, complex formulas need to be rechecked after conversion.
Steps to write fractions and superscripts in LaTeX
The following steps take a simple .tex file as an example. The goal is to write a formula with fractions, squares, and sums.
- Create a new .tex file, write \documentclass{article} in the introduction area, and add \usepackage{amsmath}.
- Write the main text between \begin{document} and \end{document}, and wrap the place where inline formulas need to be inserted with a pair of dollar signs, such as $x^{2}$.
- Formulas on separate lines are wrapped with \[ and \], such as \[ \frac{a+b}{2} \].
- Use ^ for superscript and _ for subscript. The curly braces can be omitted when there is only one character, such as x^2; curly braces must be added when there is more than one character, such as x^{10}.
- Write a summation formula as an exercise: \[ \sum_{i=1}^{n} \frac{1}{i^{2}} \]. The upper and lower limits of \sum are written using ^ and _ respectively.
- Compile once with your LaTeX environment, then open the resulting PDF and check that fractions, exponents, and subscripts are all where expected.
- If the formula needs to be modified later or needs to be converted to Word format, the formula content in .tex can be brought to the UniDoc web editor for processing. It supports formula editing and can convert back and forth between Word and LaTeX. The formulas also need to be checked after conversion.
How to type the upper left corner mark: first write an empty curly brace
The upper left corner refers to the number written in the upper left corner of a symbol, such as the notation for atomic mass number and atomic number. The difficulty is that ^ and _ act on the symbol before it by default, and nothing in front of the upper left corner subscript can act on it.
The solution is to put an empty {} as the base, and then write superscript and subscript in sequence. For example, to format a top-left subscript like Carbon 14, you would write {}^{14}_{6}\mathrm{C}, where 14 is above, 6 is below, and C is the element symbol. If you only need one number in the upper left corner and no subscript is needed, write it as {}^{14}\mathrm{C}.
Don't just write ^14C. This way only the 1 will go into the superscript, the 4 will follow directly after the sign, and the result is not as expected.
Check each item after completion
Just because the formula is compiled, it does not mean that the formatting is correct. After you get the PDF, you can check it item by item according to the table below.
| Inspection items | How to see it | What should you do if there's a problem? |
|---|---|---|
| Are the curly brackets paired? | Compilation error shows Missing } or Extra } | Count the numerator, denominator, and superscript in braces one by one, and find the one that is extra or missing |
| Scope of superscript and subscript | Check whether the index or subscript is all in the correct position | For superscripts or subscripts exceeding one character, curly brackets are added |
| Score line size | Whether the in-line score is clearly too low is hard to identify | Switch to \dfrac, and confirm that the amsmath macropackage has been loaded |
| Marked in the upper left corner | Whether the number appears in the upper left corner of the symbol | Add a blank {} before the symbol, then write the superscript and subscript |
| Command spelling | Whether the score has become FRAC text and has no score line | Add a backslash, write it as \frac, and pay attention to case sensitivity |
When compiling errors, first check the line numbers in the error prompt, then check whether the curly brackets on this and previous lines are complete. Most problems lie in curly braces and backslashes, where character comparison is faster than repeated rewriting.
❓ Frequently Asked Questions (FAQ)
1. Why does x^10 only have 1 in the superscript?
Superscript command ^ By default, it only applies to the first character immediately following it, so 1 enters the superscript and 0 becomes a regular text. If you write the exponent as x^{10}, the curly brackets treat 10 as a whole and put it into the superscript.
2. What is the difference between \frac and \dfrac?
The numerator and denominator of both have the same content, with the difference being the font size. \frac automatically selects size based on the environment and may be smaller within the line; \dfrac always uses the normal-sized fraction style, suitable for fractions sandwiched between sentences but requiring clear reading. Before using \dfrac, you need to load the amsmath macropackage in the introductory area.
3. Is there a requirement for the order of superscript and subscript?
No demands. x_i^2 yields the same result as x^2_i, with the superscript and subscript aligned vertically to the right of the symbol. As long as both are written after the same symbol, the order can be determined according to personal preference.
4. What should I do if the compilation prompt says Missing } inserted?
This indicates that curly braces are not closed at certain points, and most are found in the numerator, denominator, or superscript of the fraction. Starting from the error line number, count each pair of { and } to see if they are paired, paying special attention to the outer curly brackets of nested fractions.
📝 Summary
How to input fractions in LaTeX: The core is to use \frac{numerator}{denominator}, with ^, _, and braces when more than one character is used. In the upper left corner, you need to first place an empty {} as the base. After compiling it, check each item one by one. When errors occur, start by starting with the line numbers that cause errors, so you can quickly arrange the formulas correctly.
Open OmniDoc to edit, convert, or translate your LaTeX documents


