As an example of my comment under the question: the Association for Computing Machinery uses continuous line numbering for papers under review. These line numbers are not linked to the actual lines in the paper and may therefore be misaligned vertically.
In the code below I added the relevant parts from acmart.cls
into the example document from the question. Basically a box with line numbers is constructed by repeatedly adding the next number until the box reached \textheight
. Then this box is added to the page at the top left corner using \put
. This is repeated for each page by adding the \put
command in a header specification using \fancyhdr
.
MWE:
\documentclass[11pt]{amsart}
\usepackage{xcolor}
\setlength{\textheight}{23cm}
\setlength{\textwidth}{16cm}
\setlength{\topmargin}{-0.8cm}
\setlength{\parskip}{0.3\baselineskip}
\hoffset=-1.4cm
\usepackage{amsmath,amscd,amssymb}
\usepackage{hyperref}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{conjecture}[subsection]{Conjecture}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\numberwithin{equation}{section}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{corollary}[theorem]{Corollary}
\renewcommand{\thefootnote}{\arabic{footnote}}
\input xy
\xyoption{all}
\usepackage{fancyhdr}
\makeatletter
% the code below is modified from acmart.cls
% source: https://ctan.org/pkg/acmart
% licensed under LPPL 1.3
\newsavebox{\ACM@linecount@bx}
\newlength\ACM@linecount@bxht
\newcount\ACM@linecount
\ACM@linecount\@ne\relax
\def\ACM@mk@linecount{%
\savebox{\ACM@linecount@bx}[4em][t]{\parbox[t]{4em}{\normalfont
\normalsize
\setlength{\ACM@linecount@bxht}{0pt}%
\loop{\color{red}\scriptsize\the\ACM@linecount}\\
\global\advance\ACM@linecount by \@ne
\addtolength{\ACM@linecount@bxht}{\baselineskip}%
\ifdim\ACM@linecount@bxht<\textheight\repeat
{\color{red}\scriptsize\the\ACM@linecount}\hfill
\global\advance\ACM@linecount by \@ne}}}
\def\ACM@linecountL{%
\ACM@mk@linecount
\begin{picture}(0,0)%
\put(-26,-18){\usebox{\ACM@linecount@bx}}%
\end{picture}%
}
\pagestyle{fancy}
\fancyhead[L]{\ACM@linecountL}
% end of code modified from acmart.cls
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{}
\makeatother
\begin{document}
la la la \\
\begin{theorem}
If this is true, then that is true.\
\end{theorem}
\begin{proof}
It's always true
\end{proof}
la la la
\end{document}
Result:

There are various parameters to modify.
- Start the numbers before the first line: adjust
\put(x,y)
. In the code below \put(-26,-10)
puts the number 1 above the first line.
- Number range: this is determined by the total height of the box. The code does not use the real height, instead it is simulated by the length variable
\ACM@linecount@bxht
which is initialized to 0pt
at the start of the box and increased by \baselineskip
after every number. By reducing the simulated increase you can fit more numbers before the box reaches \textheight
. Trial and error leads to 0.855\baselineskip
for numbers 1-60.
- Distance between numbers: this can be set by adding a length to the linebreak
\\
after each number. Trial and error leads to \\[-1.5pt]
to put the number 60 near the bottom of the page.
- Resetting the numbers each page: this can be done by putting the number counter initialization
\ACM@linecount\@ne\relax
inside of the macro that is called for each page header (\ACM@mk@linecount
, mk
means 'make').
- Line numbers on first page: the numbers are produced by a header. This header is only shown if
\pagestyle{fancy}
is in effect. Many documentclasses set \pagestyle{plain}
for the first page and/or for the full document. You can redefine plain
to use the fancy
definitions (i.e., print the header and therefore the line numbers) using \fancypagestyle{plain}{}
(note: this was already included in the first version of the answer above). It is also possible that a documentclass sets the page style to empty
in which case you should modify the header settings accordingly.
Modified code:
\documentclass[11pt]{amsart}
\usepackage{xcolor}
\setlength{\textheight}{23cm}
\setlength{\textwidth}{16cm}
\setlength{\topmargin}{-0.8cm}
\setlength{\parskip}{0.3\baselineskip}
\hoffset=-1.4cm
\usepackage{amsmath,amscd,amssymb}
\usepackage{hyperref}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{conjecture}[subsection]{Conjecture}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\numberwithin{equation}{section}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{corollary}[theorem]{Corollary}
\renewcommand{\thefootnote}{\arabic{footnote}}
\input xy
\xyoption{all}
\usepackage{fancyhdr}
\usepackage{lipsum}
\makeatletter
% the code below is modified from acmart.cls
% source: https://ctan.org/pkg/acmart
% licensed under LPPL 1.3
\newsavebox{\ACM@linecount@bx}
\newlength\ACM@linecount@bxht
\newcount\ACM@linecount
%\ACM@linecount\@ne\relax
\def\ACM@mk@linecount{%
\ACM@linecount\@ne\relax % reset counter each page
\savebox{\ACM@linecount@bx}[4em][t]{\parbox[t]{4em}{\normalfont
\normalsize
\setlength{\ACM@linecount@bxht}{0pt}%
\loop{\color{red}\scriptsize\the\ACM@linecount}\\[-1.5pt] % vertical distance between numbers
\global\advance\ACM@linecount by \@ne
\addtolength{\ACM@linecount@bxht}{0.855\baselineskip}% reduce similated box height increase
\ifdim\ACM@linecount@bxht<\textheight\repeat
{\color{red}\scriptsize\the\ACM@linecount}\hfill
\global\advance\ACM@linecount by \@ne}}}
\def\ACM@linecountL{%
\ACM@mk@linecount
\begin{picture}(0,0)%
\put(-26,-10){\usebox{\ACM@linecount@bx}}% x,y coordinates of line number 1
\end{picture}%
}
\pagestyle{fancy}
\fancyhead[L]{\ACM@linecountL}
% end of code modified from acmart.cls
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{} % add numbers to plain pages (e.g., first page)
\makeatother
\begin{document}
la la la \\
\begin{theorem}
If this is true, then that is true.\
\end{theorem}
\begin{proof}
It's always true
\end{proof}
la la la
\lipsum[1-8]
\end{document}
Result (end of page 1 and start of page 2):
