1  lineno.sty  v2.02 1997/03/17

2

3 A L^{A}TEX style option to attach 4 Line numbers on paragraphs

5 Stephan I. Böttcher 6 stephan@alzt.tau.ac.il 7 boettcher@desy.de

8 Contents

9 1 Introduction 2 10 2 Put the line numbers to the lines 2 11 3 Control line numbering 4 12 4 Line number references 5 13 4.1 The linelabel command . . . . . . . . . . . . . . . . . . . . . 6 14 5 The appearance of the line numbers 7 15 5.1 Running line numbers . . . . . . . . . . . . . . . . . . . . . . 8 16 5.2 Pagewise line numbers . . . . . . . . . . . . . . . . . . . . . 9 17 5.3 Numbering modulo 5 . . . . . . . . . . . . . . . . . . . . . . 13 18 6 Package options 14 19 7 The final touch 15 20 8 The user commands 15 21 8.1 Customization hooks . . . . . . . . . . . . . . . . . . . . . . 17

1 1 Introduction

2 This package provides line numbers on paragraphs. After TEX has broken 3 a paragraph into lines there will be line numbers attached to them, with 4 the possibility to make references through the L^{A}TEX \ref, \pageref cross 5 reference mechanism. This includes four issues:

6 • attach a line number on each line,

7 • create references to a line number,

8 • control line numbering mode,

9 • count the lines and print the numbers.

10 The first two points are implemented through patches to the output routine. 11 The third by redefining \par, \@par and \@@par. The counting is easy, as 12 long as you want the line numbers run through the text. If they shall start 13 over at the top of each page, the aux-file as well as TEXs memory have to 14 carry a load for each counted line. 15 I wrote this package for my wife Petra, who needs it for transcriptions 16 of interviews. This allows her to precisely refer to passages in the text. It 17 works well together with \marginpars, but not with displaymath. 18 This style option is written for L^{A}TEX 2ε.

  1 \NeedsTeXFormat{LaTeX2e}
  2 \ProvidesPackage{lineno}
  3 [1997/03/17 line numbers on paragraphs (c) SIB v2.02]

19 2 Put the line numbers to the lines

20 The line numbers have to be attached by the output routine. We simply set 21 the \interlinepenalty to -100000. The output routine will be called after 22 each line in the paragraph, except the last, where we trigger by \par. The 23 \linenopenalty is small enough to compensate a bunch of penalties (e.g.,

24 with \samepage).
  4 \newcount\linenopenalty\linenopenalty=-100000
  5 \mathchardef\linenopenaltypar=25000

25 So let’s make a hook to \output, the direct way. The L^{A}TEX macro 26 \@reinserts puts the footnotes back on the page.

 6 \output=\expandafter{%
 7  \expandafter \LineNoTest
 8  \expandafter \if@tempswa
 9  \the\output
10  \else
11  \@reinserts
12  \MakeLineNo
13  \fi

14 }

1 The float mechanism inserts \interlinepenaltys during \output. So care-2 fully reset it before going on. Else we get doubled line numbers on every 3 float placed in horizontal mode, e.g, from \linelabel. 4 Sorry, neither a \linelabel nor a \marginpar should insert a penalty, 5 else the following linenumber could go to the next page. Nor should any 6 other float. So let us suppress the \interlinepenalty altogether with the

7 \@nobreak switch.

8 Since (ltspace.dtx, v1.2p)[1996/07/26], the \@nobreaktrue does it’s job 9 globally. We need to do it locally here.

15 \def\LineNoTest{%
16 \ifnum\interlinepenalty<-\linenopenaltypar
17  \advance\interlinepenalty-\linenopenalty
18  \my@nobreaktrue
19  \fi
20 \@tempswatrue
21 \ifnum\outputpenalty>-\linenopenaltypar\else
22  \ifnum\outputpenalty>-175000\relax
23  \@tempswafalse
24  \fi
25  \fi

26 } 27

28 \def\my@nobreaktrue{\let\if@nobreak\iftrue}

10 We have to return all the page to the current page, and add a box with the 11 line number, without adding breakpoints, glue or space. The depth of our 12 line number should be equal to the previous depth of the page, in case the 13 page breaks here, and the box has to be moved up by that depth.

14  The \interlinepenalty comes after the \vadjust from a \linelabel,

15 so we increment the line number after printing it. The macro 16 \makeLineNumber produces the text of the line number, see section 5. Finally 17 we put in the natural \interlinepenalty, except after the last line.

29 \def\MakeLineNo{\@tempdima\dp\@cclv \unvbox\@cclv

30 \sbox\@tempboxa{\hbox to\z@{\makeLineNumber}}%
31 \stepcounter{linenumber}%
32 \dp\@tempboxa=\@tempdima\ht\@tempboxa=\z@
33 \nointerlineskip\kern-\@tempdima\box\@tempboxa
34 \ifnum\outputpenalty=-\linenopenaltypar\else
35  \@tempcnta\outputpenalty
36  \advance\@tempcnta -\linenopenalty
37  \penalty\@tempcnta
38 \fi

39 }

1 3 Control line numbering

2 The line numbering is controlled via \par. L^{A}TEX saved the TEX-primitive 3 \par in \@@par. We push it one level further out, and redefine \@@par to 4 insert the \interlinepenalty needed to trigger the line numbering. And 5 we need to allow pagebreaks after a paragraph.

40 \let\@@@par\@@par

41

42 \def\linenumberpar{\ifvmode\@@@par\else\ifinner\@@@par\else
43  \advance\interlinepenalty \linenopenalty
44  \@@@par
45  \penalty-\linenopenaltypar
46  \kern\z@
47  \advance\interlinepenalty -\linenopenalty
48  \fi\fi

49 }

6 The basic commands to enable and disable line numbers. \@par and \par 7 are only touched, when they are \let to \@@@par/\linenumberpar. The line 8 number may be reset to 1 with the star-form, or set by an optional argument 9 [⟨number⟩].

50 \def\linenumbers{\let\@@par\linenumberpar
51  \ifx\@par\@@@par\let\@par\linenumberpar\fi
52  \ifx\par\@@@par\let\par\linenumberpar\fi
53  \@ifnextchar[{\resetlinenumber}%]
54  {\@ifstar{\resetlinenumber}{}}%

55 } 56

57 \def\nolinenumbers{\let\@@par\@@@par
58 \ifx\@par\linenumberpar\let\@par\@@@par\fi
59 \ifx\par\linenumberpar\let\par\@@@par\fi

60 }

What happens with a display? Since \par is not executed, when breaking the lines before a display, they will not get line numbers. Sorry, but I do not dare to change \interlinepenalty globally, nor do I want to redefine the display math environments. Do that, if you really need it.

display math

1 The next two commands are provided to turn on line numbering in a specific 2 mode. Please note the difference: for pagewise numbering, \linenumbers 3 comes first to inhibit it from seeing optional arguments, since re-/presetting 4 the counter is useless.

61 \def\pagewiselinenumbers{\linenumbers\setpagewiselinenumbers}
62 \def\runninglinenumbers{\setrunninglinenumbers\linenumbers}

5 Finally, it is a L^{A}TEX style, so we provide for the use of environments, includ-6 ing the suppression of the following paragraphs indentation.

63 \@namedef{linenumbers*}{\par\linenumbers*}
64 \@namedef{runninglinenumbers*}{\par\runninglinenumbers*}

65

66 \def\endlinenumbers{\par\@endpetrue}
67 \let\endrunninglinenumbers\endlinenumbers
68 \let\endpagewiselinenumbers\endlinenumbers
69 \expandafter\let\csname endlinenumbers*\endcsname\endlinenumbers
70 \expandafter\let\csname endrunninglinenumbers*\endcsname\endlinenumbers

7 4 Line number references

8 The only way to get a label to a line number in a paragraph is to ask the 9 output routine to mark it. 10 We use the marginpar mechanism to hook to \output for a second time. 11 Marginpars are floats with number −1, we fake marginpars with No −2. 12 Originally, every negative numbered float was considered to be a marginpar. 13 The float box number \@currbox is used to transfer the label name in a 14 macro called \@LNL@⟨box-number⟩. 15 A \newlabel is written to the aux-file. The reference is to 16 \theLineNumber, not \thelinenumber. This allows to hook in, as done 17 below for pagewise line numbering.

71 \let\@LN@addmarginpar\@addmarginpar
72 \def\@addmarginpar{%
73 \ifnum\count\@currbox>-2\relax

 74  \@LN@addmarginpar
 75 \else
 76  \@cons\@freelist\@currbox
 77  \protected@write\@auxout{}{%
 78  \string\newlabel
 79  {\csname @LNL@\the\@currbox\endcsname}%
 80  {{\theLineNumber}{\thepage}}}%
 81 \fi}

1 4.1 The linelabel command

2 To refer to a place in line \ref{⟨foo⟩} at page \pageref{⟨foo⟩} you place a 3 \linelabel{⟨foo⟩} at that place.

If you use this command outside a \linenumbers paragraph, you will

It works: This paragraph starts on page 6, line 4.

4

5 get references to some junky line numbers, sorry. But we don’t disable the 6 command, because only the \par at the end of a paragraph may decides 7 whether to print line numbers on this paragraph or not. A \linelabel may 8 appear earlier than \linenumbers. 9 \linelabel, via a fake float number −2, puts a \penalty into a 10 \vadjust, which triggers the pagebuilder after putting the current line to 11 the main vertical list. A \write is placed on the main vertical list, which 12 prints a reference to the current value of \thelinenumber and \thepage at 13 the time of the \shipout. 14 A \linelabel is allowed only in outer horizontal or vertical modes. 15 The argument of \linelabel is put into a macro with a name derived 16 from the number of the allocated float box. Much of the rest is dummy float 17 setup.

 82 \def\linelabel#1{%
 83 \ifvmode
 84  \ifinner \else \leavevmode \fi
 85  \fi
 86 \ifhmode
 87  \ifinner
 88  \@parmoderr
 89  \else
 90  \@bsphack\@floatpenalty -\@Mii
 91  \@next\@currbox\@freelist
 92  {\global\count\@currbox-2%
 93  \expandafter\gdef\csname @LNL@\the\@currbox\endcsname{#1}}%
 94  {\@floatpenalty\z@ \@fltovf \def\@currbox{\@tempboxa}}%
 95  \begingroup
 96  \setbox\@currbox \color@vbox \vbox \bgroup \end@float
 97  \endgroup
 98  \global \@ignorefalse \@esphack

 99  \fi
100 \else
101  \@parmoderr
102 \fi

103 }

5 The appearance of the line numbers

  The line numbers are set as \tiny\sffamily\arabic{linenumber}, 10pt

3 left of the text. You may add options to place it right of the text, or … … here are the hooks:

104 \def\makeLineNumberLeft{\hss\linenumberfont\LineNumber\hskip\linenumbersep}

105

106 \def\makeLineNumberRight{\linenumberfont\hskip\linenumbersep\hskip\textwidth
107  \hbox to\linenumberwidth{\hss\LineNumber}\hss}

108

109 \def\linenumberfont{\normalfont\tiny\sffamily}

110

111 \newdimen\linenumbersep
112 \newdimen\linenumberwidth

113

114 \linenumberwidth=10pt
115 \linenumbersep=10pt

Oh well, some of the suggested ‘customization’ has been done, particularly 6 the placement of the numbers. Margin switching requires pagewise num-

bering mode, but choosing the left or right margin for the numbers always works.

116 \def\switchlinenumbers{\@ifstar
117  {\let\makeLineNumberOdd\makeLineNumberRight
118  \let\makeLineNumberEven\makeLineNumberLeft}%
119  {\let\makeLineNumberOdd\makeLineNumberLeft
120  \let\makeLineNumberEven\makeLineNumberRight}%

121 } 122

123 \def\setmakelinenumbers#1{\@ifstar
124 {\let\makeLineNumberRunning#1%
125 \let\makeLineNumberOdd#1%
126 \let\makeLineNumberEven#1}%
127 {\ifx\c@linenumber\c@runninglinenumber
128  \let\makeLineNumberRunning#1%
129 \else
130  \let\makeLineNumberOdd#1%
131  \let\makeLineNumberEven#1%

132 \fi}%

133 } 134

135 \def\leftlinenumbers{\setmakelinenumbers\makeLineNumberLeft}
136 \def\rightlinenumbers{\setmakelinenumbers\makeLineNumberRight}

137

138 \leftlinenumbers*

\LineNumber is a hook which is used for the modulo stuff. It is the command to use for the line number, when you customizes \makeLineNumber. Use

3 \thelinenumber to change the outfit of the digits.

We will implement two modes of operation:

• numbers running through (parts of) the text

6 • pagewise numbers starting over with one on top of each page.

Both modes have their own count register, but only one is allocated as a L^{A}TEX counter, with the attached facilities serving both.

139 \newcounter{linenumber}
140 \newcount\c@pagewiselinenumber
141 \let\c@runninglinenumber\c@linenumber

9 Only the running mode counter may be reset, or preset, for individual paragraphs. The pagewise counter must give a unique anonymous number for each line.

142 \newcommand\resetlinenumber[1][1]{\c@runninglinenumber#1}

12 5.1 Running line numbers

Running mode is easy, \LineNumber and \theLineNumber produce

\thelinenumber, which defaults to \arabic{linenumber}, using the

15 \c@runninglinenumber counter. This is the default mode of operation.

143 \def\makeRunningLineNumber{\makeLineNumberRunning}

144

145 \def\setrunninglinenumbers{%
146 \def\theLineNumber{\thelinenumber}%
147 \let\c@linenumber\c@runninglinenumber
148 \let\makeLineNumber\makeRunningLineNumber

149 } 150

151 \setrunninglinenumbers\resetlinenumber

5.2 Pagewise line numbers

Difficult, if you think about it. The number has to be printed when there is 3 no means to know on which page it will end up, except through the aux-file.

My solution is really expensive, but quite robust.

With version v2.00 the hashsize requirements are reduced, because we 6 do not need one controlsequence for each line any more. But this costs some

computation time to find out on which page we are.

\makeLineNumber gets a hook to log the line and page number to the 9 aux-file. Another hook tries to find out what the page offset is, and

subtracts it from the counter \c@linenumber. Additionally, the switch \ifoddNumberedPage is set true for odd numbered pages, false otherwise.

152 \def\setpagewiselinenumbers{%
153 \let\theLineNumber\thePagewiseLineNumber
154 \let\c@linenumber\c@pagewiselinenumber
155 \let\makeLineNumber\makePagewiseLineNumber

156 } 157

158 \def\makePagewiseLineNumber{\logtheLineNumber\getLineNumber
159 \ifoddNumberedPage
160  \makeLineNumberOdd
161 \else
162  \makeLineNumberEven
163 \fi

164 }

12 Each numbered line gives a line to the aux file

\@LN{⟨line⟩}{⟨page⟩}

very similar to the \newlabel business, except that we need an arabic rep-15 resentation of the page number, not what there might else be in \thepage.

165 \def\logtheLineNumber{\protected@write\@auxout{}{%
166 \string\@LN{\the\c@linenumber}{\noexpand\the\c@page}}}

From the aux-file we get one macro \LN@P⟨page⟩ for each page with line numbers on it. This macro calls four other macros with one argument each.

18 These macros are dynamically defined to do tests and actions, to find out on

which page the current line number is located.

We need sort of a pointer to the first page with line numbers, initiallized 21 to point to nothing:

167 \def\LastNumberedPage{first}
168 \def\LN@Pfirst{\nextLN\relax}

The four dynamic macros are initiallized to reproduce themselves in an \xdef

169 \let\lastLN\relax  % compare to last line on this page
170 \let\firstLN\relax % compare to first line on this page
171 \let\pageLN\relax  % get the page number, compute the linenumber
172 \let\nextLN\relax  % move to the next page

During the end-document run through the aux-files, we disable \@LN. I may 3 put in a check here later, to give a rerun recommendation.

173 \AtEndDocument{\let\@LN\@gobbletwo}

Now, this is the tricky part. First of all, the whole definition of \@LN is grouped, to avoid accumulation on the save stack. Somehow

6 \csname⟨cs⟩\endcsname pushes an entry, which stays after an \xdef to that

⟨cs⟩.

If \LN@P⟨page⟩ is undefined, initialize it with the current page and line 9 number, with the pointer-to-the-next-page pointing to nothing. And the

macro for the previous page will be redefined to point to the current one.

If the macro for the current page already exists, just redefine the last-12 line-number entry.

Finally, save the current page number, to get the pointer to the following page later.

174 \def\@LN#1#2{{\expandafter\@@LN\csname LN@P#2\endcsname{#1}{#2}}}
175 \def\@@LN#1#2#3{\ifx#1\relax
176  \expandafter\@@@LN\csname LN@P\LastNumberedPage\endcsname#1
177  \xdef#1{\lastLN{#2}\firstLN{#2}\pageLN{#3}\nextLN\relax}%
178 \else
179  \def\lastLN##1{\noexpand\lastLN{#2}}%
180  \xdef#1{#1}%
181 \fi
182 \gdef\LastNumberedPage{#3}}

15 The previous page macro gets its pointer to the current one, replacing the \relax with the cs-token \LN@P⟨page⟩. In case of page number mismatch, TEX will trip here, because the argument string for \nextLN is not \relax.

18 I think it’s difficult to do a reasonable intercept here, because this is running in an \xdef. Does \PackageError{} work in there?

183 \def\@@@LN#1#2{{\def\nextLN\relax{\noexpand\nextLN\noexpand#2}%
184  \xdef#1{#1}}}

Now, to print a line number, we need to find the page, where it resides. This will most probably be the one where the last one came from or maybe the

3 next. However, it can be a completely different one. We maintain a cache, which is let to the last accessed pages macro. But for now it is initialized to expand \LN@first, where the poiner to the first numbered page has been

6 stored in.

185 \def\NumberedPageCache{\LN@Pfirst}

To find out on which page the current \c@linenumber is, we define the four dynamic macros to do something usefull and execute the current cache macro.

9 \lastLN is run first, testing if the line number in question may be on a later

page. If so, disable \firstLN, and go on to the next page via \nextLN.

186 \def\testLastNumberedPage#1{\ifnum#1<\c@linenumber
187  \let\firstLN\@gobble
188 \fi}

Else, if \firstLN finds out that we need an earlier page, we start over 12 from the beginning. Else, \nextLN will be disabled, and \pageLN will run

\gotNumberedPage with two arguments: the first line number on this page, and the page number.

189 \def\testFirstNumberedPage#1{\ifnum#1>\c@linenumber
190  \def\nextLN##1{\testNextNumberedPage\LN@Pfirst}%
191 \else
192  \let\nextLN\@gobble
193  \def\pageLN{\gotNumberedPage{#1}}%
194 \fi}

15 We start with \pageLN disabled and \nextLN defined to continue the search

with the next page.

195 \def\testNumberedPage{%
196 \let\lastLN\testLastNumberedPage
197 \let\firstLN\testFirstNumberedPage
198 \let\pageLN\@gobble
199 \let\nextLN\testNextNumberedPage
200 \NumberedPageCache

201 }

When we switch to another page, we first have to make sure that it is there. 18 If we are done with the last page, we probably need to run TEX again, but

for the rest of this run, the cache macro will just return two zeros. This saves a lot of time, for example if you have half of an aux-file from an aborted run,

21 in the next run the whole page-list would be searched in vain again and again

for the second half of the document.

If there is another page, we iterate the search.

202 \def\testNextNumberedPage#1{\ifx#1\relax
203  \global\def\NumberedPageCache{\gotNumberedPage00}%
204  \PackageWarningNoLine{lineno}%
205  {Linenumber reference failed,
206  \MessageBreak  rerun to get it right}%
207 \else
208  \global\let\NumberedPageCache#1%
209 \fi
210 \testNumberedPage

211 }

To separate the official hooks from the internals there is this equivalence, to Let’s see if

it finds the label on page 6, line 4, and back here on page 12, line 1.

hook in later for whatever purpose:

212 \let\getLineNumber\testNumberedPage

3 So, now we got the page where the number is on. We establish if we are on an odd or even page, and calculate the final line number to be printed.

213 \newif\ifoddNumberedPage

214

215 \def\gotNumberedPage#1#2{\oddNumberedPagefalse
216 \ifodd#2\relax\oddNumberedPagetrue\fi
217 \advance\c@linenumber 1\relax
218 \subtractlinenumberoffset{#1}%

219 }

You might want to run the pagewise mode with running line numbers, or 6 you might not. It’s your choice:

220 \def\runningpagewiselinenumbers{%
221 \let\subtractlinenumberoffset\@gobble

222 } 223

224 \def\realpagewiselinenumbers{%
225 \def\subtractlinenumberoffset##1{\advance\c@linenumber-##1\relax}%

226 } 227

228 \realpagewiselinenumbers

For line number references, we need a protected call to the whole procedure, with the requested line number stored in the \c@linenumber counter. This

9 is what gets printed to the aux-file to make a label:

229 \def\thePagewiseLineNumber{\protect
230  \getpagewiselinenumber{\the\c@linenumber}}%

And here is what happens when the label is refered to:

231 \def\getpagewiselinenumber#1{{%
232 \c@linenumber #1\relax\testNumberedPage
233 \thelinenumber

234 }}

A summary of all per line expenses:

3 CPU: The \output routine is called for each line, and the page-search is done.

DISK: One line of output to the aux-file for each numbered line

6 MEM: One macro per page. Great improvement over v1.02, which had one control sequence per line in addition. It blew the hash table after some five thousand lines.

9 5.3 Numbering modulo 5

Most users want to have only one in five lines numbered. \LineNumber is supposed to produce the outfit of the line number attached to the line, while

12 \thelinenumber is used also for references, which should appear even if they are not multiples of five.

235 \newcount\c@linenumbermodulo

236

237 \def\themodulolinenumber{{\@tempcnta\c@linenumber
238 \divide\@tempcnta\c@linenumbermodulo
239 \multiply\@tempcnta\c@linenumbermodulo
240 \ifnum\@tempcnta=\c@linenumber\thelinenumber\fi

241 }}

The user command to set the modulo counter:

242 \newcommand\modulolinenumbers[1][0]{%
243 \let\LineNumber\themodulolinenumber
244 \ifnum#1>1\relax
245 \c@linenumbermodulo#1\relax
246 \else\ifnum#1=1\relax
247 \def\LineNumber{\thelinenumber}%
248 \fi\fi

249 } 250

251 \setcounter{linenumbermodulo}{5}
252 \modulolinenumbers[1]

6 Package options 1

There is a bunch of package options, all of them executing only user com- 2 mands (see below). 3

Options left (right) put the line numbers on the left (right) margin. 4 This works in all modes. left is the default. 5

253 \DeclareOption{left}{\leftlinenumbers*}

254

255 \DeclareOption{right}{\rightlinenumbers*}

Option switch (switch*) puts the line numbers on the outer (inner) margin 6 of the text. This requires running the pagewise mode, but we turn off the 7 page offset subtraction, getting sort of running numbers again. The pagewise 8 option may restore true pagewise mode later. 9

256 \DeclareOption{switch}{\setpagewiselinenumbers
257  \switchlinenumbers
258  \runningpagewiselinenumbers}

259

260 \DeclareOption{switch*}{\setpagewiselinenumbers
261  \switchlinenumbers*%
262  \runningpagewiselinenumbers}

The options pagewise and running select the major linenumber mechanism. 10 running line numbers refer to a real counter value, which can be reset for 11 any paragraph, even getting multiple paragraphs on one page starting with 12 line number one. pagewise line numbers get a unique hidden number within 13 the document, but with the opportunity to establish the page on which they 14 finally come to rest. This allows the subtraction of the page offset, getting 15 the numbers starting with 1 on top of each page, and margin switching in 16 twoside formats becomes possible. The default mode is running. 17

The order of declaration of the options is important here pagewise must 18 come after switch, to overide running pagewise mode. running comes last, 19 to reset the running line number mode, e.g, after selecting margin switch 20 mode for pagewise running. Once more, if you specify all three of the options 21 [switch,pagewise,running], the result is almost nothing, but if you later 22 say \pagewiselinenumbers, you get margin switching, with real pagewise 23 line numbers. 24

263 \DeclareOption{pagewise}{\setpagewiselinenumbers
264  \realpagewiselinenumbers}

265

266 \DeclareOption{running}{\setrunninglinenumbers}

1 And finally, the option modulo causes only those linenumbers to be printed 2 which are multiples of five.

267 \DeclareOption{modulo}{\modulolinenumbers\relax}

268

269 \ProcessOptions

3 7 The final touch

4 There is one deadcycle for each line number.

270 \advance\maxdeadcycles 100

271

272 \endinput

5 8 The user commands

6 The user command to turn on and off line numbering are

 7 \linenumbers

8 Turn on line numbering in the current mode.

 9 \linenumbers*

10 and reset the line number to 1.

11 \linenumbers[⟨number⟩]

12 and start with ⟨number⟩.

13 \nolinenumbers

14 Turn off line numbering.

15 \runninglinenumbers*[⟨number⟩]

16 Turn on running line numbers, with the same optional arguments as 17 \linenumbers. The numbers are running through the text over page-18 breaks. When you turn numbering off and on again, the numbers will 19 continue, except, of cause, if you ask to reset or preset the counter.

20 \pagewiselinenumbers

21 Turn on pagewise line numbers. The lines on each page are numbered 22 beginning with one at the first pagewise numbered line.

\resetlinenumber[⟨number⟩]  1

Reset [Set] the line number to 1 [⟨number⟩]. 2

\setrunninglinenumbers  3

Switch to running line number mode. Do not turn it on or off. 4

\setpagewiselinenumbers  5

Switch to pagewise line number mode. Do not turn it on or off. 6

\switchlinenumbers*  7

Causes margin switching in pagewise modes. With the star, put the 8 line numbers on the inner margim. 9

\leftlinenumbers*  10
\rightlinenumbers*  11

Set the line numbers in the left/right margin. With the star this works 12 for both modes of operation, without the star only for the currently 13 selected mode. 14

\runningpagewiselinenumbers  15

When using the pagewise line number mode, do not subtract the page 16 offset. This results in running line numbers again, but with the possibil- 17 ity to switch margins. Be careful when doing line number referencing, 18 this mode status must be the same while setting the paragraph and 19 during references. 20

\realpagewiselinenumbers  21
Reverses the effect of \runningpagewiselinenumbers.  22
\modulolinenumbers[⟨number⟩]  23

Give a number only to lines which are multiples of [⟨number⟩]. 24 If ⟨number⟩ is not specified, the current value in the counter 25 linenumbermodulo is retained. ⟨number⟩=1 turns this off without 26 changing linenumbermodulo. The counter is initialized to 5. 27

\linelabel  28

Set a \linelabel{⟨foo⟩} to the line number where this commands is 29 in. Refer to it with the L^{A}TEX referencing commands \ref{⟨foo⟩} and 30

\pageref{⟨foo⟩}.  31

1 The commands can be used globally, locally within groups or as environ-2 ments. It is important to know that they take action only when the \par is 3 executed. The \end{⟨mode⟩linenumbers} commands provide a \par. Ex-4 amples:

 5  {\linenumbers ⟨text⟩ \par}

6

 7  \begin{linenumbers}

8 ⟨text⟩

 9  \end{linenumbers}

10

11  ⟨paragraph⟩ {\linenumbers\par}

12

13  \linenumbers

14 ⟨text⟩ \par

15  \nolinenumbers

16

17  \linenumbers
18  ⟨paragraph⟩ {\nolinenumbers\par}

19 8.1 Customization hooks

20 There are several hooks to customize the appearance of the line numbers, 21 and some low level hooks for special effects.

22 \thelinenumber

23 This macro should give the representation of the line number in the 24 L^{A}TEX-counter linenumber. The default is provided by L^{A}TEX:

25  \arabic{linenumber}
26 \makeLineNumberLeft

27 This macro is used to attach a line number to the left of the text page. 28 This macro should fill an \hbox to 0pt which will be placed at the 29 left margin of the page, with the reference point aligned to the line to 30 which it should give a number. Please use the macro \LineNumber to 31 refer to the line number.

32 The default definition is

33  \hss\linenumberfont\LineNumber\hskip\linenumbersep
34 \makeLineNumberRight

Like \makeLineNumberLeft, but for line numbers on the right margin. 1 The default definition is 2

    \linenumberfont\hskip\linenumbersep\hskip\textwidth  3
    \hbox to\linenumberwidth{\hss\LineNumber}\hss  4
\linenumberfont  5

This macro is initialized to 6

    \normalfont\tiny\sffamily  7
\linenumbersep  8

This dimension register sets the separation of the linenumber to the 9 text. Default value is 10pt. 10

\linenumberwidth  11

This dimension register sets the width of the line number box on the 12 right margin. The distance of the right edge of the text to the right 13

edge of the line number is \linenumbersep + \linenumberwidth. The  14

default value is 10pt. 15

\theLineNumber (for wizards)  16

This macro is called for printing a \newlabel entry to the aux-file. 17 Its definition depends on the mode. For running line numbers it’s just 18 \thelinenumber, while in pagewise mode, the page offset subtraction 19 is done in here. 20

\makeLineNumber (for wizards)  21

This macro produces the line numbers. The definition depends 22 on the mode. In the running line numbers mode it just expands 23

\makeLineNumberLeft.  24

\LineNumber (for wizards) 25 This macro is called by \makeLineNumber to typeset the line number. 26 This hook is changed by the modulo mechanism. 27