How to label equations in Latex?

  • LaTeX
  • Thread starter epenguin
  • Start date
  • Tags
    Latex
In summary: If your post falls on page 2, then the equation numbering will start at 2. If your post falls on page 3, then the equation numbering will start at 3. In summary, the equation numbering starts at 1, increments by 1 for each new {equation} field, and resets to 1 when the document is closed.
  • #1
epenguin
Homework Helper
Gold Member
3,636
1,010
I just want to label equations in a post I could make in the next hours if I knew.
Done 'by hand' it is always ugly.
I don't want anything fancy, stuff on the web is too fancy and useful for people writing books, I just want to put numbers on a handful of equations I don't need to give them names or anything like that

xyzabc ... (1)
uvwnmo ...(2)

and not spoil the look of it, with a minimum of effort..

I will like the one that works easy. :oldsmile:
 
Physics news on Phys.org
  • #2
The AMS-LaTex package automatically numbers equations. It looks like these web pages do too.
See https://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics#Equation_numbering
Using this code:
Fortran:
\begin{equation}
f(x)=(x+a)(x+b)
\end{equation}
Gives:
\begin{equation}
f(x)=(x+a)(x+b)
\end{equation}

NOTE 1: When I started this post, the equation number started at 1. Each edit incremented it.
NOTE 2: I had to display the LaTex code as Fortran to keep the code from being parsed by LaTex.
 
Last edited:
  • Like
Likes epenguin
  • #3
Thank you. That seems to be giving a good result so far except that ithappens exactly as in your note 1. My first equation is now (4). This will increase as I go along so there is no point in correcting it now, but when I have finished will I be able to reset the first equation as (1) and how?

Not too appears above my head and needs, I am just using mostly the PF latex primer which however doesn't have instructions for equation numbering.
 
  • #4
I left the page and have come back. Now the equation number is 1. I bet that it resets that way. If you saw my post as equation 1, then that is what we want.

I just tested it. If you close the tab and come back, the numbering starts at 1. So that unwanted incrementing is only during the edit.
 
  • #5
We can use \tag <nr> to add fixed tags:
$$f(x)=x+a \tag 1$$
 
  • Like
Likes epenguin and FactChecker
  • #6
I like Serena said:
We can use \tag <nr> to add fixed tags:
$$f(x)=x+a \tag 1$$
Although auto-numbering is sometimes nice, these tags would be especially preferred if you only want to number the important equations. I think that would be most of the time.
 
  • #7
Thank you FactChecker and Serena. I have now used FactChecker's suggestion and it has worked well. https://www.physicsforums.com/threa...ule-of-derivatives.924400/page-3#post-5837451 For my average post on here with a handful of equations the method given by Serena will no doubt be better, but for writing more complex work that of FactChecker would surely save a lot of work changing every number every time you changed a manuscript a little.

Serena's didn't actually work for me on a quick try but I wondered if her < >are the same as the inequalities signs on my keyboard, well they are looking the same; I will come back to this another day
 
  • #8
Try
\tag{5}
 
  • Like
Likes epenguin
  • #9
Sorry for that. I didn't intend for the angle brackets to be taken literally.
The code is:
Code:
f(x)=x+a \tag 1
f(x)=2x \tag{10}
$$f(x)=x+a \tag 1$$
$$f(x)=2x \tag{10}$$
And we need braces if the number is more than 1 digit, as @FactChecker suggested.
 
  • Like
Likes FactChecker and epenguin
  • #10
FactChecker said:
Although auto-numbering is sometimes nice, these tags would be especially preferred if you only want to number the important equations. I think that would be most of the time.

There's an essay (What's wrong with these equations?) by David Mermin about writing prose with equations embedded in it. One of the recommendations is to always number displayed equations. The reason is that equation numbers are there for anyone to refer to and not just you the author. You might know what equations you want to refer to but you don't know in advance what equations your readers (or referees) might want to refer to from your text. (Admittedly this is less of an issue for forum posts than research papers, since you can simply quote the parts of posts you want to refer to directly, but I still see lots of papers and project notes that don't consistently number equations.)
 
  • #11
I don't think that I would number intermediate equations as a rule. Scanning through books by some mathematicians that I admire, I see that there is some variation, even with the same book. In general, there are more numbered equations than I would have expected. Certainly the large majority are numbered.

I see that there is a LaTex \nonumber option to suppress numbers on certain equations.
 
Last edited:
  • #12
FactChecker said:
The AMS-LaTex package automatically numbers equations. It looks like these web pages do too.
See https://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics#Equation_numbering
Using this code:
Fortran:
\begin{equation}
f(x)=(x+a)(x+b)
\end{equation}

Gives:
\begin{equation}
f(x)=(x+a)(x+b)
\end{equation}

NOTE 1: When I started this post, the equation number started at 1. Each edit incremented it.
NOTE 2: I had to display the LaTex code as Fortran to keep the code from being parsed by LaTex.
The {equation} fields works for the entire document - i.e. this web page - such that its first use will be 1. Each added {equation} field will add 1 to the numbering, even if it is not in the same post. If your post falls on page 2, the numbering will reset to 1 (page 2 is a new HTML document).

You should note that in my quote, @FactChecker 's equation now have ##(2)## as the number and when I repeat it in my post, it increases to ##(3)##:
$$\begin{equation}
f(x)=(x+a)(x+b)
\end{equation}$$
Since the preview is part of this document, it also adds + 1 to the number the first time. I'm not sure why it adds one more every time you hit preview, but it has to do with how the DOM of the document is manipulated.
 
Last edited:
  • Like
Likes FactChecker

Related to How to label equations in Latex?

1. How do I label an equation in Latex?

To label an equation in Latex, you can use the command "\label{label_name}" after the equation. This will assign a label to the equation, which can then be referenced using the command "\ref{label_name}".

2. Can I use a custom label for my equations?

Yes, you can use any label name as long as it is unique within the document. It is recommended to use a descriptive label name to make it easier to reference the equation later on.

3. How do I reference an equation in my text?

To reference an equation in your text, use the command "\ref{label_name}". This will insert the number of the equation that matches the label you specified.

4. Is there a way to number equations automatically?

Yes, equations can be numbered automatically by using the "equation" environment. This will automatically assign a number to each equation and you can still use the "\label" and "\ref" commands to reference them.

5. Can I change the format of the equation numbers?

Yes, you can change the format of the equation numbers by using the "\tag" command. This will allow you to add a custom label or change the numbering style for a specific equation.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Feedback and Announcements
Replies
11
Views
355
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
353
Back
Top