How to use lineno with amsmath align?
up vote
4
down vote
favorite
Is there a way to have lineno
show line numbers for a paragraph that uses the align
environment?
In the following example, the (first) paragraph that ends with begin{align} ... end{align}
does not have the desired line numbers, whereas the (second) paragraph that separates the text with a single new line contains the line numbers.
documentclass{article}
usepackage{amsmath}
usepackage[mathlines]{lineno}
usepackage{lipsum}
linenumbers
title{My Document}
author{Anonymous Anteater}
begin{document}
maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{align}
x = 2
end{align}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
begin{align}
x = 2
end{align}
end{document}
align amsmath line-numbering lineno
add a comment |
up vote
4
down vote
favorite
Is there a way to have lineno
show line numbers for a paragraph that uses the align
environment?
In the following example, the (first) paragraph that ends with begin{align} ... end{align}
does not have the desired line numbers, whereas the (second) paragraph that separates the text with a single new line contains the line numbers.
documentclass{article}
usepackage{amsmath}
usepackage[mathlines]{lineno}
usepackage{lipsum}
linenumbers
title{My Document}
author{Anonymous Anteater}
begin{document}
maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{align}
x = 2
end{align}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
begin{align}
x = 2
end{align}
end{document}
align amsmath line-numbering lineno
1
Related/duplicate: Why doesn'tlineno
number a paragraph when it is followed by analign
equation environment without a space?
– Werner
Nov 21 at 20:20
@Werner apologies for the duplicate, shall I close my question?
– jesterII
Nov 21 at 20:39
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Is there a way to have lineno
show line numbers for a paragraph that uses the align
environment?
In the following example, the (first) paragraph that ends with begin{align} ... end{align}
does not have the desired line numbers, whereas the (second) paragraph that separates the text with a single new line contains the line numbers.
documentclass{article}
usepackage{amsmath}
usepackage[mathlines]{lineno}
usepackage{lipsum}
linenumbers
title{My Document}
author{Anonymous Anteater}
begin{document}
maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{align}
x = 2
end{align}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
begin{align}
x = 2
end{align}
end{document}
align amsmath line-numbering lineno
Is there a way to have lineno
show line numbers for a paragraph that uses the align
environment?
In the following example, the (first) paragraph that ends with begin{align} ... end{align}
does not have the desired line numbers, whereas the (second) paragraph that separates the text with a single new line contains the line numbers.
documentclass{article}
usepackage{amsmath}
usepackage[mathlines]{lineno}
usepackage{lipsum}
linenumbers
title{My Document}
author{Anonymous Anteater}
begin{document}
maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{align}
x = 2
end{align}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
begin{align}
x = 2
end{align}
end{document}
align amsmath line-numbering lineno
align amsmath line-numbering lineno
asked Nov 21 at 19:45
jesterII
1603
1603
1
Related/duplicate: Why doesn'tlineno
number a paragraph when it is followed by analign
equation environment without a space?
– Werner
Nov 21 at 20:20
@Werner apologies for the duplicate, shall I close my question?
– jesterII
Nov 21 at 20:39
add a comment |
1
Related/duplicate: Why doesn'tlineno
number a paragraph when it is followed by analign
equation environment without a space?
– Werner
Nov 21 at 20:20
@Werner apologies for the duplicate, shall I close my question?
– jesterII
Nov 21 at 20:39
1
1
Related/duplicate: Why doesn't
lineno
number a paragraph when it is followed by an align
equation environment without a space?– Werner
Nov 21 at 20:20
Related/duplicate: Why doesn't
lineno
number a paragraph when it is followed by an align
equation environment without a space?– Werner
Nov 21 at 20:20
@Werner apologies for the duplicate, shall I close my question?
– jesterII
Nov 21 at 20:39
@Werner apologies for the duplicate, shall I close my question?
– jesterII
Nov 21 at 20:39
add a comment |
2 Answers
2
active
oldest
votes
up vote
5
down vote
accepted
The lineno
package is not compatible with the amsmath
environments, but the two can be made to work together.
Here is (a slightly updated version of) the patch for the amsmath
environments that I wrote for it as an answer to this question.
documentclass{article}
usepackage{amsmath}
usepackage[mathlines]{lineno}
usepackage{etoolbox} %% <- for pretocmd, apptocmd and patchcmd
%% Patch 'normal' math environment: (currently unused, but good to have)
% newcommand*linenomathpatch[1]{%
% expandafterpretocmdcsname #1endcsname {linenomath}{}{}%
% expandafterpretocmdcsname #1*endcsname{linenomath}{}{}%
% expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
% expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
% }
%% Patch AMS math environment:
newcommand*linenomathpatchAMS[1]{%
expandafterpretocmdcsname #1endcsname {linenomathAMS}{}{}%
expandafterpretocmdcsname #1*endcsname{linenomathAMS}{}{}%
expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
}
%% Definition of linenomathAMS depends on whether the mathlines option is provided
expandafterifxlinenomathlinenomathWithnumbers
letlinenomathAMSlinenomathWithnumbers
%% The following line gets rid of an extra line numbers at the bottom:
patchcmdlinenomathAMS{advancepostdisplaypenaltylinenopenalty}{}{}{}
else
letlinenomathAMSlinenomathNonumbers
fi
% linenomathpatch{equation} %% <- unnecessary, equation is already patched
linenomathpatchAMS{gather}
linenomathpatchAMS{multline}
linenomathpatchAMS{align}
linenomathpatchAMS{alignat}
linenomathpatchAMS{flalign}
linenumbers
title{My Document}
author{Anonymous Anteater}
begin{document}
maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{align*}
nabla cdot E &= frac{rho}{varepsilon_0}
&
nabla times E &= - frac{partial}{partial t}
\
nabla cdot B &= 0
&
nabla times B &= mu_0 J + mu_0 varepsilon_0 frac{partial E}{partial t}
end{align*}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
[
i hbar frac{d}{dt} lvert Psi(t) rangle = hat H lvert Psi(t) rangle.
]
end{document}
Some details
The following excerpts are from the lineno
documentation:
lineno.sty
does not work well with display math. The parts of a
paragraph preceeding a display math will not get line numbers. The
reason is that the paragraph is not finished, but the part above the
display is broken into lines anyway.
[…]
lineno.sty
defines a{linenomath}
environment, which can be wrapped around a display math to make the line numbering work. This will work with any kind of display math, even if you use explicit$$
pairs. There is a *-form{linenomath*}
which also numbers the lines of the display itself, as good as it can.
To use the align
environment together with the lineno
package, you thus need to wrap the environment between begin{linenomath}
and end{linenomath}
, like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{linenomath}begin{align}
x = 2
end{align}end{linenomath}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Because this is a hassle, the standard math environments are automatically patched to include linenomath
and endlinenomath
.
The environments that are patched are displaymath
, equation
, equation*
, eqnarray
and eqnarray*
, as well as the macros [
and ]
.
If the mathlines
option is provided to lineno
, then the lines within these equations are also numbered.
The amsmath
environments are not patched because (from the documentation):
This will probably not work with AMSmath.
It actually works fine, apart from the fact that each of the amsmath
environments receives an additional line number at the end.
The macro linenomathpatchAMS
, which I define above, performs a modified version of this patch that gets rid of this extra line number. (For more details, see here.)
The only environment that still misbehaves is multline
, which has an extra equation number at the top.
Awesome! Is there a way to extend this to work with[ ... ]
display math as well?
– Peter Grill
Nov 21 at 21:02
@PeterGrill I modified the answer to obey (the presence/absence of) themathlines
option. With this option[…]
-equations are also counted as lines.
– Circumscribe
Nov 21 at 22:34
Oh I see. I didn't notice that you had removed themathlines
option in your MWE.
– Peter Grill
Nov 21 at 22:35
@PeterGrill I thought it was no longer necessary, but I had forgotten about[…]
.
– Circumscribe
Nov 21 at 22:44
1
example would be improved by a multi-linealign
.align
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:04
|
show 7 more comments
up vote
2
down vote
One way is to replace the align
by
[
begin{aligned}
x = 2
end{aligned}
]
or by
begin{equation}
begin{aligned}
x = 2
end{aligned}
end{equation}
if you want numbered version.
example would be improved by a multi-linealigned
.aligned
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:03
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
The lineno
package is not compatible with the amsmath
environments, but the two can be made to work together.
Here is (a slightly updated version of) the patch for the amsmath
environments that I wrote for it as an answer to this question.
documentclass{article}
usepackage{amsmath}
usepackage[mathlines]{lineno}
usepackage{etoolbox} %% <- for pretocmd, apptocmd and patchcmd
%% Patch 'normal' math environment: (currently unused, but good to have)
% newcommand*linenomathpatch[1]{%
% expandafterpretocmdcsname #1endcsname {linenomath}{}{}%
% expandafterpretocmdcsname #1*endcsname{linenomath}{}{}%
% expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
% expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
% }
%% Patch AMS math environment:
newcommand*linenomathpatchAMS[1]{%
expandafterpretocmdcsname #1endcsname {linenomathAMS}{}{}%
expandafterpretocmdcsname #1*endcsname{linenomathAMS}{}{}%
expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
}
%% Definition of linenomathAMS depends on whether the mathlines option is provided
expandafterifxlinenomathlinenomathWithnumbers
letlinenomathAMSlinenomathWithnumbers
%% The following line gets rid of an extra line numbers at the bottom:
patchcmdlinenomathAMS{advancepostdisplaypenaltylinenopenalty}{}{}{}
else
letlinenomathAMSlinenomathNonumbers
fi
% linenomathpatch{equation} %% <- unnecessary, equation is already patched
linenomathpatchAMS{gather}
linenomathpatchAMS{multline}
linenomathpatchAMS{align}
linenomathpatchAMS{alignat}
linenomathpatchAMS{flalign}
linenumbers
title{My Document}
author{Anonymous Anteater}
begin{document}
maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{align*}
nabla cdot E &= frac{rho}{varepsilon_0}
&
nabla times E &= - frac{partial}{partial t}
\
nabla cdot B &= 0
&
nabla times B &= mu_0 J + mu_0 varepsilon_0 frac{partial E}{partial t}
end{align*}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
[
i hbar frac{d}{dt} lvert Psi(t) rangle = hat H lvert Psi(t) rangle.
]
end{document}
Some details
The following excerpts are from the lineno
documentation:
lineno.sty
does not work well with display math. The parts of a
paragraph preceeding a display math will not get line numbers. The
reason is that the paragraph is not finished, but the part above the
display is broken into lines anyway.
[…]
lineno.sty
defines a{linenomath}
environment, which can be wrapped around a display math to make the line numbering work. This will work with any kind of display math, even if you use explicit$$
pairs. There is a *-form{linenomath*}
which also numbers the lines of the display itself, as good as it can.
To use the align
environment together with the lineno
package, you thus need to wrap the environment between begin{linenomath}
and end{linenomath}
, like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{linenomath}begin{align}
x = 2
end{align}end{linenomath}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Because this is a hassle, the standard math environments are automatically patched to include linenomath
and endlinenomath
.
The environments that are patched are displaymath
, equation
, equation*
, eqnarray
and eqnarray*
, as well as the macros [
and ]
.
If the mathlines
option is provided to lineno
, then the lines within these equations are also numbered.
The amsmath
environments are not patched because (from the documentation):
This will probably not work with AMSmath.
It actually works fine, apart from the fact that each of the amsmath
environments receives an additional line number at the end.
The macro linenomathpatchAMS
, which I define above, performs a modified version of this patch that gets rid of this extra line number. (For more details, see here.)
The only environment that still misbehaves is multline
, which has an extra equation number at the top.
Awesome! Is there a way to extend this to work with[ ... ]
display math as well?
– Peter Grill
Nov 21 at 21:02
@PeterGrill I modified the answer to obey (the presence/absence of) themathlines
option. With this option[…]
-equations are also counted as lines.
– Circumscribe
Nov 21 at 22:34
Oh I see. I didn't notice that you had removed themathlines
option in your MWE.
– Peter Grill
Nov 21 at 22:35
@PeterGrill I thought it was no longer necessary, but I had forgotten about[…]
.
– Circumscribe
Nov 21 at 22:44
1
example would be improved by a multi-linealign
.align
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:04
|
show 7 more comments
up vote
5
down vote
accepted
The lineno
package is not compatible with the amsmath
environments, but the two can be made to work together.
Here is (a slightly updated version of) the patch for the amsmath
environments that I wrote for it as an answer to this question.
documentclass{article}
usepackage{amsmath}
usepackage[mathlines]{lineno}
usepackage{etoolbox} %% <- for pretocmd, apptocmd and patchcmd
%% Patch 'normal' math environment: (currently unused, but good to have)
% newcommand*linenomathpatch[1]{%
% expandafterpretocmdcsname #1endcsname {linenomath}{}{}%
% expandafterpretocmdcsname #1*endcsname{linenomath}{}{}%
% expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
% expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
% }
%% Patch AMS math environment:
newcommand*linenomathpatchAMS[1]{%
expandafterpretocmdcsname #1endcsname {linenomathAMS}{}{}%
expandafterpretocmdcsname #1*endcsname{linenomathAMS}{}{}%
expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
}
%% Definition of linenomathAMS depends on whether the mathlines option is provided
expandafterifxlinenomathlinenomathWithnumbers
letlinenomathAMSlinenomathWithnumbers
%% The following line gets rid of an extra line numbers at the bottom:
patchcmdlinenomathAMS{advancepostdisplaypenaltylinenopenalty}{}{}{}
else
letlinenomathAMSlinenomathNonumbers
fi
% linenomathpatch{equation} %% <- unnecessary, equation is already patched
linenomathpatchAMS{gather}
linenomathpatchAMS{multline}
linenomathpatchAMS{align}
linenomathpatchAMS{alignat}
linenomathpatchAMS{flalign}
linenumbers
title{My Document}
author{Anonymous Anteater}
begin{document}
maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{align*}
nabla cdot E &= frac{rho}{varepsilon_0}
&
nabla times E &= - frac{partial}{partial t}
\
nabla cdot B &= 0
&
nabla times B &= mu_0 J + mu_0 varepsilon_0 frac{partial E}{partial t}
end{align*}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
[
i hbar frac{d}{dt} lvert Psi(t) rangle = hat H lvert Psi(t) rangle.
]
end{document}
Some details
The following excerpts are from the lineno
documentation:
lineno.sty
does not work well with display math. The parts of a
paragraph preceeding a display math will not get line numbers. The
reason is that the paragraph is not finished, but the part above the
display is broken into lines anyway.
[…]
lineno.sty
defines a{linenomath}
environment, which can be wrapped around a display math to make the line numbering work. This will work with any kind of display math, even if you use explicit$$
pairs. There is a *-form{linenomath*}
which also numbers the lines of the display itself, as good as it can.
To use the align
environment together with the lineno
package, you thus need to wrap the environment between begin{linenomath}
and end{linenomath}
, like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{linenomath}begin{align}
x = 2
end{align}end{linenomath}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Because this is a hassle, the standard math environments are automatically patched to include linenomath
and endlinenomath
.
The environments that are patched are displaymath
, equation
, equation*
, eqnarray
and eqnarray*
, as well as the macros [
and ]
.
If the mathlines
option is provided to lineno
, then the lines within these equations are also numbered.
The amsmath
environments are not patched because (from the documentation):
This will probably not work with AMSmath.
It actually works fine, apart from the fact that each of the amsmath
environments receives an additional line number at the end.
The macro linenomathpatchAMS
, which I define above, performs a modified version of this patch that gets rid of this extra line number. (For more details, see here.)
The only environment that still misbehaves is multline
, which has an extra equation number at the top.
Awesome! Is there a way to extend this to work with[ ... ]
display math as well?
– Peter Grill
Nov 21 at 21:02
@PeterGrill I modified the answer to obey (the presence/absence of) themathlines
option. With this option[…]
-equations are also counted as lines.
– Circumscribe
Nov 21 at 22:34
Oh I see. I didn't notice that you had removed themathlines
option in your MWE.
– Peter Grill
Nov 21 at 22:35
@PeterGrill I thought it was no longer necessary, but I had forgotten about[…]
.
– Circumscribe
Nov 21 at 22:44
1
example would be improved by a multi-linealign
.align
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:04
|
show 7 more comments
up vote
5
down vote
accepted
up vote
5
down vote
accepted
The lineno
package is not compatible with the amsmath
environments, but the two can be made to work together.
Here is (a slightly updated version of) the patch for the amsmath
environments that I wrote for it as an answer to this question.
documentclass{article}
usepackage{amsmath}
usepackage[mathlines]{lineno}
usepackage{etoolbox} %% <- for pretocmd, apptocmd and patchcmd
%% Patch 'normal' math environment: (currently unused, but good to have)
% newcommand*linenomathpatch[1]{%
% expandafterpretocmdcsname #1endcsname {linenomath}{}{}%
% expandafterpretocmdcsname #1*endcsname{linenomath}{}{}%
% expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
% expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
% }
%% Patch AMS math environment:
newcommand*linenomathpatchAMS[1]{%
expandafterpretocmdcsname #1endcsname {linenomathAMS}{}{}%
expandafterpretocmdcsname #1*endcsname{linenomathAMS}{}{}%
expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
}
%% Definition of linenomathAMS depends on whether the mathlines option is provided
expandafterifxlinenomathlinenomathWithnumbers
letlinenomathAMSlinenomathWithnumbers
%% The following line gets rid of an extra line numbers at the bottom:
patchcmdlinenomathAMS{advancepostdisplaypenaltylinenopenalty}{}{}{}
else
letlinenomathAMSlinenomathNonumbers
fi
% linenomathpatch{equation} %% <- unnecessary, equation is already patched
linenomathpatchAMS{gather}
linenomathpatchAMS{multline}
linenomathpatchAMS{align}
linenomathpatchAMS{alignat}
linenomathpatchAMS{flalign}
linenumbers
title{My Document}
author{Anonymous Anteater}
begin{document}
maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{align*}
nabla cdot E &= frac{rho}{varepsilon_0}
&
nabla times E &= - frac{partial}{partial t}
\
nabla cdot B &= 0
&
nabla times B &= mu_0 J + mu_0 varepsilon_0 frac{partial E}{partial t}
end{align*}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
[
i hbar frac{d}{dt} lvert Psi(t) rangle = hat H lvert Psi(t) rangle.
]
end{document}
Some details
The following excerpts are from the lineno
documentation:
lineno.sty
does not work well with display math. The parts of a
paragraph preceeding a display math will not get line numbers. The
reason is that the paragraph is not finished, but the part above the
display is broken into lines anyway.
[…]
lineno.sty
defines a{linenomath}
environment, which can be wrapped around a display math to make the line numbering work. This will work with any kind of display math, even if you use explicit$$
pairs. There is a *-form{linenomath*}
which also numbers the lines of the display itself, as good as it can.
To use the align
environment together with the lineno
package, you thus need to wrap the environment between begin{linenomath}
and end{linenomath}
, like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{linenomath}begin{align}
x = 2
end{align}end{linenomath}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Because this is a hassle, the standard math environments are automatically patched to include linenomath
and endlinenomath
.
The environments that are patched are displaymath
, equation
, equation*
, eqnarray
and eqnarray*
, as well as the macros [
and ]
.
If the mathlines
option is provided to lineno
, then the lines within these equations are also numbered.
The amsmath
environments are not patched because (from the documentation):
This will probably not work with AMSmath.
It actually works fine, apart from the fact that each of the amsmath
environments receives an additional line number at the end.
The macro linenomathpatchAMS
, which I define above, performs a modified version of this patch that gets rid of this extra line number. (For more details, see here.)
The only environment that still misbehaves is multline
, which has an extra equation number at the top.
The lineno
package is not compatible with the amsmath
environments, but the two can be made to work together.
Here is (a slightly updated version of) the patch for the amsmath
environments that I wrote for it as an answer to this question.
documentclass{article}
usepackage{amsmath}
usepackage[mathlines]{lineno}
usepackage{etoolbox} %% <- for pretocmd, apptocmd and patchcmd
%% Patch 'normal' math environment: (currently unused, but good to have)
% newcommand*linenomathpatch[1]{%
% expandafterpretocmdcsname #1endcsname {linenomath}{}{}%
% expandafterpretocmdcsname #1*endcsname{linenomath}{}{}%
% expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
% expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
% }
%% Patch AMS math environment:
newcommand*linenomathpatchAMS[1]{%
expandafterpretocmdcsname #1endcsname {linenomathAMS}{}{}%
expandafterpretocmdcsname #1*endcsname{linenomathAMS}{}{}%
expandafterapptocmdcsname end#1endcsname {endlinenomath}{}{}%
expandafterapptocmdcsname end#1*endcsname{endlinenomath}{}{}%
}
%% Definition of linenomathAMS depends on whether the mathlines option is provided
expandafterifxlinenomathlinenomathWithnumbers
letlinenomathAMSlinenomathWithnumbers
%% The following line gets rid of an extra line numbers at the bottom:
patchcmdlinenomathAMS{advancepostdisplaypenaltylinenopenalty}{}{}{}
else
letlinenomathAMSlinenomathNonumbers
fi
% linenomathpatch{equation} %% <- unnecessary, equation is already patched
linenomathpatchAMS{gather}
linenomathpatchAMS{multline}
linenomathpatchAMS{align}
linenomathpatchAMS{alignat}
linenomathpatchAMS{flalign}
linenumbers
title{My Document}
author{Anonymous Anteater}
begin{document}
maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{align*}
nabla cdot E &= frac{rho}{varepsilon_0}
&
nabla times E &= - frac{partial}{partial t}
\
nabla cdot B &= 0
&
nabla times B &= mu_0 J + mu_0 varepsilon_0 frac{partial E}{partial t}
end{align*}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
[
i hbar frac{d}{dt} lvert Psi(t) rangle = hat H lvert Psi(t) rangle.
]
end{document}
Some details
The following excerpts are from the lineno
documentation:
lineno.sty
does not work well with display math. The parts of a
paragraph preceeding a display math will not get line numbers. The
reason is that the paragraph is not finished, but the part above the
display is broken into lines anyway.
[…]
lineno.sty
defines a{linenomath}
environment, which can be wrapped around a display math to make the line numbering work. This will work with any kind of display math, even if you use explicit$$
pairs. There is a *-form{linenomath*}
which also numbers the lines of the display itself, as good as it can.
To use the align
environment together with the lineno
package, you thus need to wrap the environment between begin{linenomath}
and end{linenomath}
, like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
begin{linenomath}begin{align}
x = 2
end{align}end{linenomath}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
culpa qui officia deserunt mollit anim id est laborum.
Because this is a hassle, the standard math environments are automatically patched to include linenomath
and endlinenomath
.
The environments that are patched are displaymath
, equation
, equation*
, eqnarray
and eqnarray*
, as well as the macros [
and ]
.
If the mathlines
option is provided to lineno
, then the lines within these equations are also numbered.
The amsmath
environments are not patched because (from the documentation):
This will probably not work with AMSmath.
It actually works fine, apart from the fact that each of the amsmath
environments receives an additional line number at the end.
The macro linenomathpatchAMS
, which I define above, performs a modified version of this patch that gets rid of this extra line number. (For more details, see here.)
The only environment that still misbehaves is multline
, which has an extra equation number at the top.
edited Nov 22 at 16:22
answered Nov 21 at 20:24
Circumscribe
3,4821328
3,4821328
Awesome! Is there a way to extend this to work with[ ... ]
display math as well?
– Peter Grill
Nov 21 at 21:02
@PeterGrill I modified the answer to obey (the presence/absence of) themathlines
option. With this option[…]
-equations are also counted as lines.
– Circumscribe
Nov 21 at 22:34
Oh I see. I didn't notice that you had removed themathlines
option in your MWE.
– Peter Grill
Nov 21 at 22:35
@PeterGrill I thought it was no longer necessary, but I had forgotten about[…]
.
– Circumscribe
Nov 21 at 22:44
1
example would be improved by a multi-linealign
.align
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:04
|
show 7 more comments
Awesome! Is there a way to extend this to work with[ ... ]
display math as well?
– Peter Grill
Nov 21 at 21:02
@PeterGrill I modified the answer to obey (the presence/absence of) themathlines
option. With this option[…]
-equations are also counted as lines.
– Circumscribe
Nov 21 at 22:34
Oh I see. I didn't notice that you had removed themathlines
option in your MWE.
– Peter Grill
Nov 21 at 22:35
@PeterGrill I thought it was no longer necessary, but I had forgotten about[…]
.
– Circumscribe
Nov 21 at 22:44
1
example would be improved by a multi-linealign
.align
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:04
Awesome! Is there a way to extend this to work with
[ ... ]
display math as well?– Peter Grill
Nov 21 at 21:02
Awesome! Is there a way to extend this to work with
[ ... ]
display math as well?– Peter Grill
Nov 21 at 21:02
@PeterGrill I modified the answer to obey (the presence/absence of) the
mathlines
option. With this option […]
-equations are also counted as lines.– Circumscribe
Nov 21 at 22:34
@PeterGrill I modified the answer to obey (the presence/absence of) the
mathlines
option. With this option […]
-equations are also counted as lines.– Circumscribe
Nov 21 at 22:34
Oh I see. I didn't notice that you had removed the
mathlines
option in your MWE.– Peter Grill
Nov 21 at 22:35
Oh I see. I didn't notice that you had removed the
mathlines
option in your MWE.– Peter Grill
Nov 21 at 22:35
@PeterGrill I thought it was no longer necessary, but I had forgotten about
[…]
.– Circumscribe
Nov 21 at 22:44
@PeterGrill I thought it was no longer necessary, but I had forgotten about
[…]
.– Circumscribe
Nov 21 at 22:44
1
1
example would be improved by a multi-line
align
. align
isn't meant to be used for single-line formulas.– barbara beeton
Nov 22 at 16:04
example would be improved by a multi-line
align
. align
isn't meant to be used for single-line formulas.– barbara beeton
Nov 22 at 16:04
|
show 7 more comments
up vote
2
down vote
One way is to replace the align
by
[
begin{aligned}
x = 2
end{aligned}
]
or by
begin{equation}
begin{aligned}
x = 2
end{aligned}
end{equation}
if you want numbered version.
example would be improved by a multi-linealigned
.aligned
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:03
add a comment |
up vote
2
down vote
One way is to replace the align
by
[
begin{aligned}
x = 2
end{aligned}
]
or by
begin{equation}
begin{aligned}
x = 2
end{aligned}
end{equation}
if you want numbered version.
example would be improved by a multi-linealigned
.aligned
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:03
add a comment |
up vote
2
down vote
up vote
2
down vote
One way is to replace the align
by
[
begin{aligned}
x = 2
end{aligned}
]
or by
begin{equation}
begin{aligned}
x = 2
end{aligned}
end{equation}
if you want numbered version.
One way is to replace the align
by
[
begin{aligned}
x = 2
end{aligned}
]
or by
begin{equation}
begin{aligned}
x = 2
end{aligned}
end{equation}
if you want numbered version.
answered Nov 21 at 19:52
Sigur
23.6k354135
23.6k354135
example would be improved by a multi-linealigned
.aligned
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:03
add a comment |
example would be improved by a multi-linealigned
.aligned
isn't meant to be used for single-line formulas.
– barbara beeton
Nov 22 at 16:03
example would be improved by a multi-line
aligned
. aligned
isn't meant to be used for single-line formulas.– barbara beeton
Nov 22 at 16:03
example would be improved by a multi-line
aligned
. aligned
isn't meant to be used for single-line formulas.– barbara beeton
Nov 22 at 16:03
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461186%2fhow-to-use-lineno-with-amsmath-align%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Related/duplicate: Why doesn't
lineno
number a paragraph when it is followed by analign
equation environment without a space?– Werner
Nov 21 at 20:20
@Werner apologies for the duplicate, shall I close my question?
– jesterII
Nov 21 at 20:39