5

I've looked at questions about numbering each line in Latex document, and using package lineno and tried all the tricks shown in the questions and answers, but nothing is working for me. The package still do not number each line. I want each line numbered, including math and text.

Has something changed recently? I tried

\usepackage[]{lineno}
\linenumbers 

Tried

\usepackage[]{lineno}
\internallinenumbers

Tried

\usepackage[]{lineno}
\linenumbers 
\setrunninglinenumbers
\runninglinenumbers

Tried

\usepackage[]{lineno}
\internallinenumbers
\setrunninglinenumbers
\runninglinenumbers

This last one does the best job, but it stil skips some equations and some text lines as well by random.

Here is a MWE using the above last configuration, as it seems to work best

\documentclass[12pt]{article}%
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}%

\usepackage[]{lineno}
\internallinenumbers
\setrunninglinenumbers
\runninglinenumbers

\begin{document}
\section{problem (a), page 88}%
\[
y^{\prime\prime}=\frac{1}{x^{5}}y
\]
Irregular singular point at $x\rightarrow0^{+}$. 
Let $y=e^{S_{0}\left(x\right)}$ and the above becomes%
\begin{align*}
y\left(  x\right)   &  =e^{S_{0}\left(  x\right)  }\\
y^{\prime}\left(  x\right)   &  =S_{0}^{\prime}e^{S}\\
y^{\prime\prime} &  =S_{0}^{\prime\prime}e^{S_{0}}+\left(  S_{0}^{\prime
}\right)  ^{2}e^{S_{0}}\\
&  =\left(  S_{0}^{\prime\prime}+\left(S_{0}^{\prime}\right) ^{2}\right)e^{S_{0}}
\end{align*}
Substituting back into $\frac{d^{2}}{dx^{2}}y=x^{-5}y$ gives

Hence%
\begin{align*}
S_{1}  & \thicksim-\int\frac{S_{0}^{\prime\prime}}{S_{0}^{\prime}}dx\\
& \thicksim-\ln S_{0}^{\prime}+c
\end{align*}
\end{document}

Here is the pdf generated using lualatex foo.tex You can see it skips lines and some math.

Mathematica graphics

I tried solution given in number-every-line-of-pages/16012#16012 but the code given in the answer there did not even compile for me. Many errors. May be things changed since answer was old.

my question is: How can one number each line (math and text) in document?

1
  • So we still don't have an actual solution here?
    – dodo
    Commented Jun 30, 2022 at 7:39

2 Answers 2

2

This is a response to a comment by the OP in chat.

If all you want is a bunch of numbers down the left margin of the kind which journals add to papers on submission, then this is straightforward. These will not necessarily correspond with actual lines, but they can be used to provide approximate references. Since line numbers are not well-defined for maths anyway, this may be adequate for some purposes.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz,everypage}
\AtBeginDocument{%
  \AddEverypageHook{%
    \begin{tikzpicture}[remember picture,overlay]
      \path (current page.north west) --  (current page.south west) \foreach \i in {1,...,\fakelinenos} { node [pos={(\i-.5)/\fakelinenos}, xshift=\fakelinenoshift, line number style] {\i} }  ;
    \end{tikzpicture}%
  }%
}
\tikzset{%
  line numbers/.store in=\fakelinenos,
  line numbers=50,
  line number shift/.store in=\fakelinenoshift,
  line number shift=5mm,
  line number style/.style={text=gray},
}
\begin{document}
\section{problem (a), page 88}
\[
y^{\prime\prime}=\frac{1}{x^{5}}y
\]
Irregular singular point at $x\rightarrow0^{+}$.
Let $y=e^{S_{0}\left(x\right)}$ and the above becomes%
\begin{align*}
  y\left(  x\right)   &  =e^{S_{0}\left(  x\right)  }\\
  y^{\prime}\left(  x\right)   &  =S_{0}^{\prime}e^{S}\\
  y^{\prime\prime} &  =S_{0}^{\prime\prime}e^{S_{0}}+\left(  S_{0}^{\prime
  }\right)  ^{2}e^{S_{0}}\\
  &  =\left(  S_{0}^{\prime\prime}+\left(S_{0}^{\prime}\right) ^{2}\right)e^{S_{0}}
\end{align*}
Substituting back into $\frac{d^{2}}{dx^{2}}y=x^{-5}y$ gives

Hence
\begin{align*}
  S_{1}  & \thicksim-\int\frac{S_{0}^{\prime\prime}}{S_{0}^{\prime}}dx\\
  & \thicksim-\ln S_{0}^{\prime}+c
\end{align*}
\end{document}

fake line numbers

1
  • The package vruler is the go-to solution if this is the approach you want to take. Commented Feb 26, 2022 at 7:13
5

As the documentation states numbers before displaymath environments can disappear. For standard displaymath you can avoid it (and get numbered equations) by using the options mathlines and displaymath. But this won't work with amsmath environments. You can surround them with linenomath environments but then you get spurious numbers at the end of the align (and I didn't dare to test what happens if you mix amsmath environments):

\documentclass[12pt]{article}%
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}%

\usepackage[mathlines,displaymath]{lineno}

\runninglinenumbers

\begin{document}
\section{problem (a), page 88}%
\[
y^{\prime\prime}=\frac{1}{x^{5}}y
\]
Irregular singular point at $x\rightarrow0^{+}$.
Let $y=e^{S_{0}\left(x\right)}$ and the above becomes%
\begin{linenomath}
\begin{align*}
 y\left(  x\right)   &  =e^{S_{0}\left(  x\right)  }\\
y^{\prime}\left(  x\right)   &  =S_{0}^{\prime}e^{S}\\
y^{\prime\prime} &  =S_{0}^{\prime\prime}e^{S_{0}}+\left(  S_{0}^{\prime
}\right)  ^{2}e^{S_{0}}\\
&  =\left(  S_{0}^{\prime\prime}+\left(S_{0}^{\prime}\right) ^{2}\right)e^{S_{0}}
\end{align*}
\end{linenomath}
Substituting back into $\frac{d^{2}}{dx^{2}}y=x^{-5}y$ gives
Hence %
\begin{linenomath}%
\begin{align*}
S_{1}  & \thicksim-\int\frac{S_{0}^{\prime\prime}}{S_{0}^{\prime}}dx\\
& \thicksim-\ln S_{0}^{\prime}+c
\end{align*}%
\end{linenomath}


\end{document}

enter image description here

Using linenomath* and \internallinenumbers instead isn't really good either. So it doesn't look as if there is a good solution with amsmath environments ...

3
  • Thanks. But I do not want to edit the document itself and add \begin{linenomath} and \end{linenomath} each time. I wanted to just issue commands from preamble once. Strange that for all latex power, one can't have line numbers on every line in document. But thank you for your effort.
    – Nasser
    Commented Feb 4, 2017 at 17:01
  • 1
    i've added a note to the collected bugs/suggestions for amsmath to document this incompatibility, and (if possible) to consider how to make the packages work together. (the lineno documentation does mention that some things "will probably not work with amsmath.) Commented Feb 4, 2017 at 18:20
  • 1
    If you don't care about the slight problem with the number of the end you can patch \start@align: \usepackage{xpatch} \makeatletter \xpretocmd \start@align{\linenomathWithnumbers}{}{\fail}. then you don't need the linenomath environment. Commented Feb 5, 2017 at 10:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .