How to set LaTeX formula numbers and theorem references

Explain the common writing methods of formula numbering in LaTeX, the numbering processing of multi-line formulas, and how theorems and definitions can be referenced by the text and other theorems using tags, and provide the verification method after compilation.

Key points of this article

  • A single formula that needs to be numbered is put into the equation environment and labeled. The text is quoted with eqref, and the result is automatically bracketed, such as (3).
  • When the theorem and definition share a counter, the definition environment must be written in the form of a reference to the theorem counter, so that the numbering will be continuous.
  • The label must be written inside the corresponding environment. When placed outside the environment, the reference will point to the previous number.
  • A question mark is displayed at the reference point, usually because it is not compiled twice or the label name is misspelled. Please check these two points before processing.

When writing papers or lecture notes, many people allow the formulas to be automatically numbered, but handwrite "see equation (3)" in the text. Once a formula is added or deleted, all the numbers will be misaligned and can only be changed one by one. The citation of theorems, lemmas, and definitions has the same problem. Handwritten numbers are difficult to maintain and can easily conflict with journal templates.

This article is written for people who can already write basic LaTeX, but have not yet mastered numbering and cross-referencing. After reading, you will be able to distinguish several ways of writing formula numbers, know how to number only the required lines in multi-line derivation, follow the steps to ensure that theorems and definitions are correctly cited in the text, and check the results after compilation.

LaTeX's numbering and citation rely on the "tag" mechanism: the object is given a name, cited by name in the text, and the number is automatically generated by the compiler. The following content is all centered around this mechanism.

# how to set formula number and theorem reference? Conclusion in a word

Use tags to add cross-reference commands: formulas are quoted with eqref, theorems and definitions are quoted with ref (when you need to include the word "theorem", use the cref of the cleveref macro package), all numbers are automatically generated by LaTeX, no handwritten numbers are required.

your situationRecommended practiceReason
A single independent formula needs to be numberedPut it in the equation environment and tag it, and use eqref in the textThe number is generated automatically and quoted with parentheses automatically.
Multi-line derivation, each line or only part of the line to be numberedIn an align environment, the lines that need to be numbered are tagged, and the rest are tagged with notagThe number follows, and line deletion does not affect other numbers.
Paper requirements (2.1) this category is numbered by chapterUse numberwithin to set the formula to count by section in the introduction areaThe counter is reset with the chapter and the format is uniform.
Theorems and definitions should be quoted elsewhere.Add tags in the environment and use ref; when the text requires the word "Theorem 2.1". Use cref.Ref only gives the number, and cref will automatically add the category name.

# before you start: confirm these points first

- the introduction area loads amsmath and amsthm. eqref and align depend on amsmath, and the theorem environment depends on amsthm. In the absence of them, the command will report an error, or the number does not meet expectations. - first check whether the template has defined the theorem environment. periodicals and dissertation templates usually come with theorem, definition and other environments. If you repeat the definition, you will report an error. You should directly use the name already in the template. - uniform label prefix. it is suggested that the formula be defined by eq:, Theorem, defined by thm:, defined by def:, Lemma and used by lem:. Label signatures are case-sensitive, cannot be repeated in the same document, and prefixes can significantly reduce conflicts. - determine the number range in advance. papers are generally required to be numbered according to chapters, and handouts are often numbered successively. This choice should be determined before the first formula is written, and the midway change will cause all references to be rechecked. - if the original is a LaTeX source package, it will be compiled locally. only if the source file can be compiled properly can you determine whether the tag corresponds to the number. If you use OmniDoc to translate the LaTeX source code package, you should also check the formula number and citation against the original text after translation, not just whether the translation is smooth or not.

# steps to number and quote a formula in LaTeX

  1. Load the amsmath macro package in the introductory area. If you need to click on the reference jump, then load hyperref and try to put it after other macro packages.
  2. Use the equation environment to write formulas that require numbering. After compilation, the number will be automatically displayed on the right side of the formula.
  3. Write the label command inside the equation environment, after the formula, for example, the label name eq:energy. The label must be within the environment. Writing outside the environment will refer to the previous number.
  4. Write eqref at the location that needs to be quoted in the text, for example, in the form of "can be obtained from the formula \eqref{eq:energy}". Parentheses are automatically generated, no need to add them manually.
  5. Use the align environment for multi-line derivation, and wrap each line with double backslashes. Only add labels to lines that need to be quoted, and notag to lines that do not need to be numbered.
  6. If you want to number by section, set the formula counter in the introductory area to reset with the section. After setting, the formula number will change into the form of "chapter number.serial number".
  7. Compile twice in succession. Record the label position for the first time, and write the number into the reference for the second time.

# numbering and quoting steps for Theorems and Definitions

  1. Use newtheorem to define the theorem environment in the introduction area, such as the environment name theorem and the display name Theorem.

two. When defining the definition environment, let it share counters with the theorem: the environment name is followed by square brackets, theorem is written inside, and the name Definition is displayed. In this way, the definition and the determinant will not be numbered successively and will not start with 1 respectively.

  1. If you want the theorem to be numbered by chapter, write section in square brackets at the end of the newtheorem. This method of writing should be put in the introduction area and should not be modified in the text.
  2. After the begin command in the theorem environment, write the label, such as thm:main. The number is accurate only when the label is placed before the first line of the text.
  3. Use ref references in the text, such as writing "knowable by theorem\ ref {thm:main}", outputting numbers such as "Theorem 2.1".
  4. If you want the output to be automatically marked with the words "Theorem" or "theorem", load the cleveref macro package and place it after hyperref, and then replace ref with cref.
  5. Refer to the theorem in the definition and write it in the same way as the text: write ref and corresponding tags in the definition environment. If you encounter a forward reference defined before the theorem, you also need to compile twice.

# check item by item after completion

When the compilation is complete, open PDF to check the following items one by one.

Check itemWhat do you think?What if there's a problem?
Does the reference show a question mark?Check the number in the text in PDFCompile twice in a row; check the spelling of the label signature if there is still a question mark
Whether the reference corresponds to the cited objectClick the quote to jump (need hyperref), or turn to the corresponding page to checkCheck whether the label is written inside the corresponding environment
Whether the label is duplicatedView multiply defined warnings in the compilation logChange the name of one of the tags
Theorem and whether the numbers are continuous or notThe numbering order of the environment of visual theoremCheck whether the definition environment references theorem counters
Whether the number of the multi-line formula is excessive or missingView the right number of the align environment line by lineAdd notag to the lines that do not need to be numbered, and label the rows that are needed
Whether references are synchronized after adding or deleting contentRecompile after modification, and check the reference againCompile twice in a row to confirm that the question mark disappears

# Core comparison

Writing methodNumbering situationSuitable for the scene
Equation environmentThe whole formula has a number.A single formula that needs to be quoted
Align environmentEach line can be numbered separately.Multi-line derivation, with only a few lines referenced
equation* or \[ \]No number.Display formulas that do not need to be quoted
Use the tag command in a formulaThe numbered content is specified by yourself.Special marks are required, such as asterisks or appendix numbers

# frequently asked questions (FAQ)

1. The citation shows a question mark. What went wrong?

In most cases, it is not compiled twice in a row, and the first compilation of LaTeX only records the location of the tag, and the second time the number is written to the reference. If there is still a question mark after compiling twice, check that the label signature is spelled the same, and make sure that the label is written inside the corresponding environment.

2. How to change the number format of LaTeX formula to (2.1)?

Set the formula counter in the introduction area to reset with section, and the number will become a chapter number. The form of the serial number. Note that this setting should be completed before the start of the document, and it is easy to change the text halfway so that the numbering is inconsistent.

3. Can I quote the formula without parentheses?

Sure. Eqref automatically adds parentheses, and if you only want the number itself, you can use ref instead. Both rely on the same tag, but the format of the output is different.

4. Quote the theorem in the definition, is there any difference between the writing method and the text?

No difference. Write ref and theorem tags directly in the definition environment. If the definition and the theorem refer to each other, you also have to compile twice to make the number stable.

5. After translating LaTeX source code package with OmniDoc, can the formula number still be used directly?

The translated file needs to be recompiled and check the formula number, label reference and theorem sequence number against the original text. Translation only deals with the text, and it still depends on the compilation results and manual check to determine whether the number is correct or not.

# Summary

The core of the formula number and theorem reference of LaTeX is to label the object, call it with the reference command, and give the number to the compiler for maintenance. According to the steps of this article, set the counter and label prefix, compile twice and then check item by item, you can avoid the dislocation problem caused by handwritten numbers.

Open OmniDoc to edit, convert or translate your LaTeX document

Updated 2026-11-11