Debian Codegraph @

texmf-dist/tex/latex/lineno/lineno.sty

raw
1 \iffalse; awk '/S[H]ELL1/' lineno.sty|sh;exit;
2 ... see bottom for .tex documentation ...
3
4 Macro file lineno.sty for LaTeX: attach line numbers, refer to them.
5 \fi
6 \def\fileversion{v5.9} \def\filedate{2026/03/08} %VERSION
7
8 %%% Copyright 1995--2003 Stephan I. Böttcher
9 %%% Copyright 2002--2005 Uwe Lück for versions 4.x and code from former Ednotes
10 %%% Copyright 2021--2025 Karl Wette for versions 5.x
11 %%%
12 %%% This file can be redistributed and/or modified under
13 %%% the terms of the LaTeX Project Public License; either
14 %%% version 1.3a of the License, or any later version.
15 %%% The latest version of this license is in
16 %%% http://www.latex-project.org/lppl.txt
17 %%% We did our best to help you, but there is NO WARRANTY.
18 %
19 %%% $Id: lineno.sty,v 3.14.2.2 2004/09/13 19:30:39 stephan Exp $ %% was v4.00.
20 % \title{\texttt{\itshape
21 %% %% (UL 2004/10/09:) Italic TT is evil
22 %% %% ... or nice front page layout!?
23 %%
24 % lineno.sty \ \fileversion\ \filedate
25 % \unskip}\\\ \\
26 % A \LaTeX\ package to attach
27 % \\ line numbers to paragraphs
28 % \unskip}\author{%
29 % Stephan I. Böttcher
30 % \\ Uwe Lück
31 % \\ Karl Wette
32 % \unskip}\date{%
33 % \url{https://github.com/latex-lineno/lineno}
34 % \\}
35 %
36 % \documentclass[a4paper,12pt]{article}%D
37 % \usepackage{lineno}%D
38 % \usepackage{hyperref}%D
39 %% %% (New v4.00)
40 % \catcode`\_\active\let_~
41 %% %% Beware math!? (/New v4.00)
42 % \def~{\verb~}
43 % \let\lessthan<
44 % \def\angle#1{$\langle${\itshape#1}\/$\rangle$}
45 % \catcode`\|\active
46 %% (New v4.1: \tt star; in box anyway.)
47 % \def|#1{\ttfamily\string#1}
48 %% \def|#1{{\ttfamily\string#1}}
49 %% (/New v4.1)
50 % \newenvironment{code}
51 % {\par\runninglinenumbers
52 % \modulolinenumbers[1]%
53 % \linenumbersep.3em
54 % \footnotesize
55 % \def\linenumberfont
56 % {\normalfont\tiny\itshape}}
57 % {}
58 %% %% (New v4.00)
59 % {\makeatletter \gdef\scs#1{\texttt
60 % {\protect\@backslashchar#1}}}
61 % \def\old{\par\footnotesize}
62 %% %% (/New v4.00)
63 %% %% (New v4.1)
64 % {\catcode`\/\active
65 % \gdef\path{\begingroup\catcode`\/\active
66 % \let/\slash\dopath}
67 % \gdef\dopath#1{\slash\unpenalty#1\endgroup}}
68 %% %% (/New v4.1)
69 %
70 % \begin{document}%D
71 %% \DocInput{lineno}%D
72 % \pagewiselinenumbers
73 % \maketitle
74 % \pagestyle{headings}
75 % \tableofcontents
76 % \sloppy
77 %
78 %% %% New v4.00: `...section{%' + \unskip
79 % \section{%
80 % Introductions
81 %% %% New v4.00: `s'
82 % \unskip}
83 %
84 % (New v4.00) Parts of former first section
85 % have been rendered separate subsections for package
86 % version_v4.00. (/New v4.00)
87 %
88 % \subsection{%
89 % Introduction to versions $\textrm{v}\lessthan4$
90 % \unskip}
91 %
92 % This package provides line numbers on paragraphs.
93 % After \TeX\ has broken a paragraph into lines there will
94 % be line numbers attached to them, with the possibility to
95 % make references through the \LaTeX\ ~\ref~, ~\pageref~
96 % cross reference mechanism. This includes four issues:
97 % \begin{itemize}
98 % \item attach a line number on each line,
99 % \item create references to a line number,
100 % \item control line numbering mode,
101 % \item count the lines and print the numbers.
102 % \end{itemize}
103 % The first two points are implemented through patches to
104 % the output routine. The third by redefining ~\par~, ~\@par~
105 % and ~\@@par~. The counting is easy, as long as you want
106 % the line numbers run through the text. If they shall
107 % start over at the top of each page, the aux-file as well
108 % as \TeX s memory have to carry a load for each counted line.
109 %
110 % I wrote this package for my wife Petra, who needs it for
111 % transcriptions of interviews. This allows her to
112 % precisely refer to passages in the text. It works well
113 % together with ~\marginpar~s, but not too well with displaymath.
114 % ~\footnote~s are a problem, especially when they
115 % are split, but we may get there.
116 % (New v4.00 UL) Version v4.00 overcomes the problem, I believe.
117 % (/UL /New v4.00)
118 %
119 % lineno.sty works
120 % surprisingly well with other packages, for
121 % example, ~wrapfig.sty~. So please try if it
122 % works with whatever you need, and if it does,
123 % please tell me, and if it does not, tell me as
124 % well, so I can try to fix it.
125 %
126 % \subsection{%
127 % Introduction to versions v4.00ff. (UL)
128 % \unskip}
129 %
130 % ~lineno.sty~ has been maintained by Stephan until version_v3.14.
131 % From version_v4.00 onwards, maintenance is shifting towards
132 % Uwe Lück (UL), who is the author of v4\dots code and of v4\dots
133 % changes in documentation. This came about as follows.
134 %
135 % Since late 2002, Christian Tapp and Uwe Lück have employed
136 % ~lineno.sty~ for their ~ednotes.sty~, a package supporting
137 % critical editions, while you find ~ednotes.sty~ and surrounding files in
138 % CTAN folder \path{macros/latex/contrib/ednotes}.
139 %
140 % Soon, some weaknesses of ~lineno.sty~ showed up, mainly since
141 % Christian's critical editions (using ~ednotes.sty~) needed lots
142 % of ~\linelabel~s and footnotes. (These weaknesses are due to
143 % weaknesses of \LaTeX's ~\marginpar~ mechanism that Stephan
144 % used for ~\linelabel~.) So we changed some ~lineno.sty~
145 % definitions in some extra files, which moreover offered new
146 % features. We sent these files to Stephan, hoping he would take
147 % the changes into ~lineno.sty~. However, he was too short of time.
148 %
149 % Writing a TUGboat article on Ednotes in 2004, we hoped to
150 % reduce the number of files in the Ednotes bundle and so asked
151 % Stephan again. Now he generously offered maintenance to me, so
152 % I could execute the changes on my own.
153 %
154 % The improvements are as follows:
155 % \begin{itemize}\item
156 % [(i)] Footnotes placement approaches intentions better
157 % (footnotes formerly liked to pile up at late pages).
158 % \item
159 % [(ii)] The number of ~\linelabel~s in one paragraph is no longer
160 % limited to 18.
161 % \item
162 % [(iii)] ~\pagebreak~, ~\nopagebreak~, ~\vspace~, and the star
163 % and optional versions of ~\\~ work as one would expect
164 % (section_\ref{s:MVadj}). %% Added for v4.1
165 % \item
166 % [(iv)] A command is offered which chooses the first line number
167 % to be printed in the margin
168 % (subsection_\ref{ss:Mod}). %% Added for v4.1
169 % \item
170 % [(v)] (New v4.1) \LaTeX\ tabular environments (optionally)
171 % get line numbers as well, and you can refer to them in the
172 % usual automatic way. (It may be considered a shortcoming that,
173 % precisely, \emph{rows} are numbered, not lines.---See
174 % subsection_\ref{ss:Tab}.)
175 % \item
176 % [(vi)] We are moving towards referring to math items
177 % (subsection_\ref{ss:MathRef} and the hooks in
178 % subsection_\ref{ss:LL}).
179 % (/New v4.1)
180 % \end{itemize}
181 % (Thanks to Stephan for making this possible!)
182 %
183 %% Unpublish:
184 %% You may trace the earlier developments of these changes by
185 %% requesting our files ~linenox0.sty~, ~linenox1.sty~, and
186 %% ~lnopatch.sty~. Most of our changes have been in ~linenox0.sty~.
187 %% Our ~linenox1.sty~ has extended ~linenox0.sty~ for one single
188 %% purpose in a not very stable way.
189 %%% (See ~\linenumberpar~ below).
190 %% ~lnopatch.sty~ has done the first line number thing referred
191 %% to in case_(iv) up to now.
192 %% (New v4.1)
193 %% Case_(v) earlier was provided by our ~edtab02.sty~---now
194 %% called ~edtable.sty~.
195 %% (/New v4.1)
196 %
197 % Ednotes moreover profits from Stephan's offer with regard
198 % to the documentation of our code which yielded these
199 % improvements formerly. This documentation now becomes
200 % printable, being part of the ~lineno.sty~ documentation.
201 %
202 % Of course, Stephan's previous ~lineno.sty~ versions were a great
203 % and ingenious work and exhibit greatest \TeX pertise. I never
204 % could have done this. I learnt a lot in studying the code when
205 % Christian pointed out strange output results and error
206 % messages, and there are still large portions of ~lineno.sty~
207 % which I don't understand (consider only pagewise numbering of
208 % lines). Fortunately, Stephan has offered future help if
209 % needed.---My code for attaching line numbers to \emph{tabular
210 % environments} (as mentioned above, now still in
211 % ~edtable.sty~) %% %% TODO
212 % developed from macros which Stephan and Christian experimented
213 % with in December 2002. Stephan built the basics.
214 % (However, I then became too proud to follow his advice only to
215 % use and modify ~longtable.sty~.)
216 %
217 % There are some issues concerning use of counters on which I
218 % don't agree with Stephan and where I would like to change the
219 % code if ~lineno.sty~ is ``mine'' as Stephan offered. However,
220 % Stephan is afraid of compatibility problems from which, in
221 % particular, his wife could suffer in the near future. So he
222 % demanded that I change as little as possible for my first
223 % version. Instead of executing changes that I plan I just offer
224 % my opinions at the single occasions. I hope to get in touch
225 % this way with users who consider subtle features vital which I
226 % consider strange.
227 %
228 % On the other hand, the sections on improvements of the
229 % implementation have been blown up very much and may be tiring
230 % and litte understandable for mere \emph{users}. These users
231 % may profit from the present presentation just by jumping to
232 % sections_\ref{s:Opts} and_\ref{s:UserCmds}. There is a user's
233 % guide ulineno.tex which may be even more helpful, but it has
234 % not been updated for a while. %% TODO
235 %
236 % \subsection{%
237 % Availability
238 % \unskip}
239 %
240 % In case you have found the present file otherwise than from
241 % CTAN: A recent version and documentation of this package
242 % should be available from CTAN folder
243 % \path{macros/latex/contrib/lineno}.
244 % Or mail to one of the addresses at top of file.
245 %
246 % \subsection{%
247 % Introductory code
248 % \unskip}
249 %
250 % This style option is written for \LaTeXe, November 1994 or later,
251 % since we need the ~\protected@write~ macro.
252 %
253 % (New v4.00) And we use ~\newcommand*~ for
254 % controlling length of user macro arguments, which has been
255 % available since December 1994.
256 % (/New v4.00)
257 %%
258
259 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
260 %% [1994/11/04]
261 \ProvidesPackage{lineno}
262 [\filedate\space line numbers on paragraphs \fileversion]
263 %%
264 \RequirePackage{etoolbox}
265 \RequirePackage{kvoptions}
266 %% History of versions:
267 %% v1.00 1995/03/31 SIB: first release for Petra's interview transcriptions
268 %% v1.01 1995/10/28 SIB: added ~pagewise~ mode
269 %% v1.02 1995/11/15 SIB: added ~modulo~ option
270 %% v1.03 1995/12/05 SIB: pagewise: try to reduce the hash-size requirements
271 %% v2.00 1995/12/06 SIB: .. it works, new user interface
272 %% v2.01 1996/09/17 SIB: put into CVS
273 %% v2.02 1997/03/17 SIB: add: \@reinserts, for footnotes
274 %% v2.04 1998/03/09 SIB: add: linenomath environment
275 %% v2.05 1998/04/26 SIB: add: prevgraf test
276 %% v2.06 1999/03/02 SIB: LPPL added
277 %% v3.00 1999/06/11 SiB: include the extension in the main file
278 %% v3.01 1999/08/28 SiB: \@reinserts -> \holdinginserts
279 %% v3.02 2000/03/10 SiB: \@LN@output
280 %% v3.03 2000/07/01 SiB: \@LN@ExtraLabelItems, hyperref
281 %% v3.04 2000/12/17 SiB: longtable compatibility.
282 %% v3.05 2001/01/02 SiB: [fleqn] detection.
283 %% v3.05a 2001/01/04 SiB: [fleqn] detection reverted for eqnarray.
284 %% v3.06 2001/01/17 SiB: [twocolumn] mode support.
285 %% v3.07 2001/07/30 SiB: [hyperref] option obsoleted.
286 %% v3.08 2001/08/02 SiB: linenomath wrapping for \[ \]
287 %% v3.08a 2001/08/04 SiB: linenomath wrapping for \[ \] fixed
288 %% v3.08b 2002/01/27 SiB: enquotation typo fix
289 %% v3.09 2003/01/14 SIB: hyperref detection fix
290 %% v3.10 2003/04/15 FMi: \MakeLineNo fix for deep boxes
291 %% v3.10a 2003/11/12 Uwe Lück: \lineref typo fix
292 %% v4.00 2004/09/02 UL: included linenox0, linenox1, lnopatch code with
293 %% documentation, usually indicated by `New v4.00';
294 %% discussions of old code, indicated by `UL';
295 %% LPPL v.1 -> LPPL v1.3, `program' -> `file';
296 %% first lines with \filedate and \fileversion,
297 %% according nawk lines; `November 1994 or later',
298 %% some earlier documentation typos (including a few
299 %% bad minus signs), { -> {% and } -> \unskip} at
300 %% line ends (so, e.g., alignment in TOC works); \scs.
301 %% 2004/09/03 UL: removed everything which indicated that the
302 %% present file were named `lineno4.sty'.
303 %% v4.1 2004/09/19 UL: Inserted Stephan's identification line, removed
304 %% some TODOs and remarks from v4.00.
305 %% 2004/10/04 UL: Added acknowledgement for Daniel Doherty;
306 %% `(New v4.00)' with [|\firstlinenumber]; changed
307 %% TODOs; Refining -> Redefining (\vadjust).
308 %% 2004/10/05 UL: ednmath0 -> mathrefs; \catcode`\~ -> \active;
309 %% \path; refined section on options `mathrefs';
310 %% changes in introduction.
311 %% 2004/10/06 UL: Changed/removed TODOs, e.g., for edtable.sty.
312 %% 2004/10/11 UL: Reminders: linenox0/1/lnopatch.sty obsolete;
313 %% \tt star in list of commands.
314 %% 2004/10/12 UL: Corrected blank lines in lineno.tex.
315 %% 2004/10/19 UL: Fixed minor typos; remark on \if@LN@edtable.
316 %% v4.1a 2004/11/07 UL: LPPL v1.3a.
317 %% v4.1b 2004/11/13 UL: Comment on \outputpenalty values.
318 %% v4.1c 2005/01/10 UL: Contact via http.
319 %% v4.11 2005/02/20 UL: Error message with \linelabel when not numbering.
320 %% 2005/03/07 UL: Removed \linelabel from ss:Tab heading, consider
321 %% marginal line numbers as well, revised ss:Tab.
322 %% Added a few lines on missing explanations to
323 %% s:UserCmds. Corrected some code alignments.
324 %% 2005/03/08 UL: Require recent edtable.sty.
325 %%
326
327 %% v4.2 2005/03/21 UL: "Physical page" counter works with \include.
328 %% 2005/04/17 UL: Raised options section above extensions section
329 %% (v4.00 disabled `displaymath' option);
330 %% third arg for \@ifundefined{mathindent};
331 %% "bunch of options";
332 %% 2005/04/24 UL: compatibility with tamefloats; vplref.sty.
333 %% 2005/04/25 UL: \number -> \the; wondered -> $$; subsec. appbas;
334 %% CrtlLN sec -> subsec.; \newcommand* wherever ...;
335 %% doc. on `other output routines' and `addpageno'
336 %% (this changed from `varioref').
337 %% 2005/04/27 UL: =1\relax -> =\@ne, 0\relax ..., \hb@xt@,
338 %% \ifx\@@par\@@@par -> \ifLineNumbers, typos,
339 %% \pagestyle{headings}, LaTeX -> \LaTeX.
340 %% v4.21 2005/04/28 UL: linenomath section: removed wrong \else's,
341 %% \holding...: \thr@@, \@LN@outer@holdins, \global.
342 %% v4.22 2005/05/01 UL: \unvbox\@outputbox; \@LN@col without #1,
343 %% 2005/05/08 UL: global/local \internall..., \resetl... global,
344 %% shortened discussions of this and of \newcounter.
345 %% 2005/05/09 UL: corr.: doc. typo, version history, bad lines;
346 %% percent; \chardef for modulo,
347 %% \value{firstlinenumber}.
348 %% v4.3 2005/05/10 UL: \@backslashchar -> \char`\\ in \scs.
349 %% 2005/05/11 UL: \linenumbers sets ...outer@holdins; tidied up
350 %% documentation regarding earlier versions.
351 %% 2005/05/12 UL: `linenomath' without spurious number above;
352 %% `displaymath' default; edmac homepage ->
353 %% ednotes.sty.de.vu, \endlinenomath without
354 %% numbers: no change of \holdinginserts;
355 %% \linelabel doesn't go to .aux or mark,
356 %% hyperref detected; undone 2005/05/10 (bad mark).
357 %% 2005/05/13 UL: Reworked hyperref detection (new subsec.).
358 %% 2005/05/15 UL: More typo fixes, corrected terrible confusions in
359 %% the discussion (v4.22/v4.3) of \new/\stepcounter;
360 %% new subsec. in `Line number ...'; another
361 %% implementation of `hyperref' detection.
362 %% 2005/05/16 UL: Final minor changes.
363 %% v4.31b /06/14 UL: Extended explanation of \firstlinenumbers
364 %% and package options; \@LN@ifgreat@critical;
365 %% \modulolinenumbers*. Sent to Ednotes.news only.
366 %% v4.31 2005/06/15 UL: \modulolinenumbers* with \firstlinenumber{1};
367 %% " -> ``/''; more doc. on \firstlinenumber .
368 %% 2005/06/20 UL: Typo fix.
369 %% 2005/10/01 UL: Warning about \mod...* with pagewise mode.
370 %% v4.31a /10/02 UL: Minor changes of appearance of doc., e.g.,
371 %% \[ for $$.
372 %% v4.32b /10/15 UL: Support for \addvspace; removed comments that
373 %% had been invisible already for some time;
374 %% made clear with which environments the
375 %% linenomath environment is not needed.
376 %% v4.32ab /10/15 UL: Observe \if@nobreak with support for \addvspace.
377 %% v4.32 2005/10/17 UL: Just made it official and sent it to CTAN.
378 %% v4.33b /10/23 UL: \if@nobreak\nobreak\fi -> \nobreak .
379 %% v4.33ab /10/24 UL: \LineNoLaTeXOutput without \@tempswafalse;
380 %% undid v4.22: \[unv]box\@outputbox (space is OK,
381 %% \unvbox pushes short columns down); \@LN@kern@z@ .
382 %% v4.4b 2005/10/24 UL: Another tidying-up of the discussion of
383 %% \stepcounter{linenumber}; \@LN@screenoff@pen
384 %% replaces \@LN@kern@z@, \@LN@depthbox .
385 %% v4.4 2005/10/27 UL: Just made official for CTAN.
386 %% v4.4a 2005/10/29 UL: Undid change of discussion of
387 %% \stepcounter{linenumber} (confusion again).
388 %% v4.41 2005/11/02 UL: Raised \CheckCommand*.
389 %% v5.0 2022/07/30 KW: Merge in `linenoamsmath' patches
390 %% v5.1 2023/01/19 KW: Patch `amsmath` with \AddToHook if possible.
391 %% v5.2 2023/05/19 KW: Support `amsmath` option `\allowdisplaybreaks`.
392 %% v5.3 2023/05/20 KW: Handle special value of \prevdepth=-1000pt.
393 %% Add package options `sep' and `width' for
394 %% setting line number separation and width.
395 %% Add `twocolumn` support for `bframe` env.
396 %% v5.4 2025/01/29 KW: Option to allow ~\linelabel~ with ~\nolinenumbers~.
397 %% v5.5 2025/05/13 KW: Protect \\ with \protect instead of \DeclareRobustCommand.
398 %% v5.6 2026/02/11 KW: Work around a compatibility issue of twocolumn mode
399 %% againt LaTeX2e 2026-06-01 PL2 and later
400 %% v5.7 2026/02/16 KW: Adjust twocolumn mode compatibility fix after regression
401 %% v5.8 2026/02/16 KW: Fix issue with twocolumn in version 5.7
402 %% v5.9 2026/03/08 KW: Fix hook use introduced in v5.6
403 %%
404 %% Acknowledgements:
405 %% v3.06: Donald Arseneau, pointed to mparhack.sty.
406 %% v3.07+: Frank Mittelbach, points out inconsistencies in the
407 %% user interface.
408 %% v3.10: Frank Mittelbach \MakeLineNo fix for deep boxes
409 %% v4.00: Daniel Doherty points out clash of \pagewise... with resetting
410 %% page number.
411 %% v4.21: Much testing work by Erik Luijten.
412 %% v4.3: `displaymath' default by Erik Luijten's suggestion.
413 %% v4.31: \modulolinenumbers* is an idea of Hillel Chayim Yisraeli's.
414 %% v4.32: Support for \addvspace due to Saravanan M.'s observation.
415 %% v4.33: Different support for \addvspace due to bug reports by
416 %% Saravanan M.'s and David Josef Dev.
417 %% v4.4: David Josef Dev points out that \kern\z@ after a paragraph
418 %% tends to place its final baseline wrongly.
419 %% v5.3: Yukai Chou and Frank Mittelbach for patches to handle special
420 %% value of \prevdepth=-1000pt, and add `twocolumn` support for
421 %% `bframe` env.
422 %% v5.6-9 Akira Yokosawa for fix for compatibility issue of twocolumn
423 %% mode againt LaTeX2e 2026-06-01 PL2 and later, @bgvoisin
424 %% and @benebrue for reporting subsequent regressions, and
425 %% Akira Yokosawa and Frank Mittelbach for further bugfixes.
426 %
427 %
428 % \section{%
429 % Put the line numbers to the lines
430 % \unskip}
431 %
432 % (New v4.00) This section contained the most
433 % basic package code previously. For various purposes of
434 % version_4\dots, much of these basics have been to be modified.
435 % Much of my (UL's) reasoning on these modifications has been to
436 % be reported. Sorry, the present section has been blown up
437 % awfully thus and contains ramifications that may be difficult
438 % to trace. We add some ~\subsection~ commands in order to cope
439 % with the new situation. (/New v4.00)
440 %
441 % \subsection{%
442 % Basic code of \texttt{lineno.sty} \scs{output}
443 % \unskip}\label{ss:output}
444 %
445 % The line numbers have to be attached by the output
446 % routine. We simply set the ~\interlinepenalty~ to $-100000$.
447 % The output routine will be called after each line in the
448 % paragraph, except the last, where we trigger by ~\par~.
449 % The ~\linenopenalty~ is small enough to compensate a bunch of
450 % penalties (e.g., with ~\samepage~).
451 %
452 % (New v3.04) Longtable uses
453 % ~\penalty~$-30000$. The lineno penalty range was
454 % shrunk to $-188000 \dots -32000$. (/New v3.04)
455 % (New v4.00) New values are listed below (11111f.). (/New v4.00)
456
457 \newcount\linenopenalty\linenopenalty=-100000
458
459 %% TODO v4.4+:
460 % (UL) Hm. It is never needed below
461 % that this is a counter. ~\def\linenopenalty{-100000\relax}~
462 % would do. (I guess this consumes more memory, but it
463 % is more important to save counters than to save memory.)
464 % I was frightened by ~-\linenopenalty~ below, but indeed
465 % \TeX\ interprets the string ~--100000~ as 100000.
466 % Has any user or extension package writer ever called
467 % ~\linenopenalty=xxx~, or could I really change this?---The
468 % counter is somewhat faster than the macro. Together with the
469 % compatibility question this seems to support keeping the
470 % counter. (???)
471 %% Note that Stephan chose ~\mathchardef~ below,
472 %% so his choice above seems to have been deliberate.
473 %% <- no point, \mathchardef token is fast.
474 % (/UL)
475
476 \mathchardef\linenopenaltypar=32000
477
478 % So let's make a hook to ~\output~, the direct way. The \LaTeX\
479 % macro ~\@reinserts~ puts the footnotes back on the page.
480 %
481 % (New v3.01) ~\@reinserts~ badly
482 % screws up split footnotes. The bottom part is
483 % still on the recent contributions list, and the
484 % top part will be put back there after the bottom
485 % part. Thus, since lineno.sty does not play well
486 % with ~\inserts~ anyway, we can safely experiment
487 % with ~\holdinginserts~, without making things
488 % much worse.
489 %
490 % Or that's what I thought, but: Just activating
491 % ~\holdinginserts~ while doing the ~\par~ will
492 % not do the trick: The ~\output~ routine may be
493 % called for a real page break before all line
494 % numbers are done, and how can we get control
495 % over ~\holdinginserts~ at that point?
496 %
497 % Let's try this: When the ~\output~ routine is
498 % run with ~\holdinginserts=3~ for a real page
499 % break, then we reset ~\holdinginserts~ and
500 % restart ~\output~.
501 %
502 % Then, again, how do we keep the remaining
503 % ~\inserts~ while doing further line numbers?
504 %
505 % If we find ~\holdinginserts~=$-3$ we activate it again
506 % after doing ~\output~. (/New v3.01)
507 %
508 % (New v3.02) To work with
509 % multicol.sty, the original output routine is now
510 % called indirectly, instead of being replaced.
511 % When multicol.sty changes ~\output~, it is a
512 % toks register, not the real thing. (/New v3.02)
513 %
514 % (New v4.00) Two further complications are added.
515 %%
516 %% TODO v4.3+: Or three, ~\@nobreakfalse~ after ~\MakeLineNo~
517 %% for getting rid of ~\@LN@nopagebreak~.
518 % \begin{itemize}\item
519 % [(i)] Problems with footnotes formerly resulted from
520 % \LaTeX's ~\@reinserts~ in ~\@specialoutput~ which Stephan's
521 % ~\linelabel~ called via the ~\marginpar~ mechanism.
522 % \item
523 % [(ii)] \LaTeX\ commands using ~\vadjust~ formerly didn't work
524 % as one would have hoped. The problem is as follows:
525 % Printing the line number results from
526 % a box that the output routine inserts at the place of the
527 % ~\interlinepenalty~. ~\vadjust~ items appear \emph{above} the
528 % ~\interlinepenalty~ (\TeX book p._105). So ~\pagebreak~, e.g.,
529 % formerly sent the line number to the next page, while the
530 % penalty from ~\nopagebreak~ could not tie the following line,
531 % since it was screened off by the line number box.---Our trick
532 % is putting the ~\vadjust~ items into a list macro from which
533 % the output routine transfers them into the vertical list,
534 % below the line number box.
535 % \end{itemize}
536 % In this case_(ii), like in case_(i), footnotes would suffer
537 % if ~\holdinginserts~ were non-positive. Indeed, in both
538 % cases_(i) and_(ii) we tackle the footnote problem by extending
539 % that part of Stephan's output routine that is active when
540 % ~\holdinginserts~ is positive. This extension writes the line
541 % number ~\newlabel~ to the .aux file (which was formerly done
542 % under $~\holdinginserts~=-3$) and handles the ~\vadjust~
543 % items.---To trigger ~\output~ and its ~\linelabel~ or, resp.,
544 % ~\vadjust~ part, the list of signal penalties started
545 % immediately before is increased here (first for ~\linelabel~,
546 % second for postponed ~\vadjust~ items):
547
548 \mathchardef\@Mllbcodepen=11111
549 \mathchardef\@Mppvacodepen=11112
550
551 % (/New v4.00) (New v4.2) David Kastrup urges to use a private
552 % name instead of ~\the\output~ (LaTeX-L-list). Otherwise an
553 % ~\output~ routine loaded later and using ~\newtoks\output~
554 % again may get lost entirely. So we change use of ~\@LN@output~,
555 % using it for the former purpose. Reference to what appeared
556 % with the name of ~\output~ here lasts for a few lines and then
557 % is given away.
558
559 \let\@tempa\output
560 \newtoks\output
561 \let\@LN@output\output
562 \output=\expandafter{\the\@tempa}
563
564 % Now we add two cases to Stephan's output routine. (New v4.00)
565
566 \@tempa={%
567 % (/New 4.2)
568 \LineNoTest
569 \if@tempswa
570 %%
571 %% (UL) Learnt that even in def.s blank line means ~\par~.
572 %% to leave visual space in present file with having a
573 %% blank line neither in present nor in .tex file,
574 %% use double comment mark (`%%'). (/UL)
575 %%
576 % (New v4.00)
577 % We insert recognition of waiting ~\linelabel~ items---
578 %%
579 \ifnum\outputpenalty=-\@Mllbcodepen
580 \WriteLineNo
581 %%
582 % ---and of waiting ~\vadjust~ items:
583 %%
584 \else
585 \ifnum\outputpenalty=-\@Mppvacodepen
586 \PassVadjustList
587 \else
588 %%
589 %% Now we give control back to Stephan.
590 % (/New v4.00) (New v4.2) Outsource ``Standard'' output
591 % ---which occurs so rarely---to subsection_\ref{ss:LLO}:
592 %%
593 \LineNoLaTeXOutput
594 % (/New v4.2) (New v4.00)
595 % Two new ~\fi~s for the ~\linelabel~ and ~\vadjust~ tests---
596 %%
597 \fi
598 \fi
599 %%
600 % ---and the remaining is
601 %%%next three lines are
602 % Stephan's code again:
603 % (/New v4.00)
604 %%
605 \else
606 \MakeLineNo
607 \fi
608 }
609
610 % (New v4.00) Our new macros
611 % ~\WriteLineNo~ and ~\PassVadjustList~ will be dealt with in
612 % sections_\ref{s:LNref} and_\ref{ss:PVadj}. (/New v4.00)
613 %
614 % \subsection{%
615 % \scs{LineNoTest}
616 % \unskip}
617 %
618 % The float mechanism inserts ~\interlinepenalty~s during
619 % ~\output~. So carefully reset it before going on. Else
620 % we get doubled line numbers on every float placed in
621 % horizontal mode, e.g, from ~\linelabel~.
622 %
623 % Sorry, neither a ~\linelabel~ nor a ~\marginpar~ should
624 % insert a penalty, else the following line number
625 % could go to the next page. Nor should any other
626 % float. So let us suppress the ~\interlinepenalty~
627 % altogether with the ~\@nobreak~ switch.
628 %
629 % Since (ltspace.dtx, v1.2p)[1996/07/26], the ~\@nobreaktrue~ does
630 % it's job globally. We need to do it locally here.
631
632 \def\LineNoTest{%
633 \let\@@par\@@@par
634 \ifnum\interlinepenalty<-\linenopenaltypar
635 \advance\interlinepenalty-\linenopenalty
636 \@LN@nobreaktrue
637 \fi
638 \@tempswatrue
639 \ifnum\outputpenalty>-\linenopenaltypar\else
640 \ifnum\outputpenalty>-188000\relax
641 \@tempswafalse
642 \fi
643 \fi
644 }
645
646 \def\@LN@nobreaktrue{\let\if@nobreak\iftrue} % renamed v4.33
647
648 % (UL) I thought here were
649 % another case of the save stack problem explained in \TeX book,
650 % p._301, namely through both local and global changing
651 % ~\if@nobreak~. However, ~\@LN@nobreak~ is called during
652 % ~\@LN@output~ only, while ~\@nobreaktrue~ is called by \LaTeX's
653 % ~\@startsection~ only. The latter never happens during
654 % ~\@LN@output~. So there is no local value of ~\if@nobreak~ on
655 % save stack when ~\@nobreaktrue~ acts, since ~\the\@LN@output~
656 % (where ~\@LN@output~ is a new name for the original ~\output~)
657 % is executed within a group (\TeX book p._21).
658 %%
659 %% 2004/09/19 Removed nonsense here according to Stephan 2004/09/04.
660 %%
661 % (/UL)
662 %
663 % \subsection{%
664 % Other output routines (v4.2)
665 % \unskip}\label{ss:LLO}
666 %
667 % I had thought of dealing with bad interference of footnotes
668 % (and ~\enlargethispage~) with (real) ~\marginpar~s and floats
669 % \emph{here}. Yet this is done in
670 % \[
671 % ~http://~\mbox{[CTAN]}
672 % ~/macros/latex/contrib/tamefloats/tameflts.sty~
673 % \]
674 % now, and I prefer striving for compatibility with the latter.
675 % (See there for expanding on the problem.)
676 % This requires returning the special absolute value of
677 % ~\holdinginserts~ that ~lineno.sty~ finds at the end of a newly
678 % typeset paragraph---now done in subsection_\ref{ss:calls}
679 % (~\linenumberpar~).
680 % The former ~\LineNoHoldInsertsTest~ has been filled into here.
681 %% ---`3' is replaced by ~\thr@@~ for a while. ~\thr@@~ is
682 %% useful practice since plain \TeX, but Stephan may have been
683 %% wise in suspecting that \LaTeX\ once could forsake ~\thr@@~.
684 %% The same holds for ~\@M=10000~.
685 % Note: when the following code is invoked, we have
686 % ~\if@tempswa~_ =_~\iftrue~.
687 % WARNING: I am still not sure whether the present code is good
688 % for cooperating with other packages that use ~\holdinginserts~.
689
690 \def\LineNoLaTeXOutput{%
691 \ifnum \holdinginserts=\thr@@ % v4.33 without \@tempswafalse
692 \global\holdinginserts-\thr@@
693 \unvbox\@cclv
694 \ifnum \outputpenalty=\@M \else \penalty\outputpenalty \fi
695 \else
696 \if@twocolumn \let\@makecol\@LN@makecol \fi
697 \the\@LN@output % finally following David Kastrup's advice.
698 \ifnum \holdinginserts=-\thr@@
699 \global\holdinginserts\thr@@ \fi
700 \fi
701 }
702
703 % \textit{More on dealing with output routines from other
704 % packages:}
705 % Since ~lineno.sty~'s output routine is called at least once
706 % for each output line, I think it should be in \TeX's
707 % original ~\output~, while output routines dealing with
708 % building pages and with floats etc.\ should be filled into
709 % registers addressed by ~\output~ after ~\newtoks\output~.
710 % Therefore \begin{enumerate}
711 % \item
712 % ~tameflts.sty~ should be loaded \emph{after} ~lineno.sty~;
713 % \item
714 % if a class changes ~\output~ (APS journal class revtex4,
715 % e.g.), ~lineno.sty~ should be loaded by ~\RequirePackage~
716 % [here presumably following some options in
717 % brackets]~{lineno}~ \emph{preceding} ~\documentclass~.
718 % \item
719 % If you actually maintain such a class, please consider
720 % loading ~lineno.sty~ on some draft option. The bunch of
721 % lineno's package options may be a problem, but perhaps the
722 % purpose of your class is offering only very few of lineno's
723 % options anyway, maybe just one.
724 % \end{enumerate}
725 % The latter may also be needed with classes that don't follow
726 % David Kastrup's rule on changing ~\output~.
727 %
728 % \subsection{%
729 % \scs{MakeLineNo}: Actually attach line number
730 % \unskip}\label{ss:MLN}
731 %
732 % We have to return all the page to the current page, and
733 % add a box with the line number, without adding
734 % breakpoints, glue or space. The depth of our line number
735 % should be equal to the previous depth of the page, in
736 % case the page breaks here, and the box has to be moved up
737 % by that depth.
738 %
739 % The ~\interlinepenalty~ comes after the ~\vadjust~ from a
740 % ~\linelabel~, so we increment the line number \emph{after}
741 % printing it. The macro ~\makeLineNumber~ produces the
742 % text of the line number, see section \ref{appearance}.
743 %
744 % (UL) I needed a while to understand
745 % the sentence on incrementing. Correctly: writing the
746 % ~\newlabel~ to the .aux file is triggered by the signal
747 % penalty that ~\end@float~ inserts via ~\vadjust~.
748 % However, this could be changed by our new ~\PostponeVadjust~.
749 % After ~\c@linenumber~ has been introduced as a \LaTeX\
750 % counter, it might be preferable that it behaved like standard
751 % \LaTeX\ counters which are incremented shortly before printing.
752 % But this may be of little practical relevance in this case,
753 % as ~\c@linenumber~ is driven in a very non-standard
754 % way.---However still, this behaviour of ~\c@linenumber~
755 % generates a problem with our ~edtable.sty~.
756 %% \unskip---Before,
757 %% I thought that Stephan had reported his reasoning incorrectly
758 %% and rather did this because of his ~\resetlinenumber~ which
759 %% initializes ~\c@linenumber~ to 1 instead of 0---the latter is
760 %% usual with \LaTeX\ counters. Cf._additional comment at
761 %% ~\resetlinenumber~.
762 % (/UL).
763 %
764 % Finally we put in the natural ~\interlinepenalty~, except
765 % after the last line.
766 %
767 % (New v3.10) Frank Mittelbach points out that box255 may be
768 % less deep than the last box inside, so he proposes to
769 % measure the page depth with ~\boxmaxdepth=\maxdimen~.
770 % (/New v3.10)
771 %
772 % (UL, New v4.00) We also resume the matter of
773 % ~\vadjust~ items that was started in section_\ref{ss:output}.
774 %
775 % \TeX\ puts only nonzero interline
776 % penalties into the vertical list (\TeX book p._105), while
777 % ~lineno.sty~ formerly replaced the signal interline penalty by
778 % something closing with an explicit penalty of the value that
779 % the interline penalty would have without ~lineno.sty~.
780 % This is usually 0. Now, explicit vertical penalties can be
781 % very nasty with respect to ~\nopagebreak~, e.g., a low (even
782 % positive) ~\widowpenalty~ may force a widow where you
783 % explicitly tried to forbid it by ~\nopagebreak~
784 % (see explanation soon below).
785 % The ~\nopagebreak~ we create here would never work if all
786 % those zero penalties were present.---On
787 % the other hand, we cannot just omit Stephan's zero penalties,
788 % because \TeX\ puts a penalty of 10000 after what ~lineno.sty~
789 % inserts (\TeX book p._125). This penalty must be overridden
790 % to allow page breaks between ordinary lines. To revive
791 % ~\nopagebreak~, we therefore replace those zero (or low)
792 % penalties by penalties that the user demanded by
793 % ~\nopagebreak~.---This mechanism is not perfect and does not
794 % exactly restore the original \LaTeX\ working of ~\pagebreak~
795 % and ~\nopagebreak~. Viz., if there are several vertical
796 % penalties after a line which were produced by closely sitting
797 % ~\[no]pagebreak~s, without ~lineno.sty~ the lowest penalty would
798 % be effective (cf._\TeX book exercise_14.10). Our mechanism, by
799 % contrast, chooses the \emph{last} user-set penalty of the line
800 % as the effective one. It would not be very difficult to come
801 % more close to the original mechanism, but until someone urges
802 % us we will cling to the present simple way. You may consider an
803 % advantage of the difference between our mechanism and the
804 % original one that the user here can actually override low
805 % penalties by ~\nopagebreak~, which may be what a lay \LaTeX\
806 % user would expect.
807 %% ---Zero glue would do instead of zero
808 %% penalty! This could make things easier. Maybe next time.
809 %% <- v4.4: No, problem with column depth.
810 % (/UL, /New v4.00)
811
812 \def\MakeLineNo{%
813 \@LN@maybe@normalLineNumber % v4.31
814 \boxmaxdepth\maxdimen\setbox\z@\vbox{\unvbox\@cclv}%
815 \@tempdima\dp\z@ \unvbox\z@
816 \sbox\@tempboxa{\hb@xt@\z@{\makeLineNumber}}%
817 %%
818 % (New v4.00) Previously,
819 % \begin{old}\begin{verbatim}
820 % % \stepcounter{linenumber}%
821 % \end{verbatim}
822 % \end{old}
823 %% %% TODO: Still first `\begin{old}'?
824 % followed. (Of course, there was no
825 % comment mark; I put it there to make
826 % reading the actual code easy.)
827 %
828 % (New v4.22: improved) Why not just
829 % \[~\global\advance\c@linenumber\@ne~?\]
830 % ~\stepcounter~ additionally resets ``subordinate''
831 % counters, but which could these (usefully) be?
832 % Again, may be column counters with ~edtable.sty~!?
833 %
834 % But then, our ~edtable.sty~ and its ~longtable~ option
835 % should use it as well. So use a shorthand supporting
836 % uniformity. You can even use it as a hook for choosing
837 % ~\global\advance\c@linenumber\@ne~ instead of our choice.
838 % (/New v4.22)
839 %%
840 \stepLineNumber
841 %%
842 % (New v4.4) Now
843 %%
844 \ht\@tempboxa\z@ \@LN@depthbox
845 %%
846 % appends the box containing the line number without changing
847 % ~\prevdepth~---see end of section.
848 % Now is the time for inserting the $\dots$ (/New v4.4)
849 %% The line number has now been placed (it may be invisible
850 %% depending on the modulo feature), so
851 %% we can insert the
852 % ~\vadjust~ items. We cannot do this much later, because
853 % their right place is above the artificial interline
854 % penalty which Stephan's code will soon insert
855 % (cf._\TeX book p._105). The next command is just ~\relax~
856 % if no ~\vadjust~ items have been accumulated for the
857 % current line. Otherwise it is a list macro inserting
858 % the ~\vadjust~ items and finally resetting itself.
859 % (This is made in section_\ref{ss:PVadj} below.)
860 % If the final item is a penalty, it is stored so it can
861 % compete with other things about page breaking.
862 %%
863 \@LN@do@vadjusts
864 \count@\lastpenalty
865 %%
866 % At this place,
867 % \begin{old}\begin{verbatim}
868 % % \ifnum\outputpenalty=-\linenopenaltypar\else
869 % \end{verbatim}
870 % \end{old}
871 % originally followed. We need something \emph{before} the
872 % ~\else~:
873 %%
874 \ifnum\outputpenalty=-\linenopenaltypar
875 \ifnum\count@=\z@ \else
876 %%
877 % So final ~\pagebreak[0]~ or ~\nopagebreak[0]~ has no
878 % effect---but this will make a difference after headings only,
879 % where nobody should place such a thing anyway.
880 %%
881 \xdef\@LN@parpgbrk{%
882 \penalty\the\count@
883 \global\let\noexpand\@LN@parpgbrk
884 \noexpand\@LN@screenoff@pen}% v4.4
885 %%
886 % That penalty will replace former ~\kern\z@~ in
887 % ~\linenumberpar~, see subsection_\ref{ss:calls}.---A
888 % few days earlier, I tried to send just a penalty value.
889 % However, the ~\kern\z@~ in ~\linenumberpar~ is crucial,
890 % as I then found out. See below.---The final penalty is
891 % repeated, but this does no harm. (It would not be very
892 % difficult to avoid the repeating, but it may even be
893 % less efficient.) It may be repeated due to the previous
894 % ~\xdef~, but it may be repeated as well below in the
895 % present macro where artificial interline penalty is to
896 % be overridden.
897 %%
898 \fi
899 \else
900 %%
901 % (/New v4.00)
902 %% Corrected code alignment with v4.11.
903 \@tempcnta\outputpenalty
904 \advance\@tempcnta -\linenopenalty
905 %%
906 % (New v4.00)
907 % \begin{old}\begin{verbatim}
908 % % \penalty\@tempcnta
909 % \end{verbatim}
910 % \end{old}
911 % followed previously. To give ~\nopagebreak~ a chance,
912 % we do
913 %% Corrected code alignment with v4.11.
914 \penalty \ifnum\count@<\@tempcnta \@tempcnta \else \count@ \fi
915 %%
916 % instead.---In ~linenox0.sty~, the ~\else~ thing once was omitted.
917 % Sergei Mariev's complaint (thanks!) showed that it is vital
918 % (see comment before ~\MakeLineNo~).
919 % The remaining ~\fi~ from previous package version closes the
920 % ~\ifnum\outputpenalty~\dots
921 % (/New v4.00)
922 %%
923 \fi
924 }
925
926 % (New v4.00)
927
928 \newcommand\stepLineNumber{\stepcounter{linenumber}}
929
930 % For reason, see use above. (/New v4.00)
931 %% %% TODO v4.4+: ~\newcommand~ more often!?
932 %
933 % (New v4.4) The depth preserving trick is drawn here from
934 % ~\MakeLineNo~ because it will be used again in
935 % section_\ref{ss:calls}.
936 % (v5.3) Handle special value of ~\prevdepth=-1000pt~. (/v5.3)
937
938 \def\@LN@depthbox{%
939 \ifdim\@tempdima=-1000pt
940 % \nointerlineskip is already set so we don't need set it again
941 % (and we shouldn't back up)
942 \else
943 \dp\@tempboxa=\@tempdima
944 \nointerlineskip
945 \kern-\@tempdima
946 \fi
947 \box\@tempboxa}
948
949 % (/New v4.4)
950 %
951 % \section{%
952 % Control line numbering
953 % \unskip}
954 % \subsection{%
955 % Inserting \scs{output} calls %% own subsec. v4.4.
956 % \unskip}\label{ss:calls}
957 % The line numbering is controlled via ~\par~. \LaTeX\
958 % saved the \TeX-primitive ~\par~ in ~\@@par~. We push it
959 % one level further out, and redefine ~\@@par~ to insert
960 % the ~\interlinepenalty~ needed to trigger the
961 % line numbering. And we need to allow pagebreaks after a
962 % paragraph.
963 %
964 % New (2.05beta): the prevgraf test. A paragraph that ends with a
965 % displayed equation, a ~\noindent\par~ or ~wrapfig.sty~ produce empty
966 % paragraphs. These should not get a spurious line number via
967 % ~\linenopenaltypar~.
968
969 \let\@@@par\@@par
970 \newcount\linenoprevgraf
971
972 % (UL) And needs ~\linenoprevgraf~
973 % to be a counter? Perhaps there may be a paragraph having
974 % thousands of lines, so ~\mathchardef~ doesn't suffice (really??).
975 %%
976 %% %% TODO: limitations of lines per paragraph elsewhere?
977 %% %% Signal penalties, e.g.!? ~\deadcycles~!?
978 %%
979 % A macro ending on ~\relax~ might suffice, but would be
980 % somewhat slow. I think I will use ~\mathchardef~ next time.
981 % Or has any user used ~\linenoprevgraf~? (/UL)
982
983 %% v4.33: changed code alignment for better understanding.
984 \def\linenumberpar{%
985 \ifvmode \@@@par \else
986 \ifinner \@@@par \else
987 \xdef\@LN@outer@holdins{\the\holdinginserts}% v4.2
988 \advance \interlinepenalty \linenopenalty
989 \linenoprevgraf \prevgraf
990 \global \holdinginserts \thr@@
991 \@@@par
992 \ifnum\prevgraf>\linenoprevgraf
993 \penalty-\linenopenaltypar
994 \fi
995 %%
996 % (New v4.00)
997 % \begin{old}\begin{verbatim}
998 % % \kern\z@
999 % \end{verbatim}
1000 % \end{old}
1001 % was here previously. What for?
1002 % According to \TeX book p._125, Stephan's
1003 % interline penalty is changed into 10000. At the end of a
1004 % paragraph, the ~\parskip~ would follow that penalty of 10000,
1005 % so there could be a page break neither at the
1006 % ~\parskip~ nor at the ~\baselineskip~ (\TeX book p._110)---so
1007 % there could never be a page break between two paragraphs.
1008 % So something must screen off the 10000 penalty.
1009 % Indeed, the ~\kern~ is a place to break.
1010 % (Stephan once knew this: see `allow pagebreaks' above.)
1011 %
1012 % Formerly, I tried to replace ~\kern\z@~ by
1013 % \begin{old}\begin{verbatim}
1014 % % \penalty\@LN@parpgpen\relax
1015 % \end{verbatim}
1016 % \end{old}
1017 % ---but this allows a page break after heading. So:
1018 %%
1019 \@LN@parpgbrk
1020 %%
1021 %% After heading, ~\kern\z@~ resulting from previous line
1022 %% (see below) is followed by ~\write~ or ~\penalty10000~,
1023 %% so causes no page break.
1024 %
1025 % These and similar changes were formerly done by ~linenox1.sty~.
1026 % (/New v4.00)
1027 %
1028 % (New v4.4)
1029 % A ~\belowdisplayskip~ may precede the previous when the paragraph
1030 % ends on a display-math; or there may be a ~\topsep~ from a list, etc.
1031 % ~\addvspace~ couldn't take account for it with ~\kern\z@~
1032 % here. v4.32 therefore moved the space down -- with at least two
1033 % bad consequences.
1034 % Moreover, David Josef Dev observes that ~\kern\z@~ may
1035 % inappropriately yield column depth 0pt.
1036 % For these reasons, we introduce ~\@LN@screenoff@pen~ below.
1037 % (/New v4.4)
1038 %%
1039 \global\holdinginserts\@LN@outer@holdins % v4.2
1040 \advance\interlinepenalty -\linenopenalty
1041 \fi % from \ifinner ... \else
1042 \fi} % from \ifvmode ... \else
1043
1044 % (New v4.00, v4.4) Initialize ~\@LN@parpgbrk~, accounting
1045 % for earlier space and for appropriate columndepth.
1046 % We use former ~\MakeLineNo~'s depth-preverving trick
1047 % ~\@LN@depthbox~ again:
1048
1049 \def\@LN@screenoff@pen{%
1050 \ifdim\lastskip=\z@
1051 \@tempdima\prevdepth \setbox\@tempboxa\null
1052 \@LN@depthbox \fi}
1053
1054 \global\let\@LN@parpgbrk\@LN@screenoff@pen
1055
1056 % (/New v4.4, v4.00)
1057 % \subsection{%
1058 % Turning on/off %% own subsec. v4.4.
1059 % \unskip}\label{ss:OnOff}
1060 % The basic commands to enable and disable line numbers.
1061 % ~\@par~ and ~\par~ are only touched, when they are ~\let~
1062 % to ~\@@@par~/~\linenumberpar~. The line number may be
1063 % reset to 1 with the star-form, or set by an optional
1064 % argument ~[~\angle{number}~]~.
1065 %
1066 % (New v4.00) We add ~\ifLineNumbers~ etc.\ since
1067 % a number of our new adjustments need to know whether
1068 % linenumbering is active. This just provides a kind of
1069 % shorthand for ~\ifx\@@par\linenumberpar~; moreover it is
1070 % more stable: who knows what may happen to ~\@@par~?---A
1071 % caveat: ~\ifLineNumbers~ may be wrong. E.g., it may be
1072 % ~\iffalse~ where it acts, while a ~\linenumbers~ a few
1073 % lines below---in the same paragraph---brings about that
1074 % the line where the ~\ifLineNumbers~ appears gets a
1075 % marginal number.
1076 %% Better implementation suggested below.
1077 %%
1078 % (New v4.3) Just noticed: Such tricks have been
1079 % disallowed with v4.11, see subsections_\ref{ss:LL}
1080 % and_\ref{ss:OnOff}.---Moreover, the switching between
1081 % meanings of ~\linelabel~ for a possible error message
1082 % as of v4.11 is removed. Speed is difficult to esteem
1083 % and also depends on applications. Just use the most
1084 % simple code you find. (/New v4.3)
1085
1086 \newif\ifLineNumbers \LineNumbersfalse
1087
1088 % (/New v4.00)
1089
1090 \def\linenumbers{%
1091 \LineNumberstrue % v4.00
1092 \xdef\@LN@outer@holdins{\the\holdinginserts}% v4.3
1093 %%
1094 % (New v4.3) The previous line is for ~{linenomath}~
1095 % in a first numbered paragraph. (/New v4.3)
1096 %%
1097 \let\@@par\linenumberpar
1098 % \let\linelabel\@LN@linelabel % v4.11, removed v4.3
1099 \ifx\@par\@@@par\let\@par\linenumberpar\fi
1100 \ifx\par\@@@par\let\par\linenumberpar\fi
1101 \@LN@maybe@moduloresume % v4.31
1102 \@ifnextchar[{\resetlinenumber}%]
1103 {\@ifstar{\resetlinenumber}{}}%
1104 }
1105
1106 \def\nolinenumbers{%
1107 \LineNumbersfalse % v4.00
1108 \let\@@par\@@@par
1109 % \let\linelabel\@LN@LLerror % v4.11, removed v4.3
1110 \ifx\@par\linenumberpar\let\@par\@@@par\fi
1111 \ifx\par\linenumberpar\let\par\@@@par\fi
1112 }
1113
1114 % (New v4.00) Moreover, it is useful to switch to
1115 % ~\nolinenumbers~ in ~\@arrayparboxrestore~. We postpone this
1116 % to section_\ref{ss:ReDef} where we'll have an appending macro
1117 % for doing this. (/New v4.00)
1118 %
1119 % What happens with a display math? Since ~\par~ is not executed,
1120 % when breaking the lines before a display, they will not get
1121 % line numbers. Sorry, but I do not dare to change
1122 % ~\interlinepenalty~ globally, nor do I want to redefine
1123 % the display math environments here.
1124 % \begin{displaymath}
1125 % display \ math
1126 % \end{displaymath}
1127 % See the subsection below, for a wrapper environment to make
1128 % it work. But that requires to wrap each and every display
1129 % in your \LaTeX\ source %%.
1130 %% v4.3:
1131 % (see option ~displaymath~ in subsections_\ref{ss:v3opts}
1132 % and_\ref{ss:display} for some relief [UL]).
1133 %
1134 % The next two commands are provided to turn on line
1135 % numbering in a specific mode. Please note the difference:
1136 % for pagewise numbering, ~\linenumbers~ comes first to
1137 % inhibit it from seeing optional arguments, since
1138 % re-/presetting the counter is useless.
1139
1140 \def\pagewiselinenumbers{\linenumbers\setpagewiselinenumbers}
1141 \def\runninglinenumbers{\setrunninglinenumbers\linenumbers}
1142
1143 % Finally, it is a \LaTeX\ style, so we provide for the use
1144 % of environments, including the suppression of the
1145 % following paragraph's indentation.
1146 %
1147 %% TODO: v4.4+:
1148 % (UL) I am drawing the following
1149 % private thoughts of Stephan's to publicity so that others may
1150 % think about them---or to remind myself of them in an efficient
1151 % way. (/UL)
1152 %% UL changed `%%%' to `% %' below.
1153 %% TODO: add \par to \linenumbers, if called from an environment. %% v4.3
1154 %% ToDO: add an \@endpe hack if \linenumbers are turned on
1155 % \begin{old}\begin{verbatim}
1156 % % TO DO: add \par to \linenumbers, if called from an environment.
1157 % % To DO: add an \@endpe hack if \linenumbers are turned on
1158 % % in horizontal mode. {\par\parskip\z@\noindent} or
1159 % % something.
1160 % \end{verbatim}
1161 % \end{old}
1162 % (UL) However, I rather think that ~\linenumbers~ and %% v4.31
1163 % ~\nolinenumbers~ should execute a ~\par~ already. (Then the
1164 % ~\par~s in the following definitions should be removed.) (/UL)
1165
1166 \@namedef{linenumbers*}{\par\linenumbers*}
1167 \@namedef{runninglinenumbers*}{\par\runninglinenumbers*}
1168
1169 \def\endlinenumbers{\par\@endpetrue}
1170 \let\endrunninglinenumbers\endlinenumbers
1171 \let\endpagewiselinenumbers\endlinenumbers
1172 \expandafter\let\csname endlinenumbers*\endcsname\endlinenumbers
1173 \expandafter\let\csname endrunninglinenumbers*\endcsname\endlinenumbers
1174 \let\endnolinenumbers\endlinenumbers
1175
1176 %
1177 % \subsection{%
1178 % Display math
1179 % \unskip}\label{ss:DM}
1180 %
1181 % Now we tackle the problem to get display math working.
1182 % There are different options.
1183 % \begin{enumerate}\item[
1184 % 1.] Precede every display math with a ~\par~.
1185 % Not too good.
1186 % \item[
1187 % 2.] Change ~\interlinepenalty~ and associates globally.
1188 % Unstable.
1189 % \item[
1190 % 3.] Wrap each display math with a ~{linenomath}~
1191 % environment.
1192 % \end{enumerate}
1193 % We'll go for option 3. See if it works:
1194 % \begin{linenomath}
1195 % \begin{equation}
1196 % display \ math
1197 % \end{equation}
1198 % \end{linenomath}
1199 % The star form ~{linenomath*}~ should also number the lines
1200 % of the display itself,
1201 % \begin{linenomath*}
1202 % \begin{eqnarray}
1203 % multi && line \\
1204 % display && math \\
1205 % &
1206 % \begin{array}{c}
1207 % with \\
1208 % array
1209 % \end{array}
1210 % &
1211 % \end{eqnarray}
1212 % \end{linenomath*}
1213 % including multline displays.
1214 %
1215 % First, here are two macros to turn
1216 % on linenumbering on paragraphs preceeding displays, with
1217 % numbering the lines of the display itself, or without.
1218 % The ~\ifx..~ tests if line numbering is turned on. It
1219 % does not harm to add these wrappers in sections that are
1220 % not numbered. Nor does it harm to wrap a display
1221 % twice, e.q, in case you have some ~{equation}~s wrapped
1222 % explicitely, and later you redefine ~\equation~ to do it
1223 % automatically.
1224 %
1225 % (New v4.3) To avoid the spurious line number above a
1226 % display in vmode, I insert ~\ifhmode~. (/New v4.3)
1227
1228 \newcommand\linenomathNonumbers{%
1229 \ifLineNumbers
1230 %% \ifx\@@par\@@@par\else
1231 \ifnum\interlinepenalty>-\linenopenaltypar
1232 \global\holdinginserts\thr@@
1233 \advance\interlinepenalty \linenopenalty
1234 \ifhmode % v4.3
1235 \advance\predisplaypenalty \linenopenalty
1236 \fi
1237 \fi
1238 \fi
1239 \ignorespaces
1240 }
1241
1242 \newcommand\linenomathWithnumbers{%
1243 \ifLineNumbers
1244 %% \ifx\@@par\@@@par\else
1245 \ifnum\interlinepenalty>-\linenopenaltypar
1246 \global\holdinginserts\thr@@
1247 \advance\interlinepenalty \linenopenalty
1248 \ifhmode % v4.3
1249 \advance\predisplaypenalty \linenopenalty
1250 \fi
1251 \advance\postdisplaypenalty \linenopenalty
1252 \advance\interdisplaylinepenalty \linenopenalty
1253 \fi
1254 \fi
1255 \ignorespaces
1256 }
1257
1258 % The ~{linenomath}~ environment has two forms, with and
1259 % without a star. The following two macros define the
1260 % environment, where the stared/non-stared form does/doesn't number the
1261 % lines of the display or vice versa.
1262
1263 \newcommand\linenumberdisplaymath{%
1264 \def\linenomath{\linenomathWithnumbers}%
1265 \@namedef{linenomath*}{\linenomathNonumbers}%
1266 }
1267
1268 \newcommand\nolinenumberdisplaymath{%
1269 \def\linenomath{\linenomathNonumbers}%
1270 \@namedef{linenomath*}{\linenomathWithnumbers}%
1271 }
1272
1273 \def\endlinenomath{%
1274 \ifLineNumbers % v4.3
1275 \global\holdinginserts\@LN@outer@holdins % v4.21
1276 \fi
1277 \global % v4.21 support for LaTeX2e earlier than 1996/07/26.
1278 \@ignoretrue
1279 }
1280 \expandafter\let\csname endlinenomath*\endcsname\endlinenomath
1281
1282 % The default is not to number the lines of a display. But
1283 % the package option ~mathlines~ may be used to switch
1284 % that behavior.
1285
1286 \nolinenumberdisplaymath
1287
1288 %
1289 % \section{%
1290 % Line number references
1291 % \unskip}\label{s:LNref}
1292 % \subsection{%
1293 % Internals %% New subsec. v4.3.
1294 % \unskip}
1295 % The only way to get a label to a line number in a
1296 % paragraph is to ask the output routine to mark it.
1297 %
1298 % (New v4.00) The following two paragraphs don't hold any
1299 % longer, see below. (/New v4.00)
1300 % \begin{old}\begin{verbatim}
1301 % % We use the marginpar mechanism to hook to ~\output~ for a
1302 % % second time. Marginpars are floats with number $-1$, we
1303 % % fake marginpars with No $-2$. Originally, every negative
1304 % % numbered float was considered to be a marginpar.
1305 % %
1306 % % The float box number ~\@currbox~ is used to transfer the
1307 % % label name in a macro called ~\@LNL@~\angle{box-number}.
1308 % \end{verbatim}
1309 % \end{old}
1310 % A ~\newlabel~ is written to the aux-file. The reference
1311 % is to ~\theLineNumber~, \emph{not} ~\thelinenumber~.
1312 % This allows to hook in, as done below for pagewise line
1313 % numbering.
1314 %
1315 % (New v3.03) The ~\@LN@ExtraLabelItems~ are added for a hook
1316 % to keep packages like ~{hyperref}~ happy. (/New v3.03)
1317 %
1318 % (New v4.00)
1319 % We fire the ~\marginpar~ mechanism, so we leave \LaTeX's
1320 % ~\@addmarginpar~ untouched.
1321 % \begin{old}\begin{verbatim}
1322 % % \let\@LN@addmarginpar\@addmarginpar
1323 % % \def\@addmarginpar{%
1324 % % \ifnum\count\@currbox>-2\relax
1325 % % \expandafter\@LN@addmarginpar
1326 % % \else
1327 % % \@cons\@freelist\@currbox
1328 % % \protected@write\@auxout{}{%
1329 % % \string\newlabel
1330 % % {\csname @LNL@\the\@currbox\endcsname}%
1331 % % {{\theLineNumber}{\thepage}\@LN@ExtraLabelItems}}%
1332 % % \fi}
1333 % \end{verbatim}
1334 % \end{old}
1335 % OK, we keep Stephan's ~\@LN@ExtraLabelItems~:
1336 % (/New v4.00)
1337
1338 \let\@LN@ExtraLabelItems\@empty
1339
1340 % (New v4.00)
1341 % We imitate the ~\marginpar~ mechanism without using the
1342 % ~\@freelist~ boxes. ~\linelabel~ will indeed place a signal
1343 % penalty (~\@Mllbcodepen~, new), and it will put a label into
1344 % some list macro ~\@LN@labellist~. A new part of the output
1345 % routine will take the labels from the list and will write
1346 % ~\newlabel~s to the .aux file.
1347 %
1348 % The following is a version of \LaTeX's ~\@xnext~.
1349
1350 \def\@LN@xnext#1\@lt#2\@@#3#4{\def#3{#1}\gdef#4{#2}}
1351
1352 % This takes an item ~#1~ from a list ~#4~ into ~#3~;
1353 % to be used as ~\expandafter\@LN@xnext#4\@@#3#4~.
1354 % Our lists use ~\@lt~ after each item for separating.
1355 % Indeed, there will be another list macro which can
1356 % appear as argument ~#4~, this will be used for moving
1357 % ~\vadjust~ items (section_\ref{ss:PVadj}).
1358 % The list for ~\linelabel~s is the following:
1359
1360 \global\let\@LN@labellist\@empty
1361
1362 % The next is the new part of the output routine writing the
1363 % ~\newlabel~ to the .aux file. Since it is no real page output,
1364 % the page is put back to top of the main vertical list.
1365
1366 \def\WriteLineNo{%
1367 \unvbox\@cclv
1368 \expandafter \@LN@xnext \@LN@labellist \@@
1369 \@LN@label \@LN@labellist
1370 \protected@write\@auxout{}{\string\newlabel{\@LN@label}%
1371 {{\theLineNumber}{\thepage}\@LN@ExtraLabelItems}}%
1372 }
1373
1374 % (/New v4.00)
1375 %
1376 % \subsection{%
1377 % The \scs{linelabel} command
1378 % \unskip}\label{ss:LL}
1379 % To refer to a place in line ~\ref{~\angle{foo}~}~ at page
1380 % ~\pageref{~\angle{foo}~}~ you place a ~\linelabel{~\angle{foo}~}~ at
1381 % that place.
1382 %
1383 % \linelabel{demo}
1384 % \marginpar{\tiny\raggedright
1385 % See if it works: This paragraph
1386 % starts on page \pageref{demo}, line
1387 % \ref{demo}.
1388 % \unskip}%
1389 % (New v4.11)
1390 % \begin{old}\begin{verbatim}
1391 % % If you use this command outside a ~\linenumbers~
1392 % % paragraph, you will get references to some bogus
1393 % % line numbers, sorry. But we don't disable the command,
1394 % % because only the ~\par~ at the end of a paragraph may
1395 % % decide whether to print line numbers on this paragraph
1396 % % or not. A ~\linelabel~ may legally appear earlier than
1397 % % ~\linenumbers~.
1398 % \end{verbatim}
1399 % \end{old}
1400 % This trick is better not allowed---see subsections_\ref{ss:LL}
1401 % and_\ref{ss:OnOff}.
1402 % (/New v4.11)
1403 %
1404 % ~\linelabel~
1405 % \begin{old}\begin{verbatim}
1406 % %, via a fake float number $-2$, %% new mechanism v4.00
1407 % \end{verbatim}
1408 % \end{old}
1409 % puts a
1410 % ~\penalty~ into a ~\vadjust~, which triggers the
1411 % pagebuilder after putting the current line to the main
1412 % vertical list. A ~\write~ is placed on the main vertical
1413 % list, which prints a reference to the current value of
1414 % ~\thelinenumber~ and ~\thepage~ at the time of the
1415 % ~\shipout~.
1416 %
1417 % A ~\linelabel~ is allowed only in outer horizontal mode.
1418 % In outer vertical mode we start a paragraph, and ignore
1419 % trailing spaces (by fooling ~\@esphack~).
1420 %
1421 % (New v4.00) We aim at relaxing the previous condition.
1422 % We insert a hook ~\@LN@mathhook~ and a shorthand
1423 % ~\@LN@postlabel~ to support the ~mathrefs~ option which
1424 % allows ~\linelabel~ in math mode.
1425 %
1426 % The next paragraph is no longer valid.
1427 % \begin{old}\begin{verbatim}
1428 % % The argument of ~\linelabel~ is put into a macro with a
1429 % % name derived from the number of the allocated float box.
1430 % % Much of the rest is dummy float setup.
1431 % \end{verbatim}
1432 % \end{old}
1433 % (/New v4.00)
1434 %
1435 % (New v4.11)
1436 % \begin{old}\begin{verbatim}
1437 % % \def\linelabel#1{%
1438 % \end{verbatim}
1439 % \end{old}
1440 % I forgot ~\linenumbers~ today, costed me hours or so.
1441
1442 \def\@LN@LLerror{\PackageError{lineno}{%
1443 \string\linelabel\space without \string\linenumbers}{%
1444 Just see documentation. (New feature v4.11)}\@gobble}
1445
1446 % (New v4.3) Here some things have changed for v4.3.
1447 % The previous ~#1~ has been replaced by ~\@gobble~.
1448 % Ensuing, the ~\linelabel~ error message is re-implemented.
1449 % I find it difficult to compare efficiency of slight
1450 % alternatives---so choose an easy one. Explicit switching
1451 % in ~\linenumbers~ and ~\nolinenumbers~ is an additional
1452 % command that may better be avoided.
1453
1454 \newcommand\linelabel{%
1455 \ifLineNumbers \expandafter \@LN@linelabel
1456 \else \expandafter \@LN@LLerror \fi}
1457 %%\let\linelabel\@LN@LLerror
1458
1459 \gdef\@LN@linelabel#1{%
1460 %%
1461 % ~\gdef~ for hyperref ``symbolically''. (/New v4.11)
1462 %%
1463 \ifx\protect\@typeset@protect
1464 %%
1465 % $\gets$ And a ~\linelabel~ should never be replicated in a
1466 % mark or a TOC entry. (/New v4.3)
1467 %%
1468 \ifvmode
1469 \ifinner \else
1470 \leavevmode \@bsphack \@savsk\p@
1471 \fi
1472 \else
1473 \@bsphack
1474 \fi
1475 \ifhmode
1476 \ifinner
1477 \@parmoderr
1478 \else
1479 %%
1480 % (New v4.00)
1481 %%
1482 \@LN@postlabel{#1}%
1483 % \begin{old}\begin{verbatim}
1484 % % \@floatpenalty -\@Mii
1485 % % \@next\@currbox\@freelist
1486 % % {\global\count\@currbox-2%
1487 % % \expandafter\gdef\csname @LNL@\the\@currbox\endcsname{#1}}%
1488 % % {\@floatpenalty\z@ \@fltovf \def\@currbox{\@tempboxa}}%
1489 % % \begingroup
1490 % % \setbox\@currbox \color@vbox \vbox \bgroup \end@float
1491 % % \endgroup
1492 % % \@ignorefalse \@esphack
1493 % \end{verbatim}
1494 % \end{old}
1495 % (/New v4.00)
1496 %%
1497 \@esphack
1498 %%
1499 % (New v4.00)
1500 % The ~\@ignorefalse~ was appropriate before because the
1501 % ~\@Esphack~ in ~\end@float~ set ~\@ignoretrue~. Cf._\LaTeX's
1502 % ~\@xympar~. (/New v4.00)
1503 %%
1504 \fi
1505 \else
1506 %%
1507 % (New v4.00)
1508 %%
1509 \@LN@mathhook{#1}%
1510 % \begin{old}\begin{verbatim}
1511 % % \@parmoderr
1512 % \end{verbatim}
1513 % \end{old}
1514 % Instead of complaining, you may just do your job.
1515 % (/New v4.00)
1516 %%
1517 \fi
1518 \fi
1519 }
1520
1521 % (New v4.00) The shorthand just does what happened
1522 % with ~linenox0.sty~ before ~ednmath0.sty~ (New v4.1:
1523 % now ~mathrefs~ option) appeared, and
1524 % the hook is initialized to serve the same purpose.
1525 % So errors come just where Stephan had built them in,
1526 % and this is just the \LaTeX\ ~\marginpar~ behaviour.
1527
1528 \def\@LN@postlabel#1{\g@addto@macro\@LN@labellist{#1\@lt}%
1529 \vadjust{\penalty-\@Mllbcodepen}}
1530 \def\@LN@mathhook#1{\@parmoderr}
1531
1532 % (/New v4.00)
1533 %
1534 % \modulolinenumbers[3]
1535 % \firstlinenumber{1}
1536 % \section{%
1537 % The appearance of the line numbers
1538 % \unskip}\label{appearance}
1539 % \subsection{%
1540 % Basic code %% own subsec. v4.2.
1541 % \unskip}
1542 %
1543 % The line numbers are set as ~\tiny\sffamily\arabic{linenumber}~,
1544 % $10pt$ left of the text. With options to place it
1545 % right of the text, or . . .
1546 %
1547 % . . . here are the hooks:
1548
1549 \def\makeLineNumberLeft{%
1550 \hss\linenumberfont\LineNumber\hskip\linenumbersep}
1551
1552 \def\makeLineNumberRight{%
1553 \linenumberfont\hskip\linenumbersep\hskip\columnwidth
1554 \hb@xt@\linenumberwidth{\hss\LineNumber}\hss}
1555
1556 \def\linenumberfont{\normalfont\tiny\sffamily}
1557
1558 \newdimen\linenumbersep
1559 \newdimen\linenumberwidth
1560
1561 \linenumbersep=10pt
1562 \linenumberwidth=10pt
1563
1564 % Margin switching requires ~pagewise~ numbering mode, but
1565 % choosing the left or right margin for the numbers always
1566 % works.
1567
1568 \def\switchlinenumbers{\@ifstar
1569 {\let\makeLineNumberOdd\makeLineNumberRight
1570 \let\makeLineNumberEven\makeLineNumberLeft}%
1571 {\let\makeLineNumberOdd\makeLineNumberLeft
1572 \let\makeLineNumberEven\makeLineNumberRight}%
1573 }
1574
1575 \def\setmakelinenumbers#1{\@ifstar
1576 {\let\makeLineNumberRunning#1%
1577 \let\makeLineNumberOdd#1%
1578 \let\makeLineNumberEven#1}%
1579 {\ifx\c@linenumber\c@runninglinenumber
1580 \let\makeLineNumberRunning#1%
1581 \else
1582 \let\makeLineNumberOdd#1%
1583 \let\makeLineNumberEven#1%
1584 \fi}%
1585 }
1586
1587 \def\leftlinenumbers{\setmakelinenumbers\makeLineNumberLeft}
1588 \def\rightlinenumbers{\setmakelinenumbers\makeLineNumberRight}
1589
1590 \leftlinenumbers*
1591
1592 % ~\LineNumber~ is a hook which is used for the modulo stuff.
1593 % It is the command to use for the line number, when you
1594 % customize ~\makeLineNumber~. Use ~\thelinenumber~ to
1595 % change the outfit of the digits.
1596 %
1597 %
1598 % We will implement two modes of operation:
1599 % \begin{itemize}
1600 % \item numbers ~running~ through (parts of) the text
1601 % \item ~pagewise~ numbers starting over with one on top of
1602 % each page.
1603 % \end{itemize}
1604 % Both modes have their own count register, but only one is
1605 % allocated as a \LaTeX\ counter, with the attached
1606 % facilities serving both.
1607
1608 \newcounter{linenumber}
1609 \newcount\c@pagewiselinenumber
1610 \let\c@runninglinenumber\c@linenumber
1611
1612 % Only the running mode counter may be reset, or preset,
1613 % for individual paragraphs. The pagewise counter must
1614 % give a unique anonymous number for each line.
1615 %
1616 % (New v4.3) ~\newcounter{linenumber}~
1617 % was the only ~\newcounter~ in the whole package, and
1618 % formerly I was near using ~\newcount~ instead. Yet
1619 % ~\newcounter~ may be quite useful for ~\includeonly~.
1620 % It also supports resetting ``subcounters'', but what
1621 % could these be? Well, ~edtable~ might introduce a
1622 % subcounter for columns.
1623 % (Note that \LaTeX's setting commands would work with
1624 % ~\newcount\c@linenumber~ already, apart from this.
1625 % And perhaps sometimes ~\refstepcounter{linenumber}~
1626 % wouldn't work---cf._my discussion of ~\stepcounter~ in
1627 % subsection_\ref{ss:MLN}, similarly ~\refstep...~ would
1628 % be quite useless.
1629 % Even the usual redefinitions of ~\thelinenumber~ would
1630 % work. It is nice, on the other hand, that
1631 % ~\thelinenumber~ is predefined here. \LaTeX's
1632 % initialization of the value perhaps just serves making
1633 % clear \LaTeX\ counters should always be changed
1634 % globally.---Shortened and improved the discussion here.)
1635 % (/New v4.3)
1636 %
1637 % (New v4.22)
1638 % ~\c@linenumber~ usually is---globally---incremented by
1639 % ~\stepcounter~ (at present), so resetting it locally would
1640 % raise the save stack problem of \TeX book p._301, moreover
1641 % it would be is useless, there is no hope of keeping the
1642 % values local (but see subsection_\ref{ss:ILN}). So I insert
1643 % ~\global~: (/New v4.22)
1644
1645 \newcommand*\resetlinenumber[1][\@ne]{%
1646 \global % v4.22
1647 \c@runninglinenumber#1\relax}
1648
1649 % (New v4.00)
1650 % \begin{old}\begin{verbatim}
1651 % % \newcommand\resetlinenumber[1][1]{\c@runninglinenumber#1}
1652 % \end{verbatim}
1653 % \end{old}
1654 % Added ~\relax~, being quite sure that this does no harm
1655 % and is quite important, as with ~\setcounter~ etc.
1656 % I consider this a bug fix (although perhaps no user has
1657 % ever had a problem with this). (/New v4.00)
1658 %
1659 % (v4.22: I had made much fuss about resetting subordinate
1660 % counters here---removed, somewhat postponed.)
1661 %
1662 %% TODO v4.4+:
1663 %% \newcommand*\resetlinenumber[1][\@ne]{%
1664 %% \ifx\c@linenumber\c@runninglinenumber
1665 %% \global\c@linenumber#1\relax
1666 %% \global\advance\c@linenumber\m@ne
1667 %% \stepLineNumber
1668 %% \else
1669 %% \PackageError{lineno}%% Shorthand!?
1670 %% {You can't reset line number in pagewise mode}%
1671 %% {This should suffice.}%
1672 %% \fi
1673 %% }
1674 %
1675 % \subsection{%
1676 % Running line numbers
1677 % \unskip}
1678 %
1679 % Running mode is easy, ~\LineNumber~ and ~\theLineNumber~
1680 % produce ~\thelinenumber~, which defaults to
1681 % ~\arabic{linenumber}~, using the ~\c@runninglinenumber~
1682 % counter. This is the default mode of operation.
1683
1684 \def\makeRunningLineNumber{\makeLineNumberRunning}
1685
1686 \def\setrunninglinenumbers{%
1687 \def\theLineNumber{\thelinenumber}%
1688 \let\c@linenumber\c@runninglinenumber
1689 \let\makeLineNumber\makeRunningLineNumber
1690 }
1691
1692 \setrunninglinenumbers\resetlinenumber
1693
1694 %
1695 % \subsection{%
1696 % Pagewise line numbers
1697 % \unskip}\label{ss:PW}
1698 %
1699 % Difficult, if you think about it. The number has to be
1700 % printed when there is no means to know on which page it
1701 % will end up, except through the aux-file. My solution
1702 % is really expensive, but quite robust.
1703 %
1704 % With version ~v2.00~ the hashsize requirements are
1705 % reduced, because we do not need one controlsequence for
1706 % each line any more. But this costs some computation time
1707 % to find out on which page we are.
1708 %
1709 % ~\makeLineNumber~ gets a hook to log the line and page
1710 % number to the aux-file. Another hook tries to find out
1711 % what the page offset is, and subtracts it from the counter
1712 % ~\c@linenumber~. Additionally, the switch
1713 % ~\ifoddNumberedPage~ is set true for odd numbered pages,
1714 % false otherwise.
1715
1716 \def\setpagewiselinenumbers{%
1717 \let\theLineNumber\thePagewiseLineNumber
1718 \let\c@linenumber\c@pagewiselinenumber
1719 \let\makeLineNumber\makePagewiseLineNumber
1720 }
1721
1722 \def\makePagewiseLineNumber{\logtheLineNumber\getLineNumber
1723 \ifoddNumberedPage
1724 \makeLineNumberOdd
1725 \else
1726 \makeLineNumberEven
1727 \fi
1728 }
1729
1730 % Each numbered line gives a line to the aux file
1731 % \begin{verse}
1732 % ~\@LN{~\angle{line}~}{~\angle{page}~}~
1733 % \end{verse}
1734 % very similar to the ~\newlabel~ business, except that we need
1735 % an arabic representation of the page number, not what
1736 % there might else be in ~\thepage~.
1737
1738 \def\logtheLineNumber{\protected@write\@auxout{}{%
1739 %%
1740 % (New v4.00) (UL)
1741 % As Daniel Doherty observed, the earlier line
1742 % \begin{old}\begin{verbatim}
1743 % % \string\@LN{\the\c@linenumber}{\noexpand\the\c@page}}}
1744 % \end{verbatim}
1745 % \end{old}
1746 % here may lead into an infinite loop when the user resets
1747 % the page number (think of ~\pagenumbering~, e.g.).
1748 % Stephan and I brief\/ly discussed the matter and decided
1749 % to introduce a ``physical''-page counter to which
1750 % ~\logtheLineNumber~ refers. It was Stephan's idea to use
1751 % ~\cl@page~ for reliably augmenting the ``physical''-page
1752 % counter. However, this relies on the output routine once
1753 % doing ~\stepcounter{page}~. Before Stephan's
1754 % suggestion, I had thought of appending the stepping to
1755 % \LaTeX's ~\@outputpage~.---So the macro definition ends
1756 % as follows.
1757 %%
1758 \string\@LN{\the\c@linenumber}{%
1759 %%
1760 % (New v4.2)
1761 %% \noexpand\number\n@LN@truepage}}}
1762 %%
1763 % The `truepage' counter must start with ~\c@~ so it works
1764 % with ~\include~, and the ~\@addtoreset~ below is needed
1765 % for the same purpose.
1766 %%
1767 \noexpand\the\c@LN@truepage}}}
1768
1769 %% \newcount\n@LN@truepage
1770 %% \g@addto@macro\cl@page{\global\advance\n@LN@truepage\@ne}
1771 \newcount\c@LN@truepage
1772 \g@addto@macro\cl@page{\global\advance\c@LN@truepage\@ne}
1773 \@addtoreset{LN@truepage}{@ckpt}
1774
1775 % (/New v4.2) I had thought of offering more
1776 % features of a \LaTeX\ counter. However, the user should
1777 % better \emph{not} have access to this counter. ~\c@page~
1778 % should suffice as a pagewise master counter.---To be sure,
1779 % along the present lines the user \emph{can} manipulate
1780 % ~\c@LN@truepage~ by ~\stepcounter{page}~. E.g., she might
1781 % do this in order to manually insert a photograph. Well,
1782 % seems not to harm.
1783 %
1784 % The above usage of ~\g@addto@macro~ and ~\cl@page~ may be
1785 % not as stable as Stephan intended. His proposal used
1786 % ~\xdef~ directly. But he used ~\cl@page~ as well, and who
1787 % knows \dots{} And as to ~\g@addto@macro~, I have introduced
1788 % it for list macros anyway.
1789 % (/UL) (/New v4.00)
1790 %
1791 % From the aux-file we get one macro ~\LN@P~\angle{page} for each
1792 % page with line numbers on it. This macro calls four other
1793 % macros with one argument each. These macros are
1794 % dynamically defined to do tests and actions, to find out
1795 % on which page the current line number is located.
1796 %
1797 % We need sort of a pointer to the first page with line
1798 % numbers, initiallized to point to nothing:
1799
1800 \def\LastNumberedPage{first}
1801 \def\LN@Pfirst{\nextLN\relax}
1802
1803 % The four dynamic macros are initiallized to reproduce
1804 % themselves in an ~\xdef~
1805
1806 \let\lastLN\relax % compare to last line on this page
1807 \let\firstLN\relax % compare to first line on this page
1808 \let\pageLN\relax % get the page number, compute the line number
1809 \let\nextLN\relax % move to the next page
1810
1811 % During the end-document run through the aux-files, we
1812 % disable ~\@LN~. I may put in a check here later, to give
1813 % a rerun recommendation.
1814
1815 \AtEndDocument{\let\@LN\@gobbletwo}
1816
1817 % Now, this is the tricky part. First of all, the whole
1818 % definition of ~\@LN~ is grouped, to avoid accumulation
1819 % on the save stack. Somehow ~\csname~\angle{cs}~\endcsname~ pushes
1820 % an entry, which stays after an ~\xdef~ to that \angle{cs}.
1821 %
1822 % If ~\LN@P~\angle{page} is undefined, initialize it with the
1823 % current page and line number, with the
1824 % \emph{pointer-to-the-next-page} pointing to nothing. And
1825 % the macro for the previous page will be redefined to point
1826 % to the current one.
1827 %
1828 % If the macro for the current page already exists, just
1829 % redefine the \emph{last-line-number} entry.
1830 %
1831 % Finally, save the current page number, to get the pointer to the
1832 % following page later.
1833
1834 \def\@LN#1#2{{\expandafter\@@LN
1835 \csname LN@P#2C\@LN@column\expandafter\endcsname
1836 \csname LN@PO#2\endcsname
1837 {#1}{#2}}}
1838
1839 \def\@@LN#1#2#3#4{\ifx#1\relax
1840 \ifx#2\relax\gdef#2{#3}\fi
1841 \expandafter\@@@LN\csname LN@P\LastNumberedPage\endcsname#1%
1842 \xdef#1{\lastLN{#3}\firstLN{#3}%
1843 \pageLN{#4}{\@LN@column}{#2}\nextLN\relax}%
1844 \else
1845 \def\lastLN##1{\noexpand\lastLN{#3}}%
1846 \xdef#1{#1}%
1847 \fi
1848 \xdef\LastNumberedPage{#4C\@LN@column}}
1849
1850 % The previous page macro gets its pointer to the
1851 % current one, replacing the ~\relax~ with the cs-token
1852 % ~\LN@P~\angle{page}.
1853
1854 \def\@@@LN#1#2{{\def\nextLN##1{\noexpand\nextLN\noexpand#2}%
1855 \xdef#1{#1}}}
1856
1857 % Now, to print a line number, we need to find the page,
1858 % where it resides. This will most probably be the page where
1859 % the last one came from, or maybe the next page. However, it can
1860 % be a completely different one. We maintain a cache,
1861 % which is ~\let~ to the last page's macro. But for now
1862 % it is initialized to expand ~\LN@first~, where the poiner
1863 % to the first numbered page has been stored in.
1864
1865 \def\NumberedPageCache{\LN@Pfirst}
1866
1867 % To find out on which page the current ~\c@linenumber~ is,
1868 % we define the four dynamic macros to do something usefull
1869 % and execute the current cache macro. ~\lastLN~ is run
1870 % first, testing if the line number in question may be on a
1871 % later page. If so, disable ~\firstLN~, and go on to the
1872 % next page via ~\nextLN~.
1873
1874 \def\testLastNumberedPage#1{\ifnum#1<\c@linenumber
1875 \let\firstLN\@gobble
1876 \fi}
1877
1878 % Else, if ~\firstLN~ finds out that we need an earlier
1879 % page, we start over from the beginning. Else, ~\nextLN~
1880 % will be disabled, and ~\pageLN~ will run
1881 % ~\gotNumberedPage~ with four arguments: the first line
1882 % number on this column, the page number, the column
1883 % number, and the first line on the page.
1884
1885 \def\testFirstNumberedPage#1{\ifnum#1>\c@linenumber
1886 \def\nextLN##1{\testNextNumberedPage\LN@Pfirst}%
1887 \else
1888 \let\nextLN\@gobble
1889 \def\pageLN{\gotNumberedPage{#1}}%
1890 \fi}
1891
1892 % We start with ~\pageLN~ disabled and ~\nextLN~ defined to
1893 % continue the search with the next page.
1894
1895 \long\def \@gobblethree #1#2#3{}
1896
1897 \def\testNumberedPage{%
1898 \let\lastLN\testLastNumberedPage
1899 \let\firstLN\testFirstNumberedPage
1900 \let\pageLN\@gobblethree
1901 \let\nextLN\testNextNumberedPage
1902 \NumberedPageCache
1903 }
1904
1905 % When we switch to another page, we first have to make
1906 % sure that it is there. If we are done with the last
1907 % page, we probably need to run \TeX\ again, but for the
1908 % rest of this run, the cache macro will just return four
1909 % zeros. This saves a lot of time, for example if you have
1910 % half of an aux-file from an aborted run, in the next run
1911 % the whole page-list would be searched in vain again and
1912 % again for the second half of the document.
1913 %
1914 % If there is another page, we iterate the search.
1915
1916 \def\testNextNumberedPage#1{\ifx#1\relax
1917 \global\def\NumberedPageCache{\gotNumberedPage0000}%
1918 \PackageWarningNoLine{lineno}%
1919 {Line number reference failed, re-run to get it right}%
1920 \else
1921 \global\let\NumberedPageCache#1%
1922 \fi
1923 \testNumberedPage
1924 }
1925
1926 % \linelabel{demo2}
1927 % \marginpar{\tiny\raggedright
1928 % Let's see if it finds the label
1929 % on page \pageref{demo},
1930 % line \ref{demo}, and back here
1931 % on page \pageref{demo2}, line
1932 % \ref{demo2}.
1933 % \unskip}%
1934 % To separate the official hooks from the internals there is
1935 % this equivalence, to hook in later for whatever purpose:
1936
1937 \let\getLineNumber\testNumberedPage
1938
1939 % So, now we got the page where the number is on. We
1940 % establish if we are on an odd or even page, and calculate
1941 % the final line number to be printed.
1942
1943 \newif\ifoddNumberedPage
1944 \newif\ifcolumnwiselinenumbers
1945 \columnwiselinenumbersfalse
1946
1947 \def\gotNumberedPage#1#2#3#4{\oddNumberedPagefalse
1948 \ifodd \if@twocolumn #3\else #2\fi\relax\oddNumberedPagetrue\fi
1949 \advance\c@linenumber\@ne
1950 \ifcolumnwiselinenumbers
1951 \subtractlinenumberoffset{#1}%
1952 \else
1953 \subtractlinenumberoffset{#4}%
1954 \fi
1955 }
1956
1957 % You might want to run the pagewise mode with running line
1958 % numbers, or you might not. It's your choice:
1959
1960 \def\runningpagewiselinenumbers{%
1961 \let\subtractlinenumberoffset\@gobble
1962 }
1963
1964 \def\realpagewiselinenumbers{%
1965 \def\subtractlinenumberoffset##1{\advance\c@linenumber-##1\relax}%
1966 }
1967
1968 \realpagewiselinenumbers
1969
1970 % For line number references, we need a protected call to
1971 % the whole procedure, with the requested line number stored
1972 % in the ~\c@linenumber~ counter. This is what gets printed
1973 % to the aux-file to make a label:
1974
1975 \def\thePagewiseLineNumber{\protect
1976 \getpagewiselinenumber{\the\c@linenumber}}%
1977
1978 % And here is what happens when the label is refered to:
1979
1980 \def\getpagewiselinenumber#1{{%
1981 \c@linenumber #1\relax\testNumberedPage
1982 \thelinenumber
1983 }}
1984
1985 % %
1986 % A summary of all per line expenses:
1987 % \begin{description}\item
1988 % [CPU:] The ~\output~ routine is called for each line,
1989 % and the page-search is done.
1990 % \item
1991 % [DISK:] One line of output to the aux-file for each
1992 % numbered line
1993 % \item
1994 % [MEM:] One macro per page. Great improvement over v1.02,
1995 % which had one control sequence per line in
1996 % addition. It blew the hash table after some five
1997 % thousand lines.
1998 % \end{description}
1999 %
2000 % \subsection{%
2001 % Twocolumn mode (New v3.06)
2002 % \unskip}
2003 %
2004 % Twocolumn mode requires another patch to the ~\output~
2005 % routine, in order to print a column tag to the .aux
2006 % file.
2007
2008 \AtBeginDocument{% v4.2, revtex4.cls (e.g.).
2009 % <- TODO v4.4+: Or better in \LineNoLaTeXOutput!?
2010 \let\@LN@orig@makecol\@makecol
2011 }
2012
2013 \def\@LN@makecol{%
2014 \@LN@orig@makecol
2015 \setbox\@outputbox \vbox{%
2016 \boxmaxdepth \@maxdepth
2017 \protected@write\@auxout{}{%
2018 \string\def\string\@LN@column{\if@firstcolumn1\else2\fi}%
2019 }%
2020 \box\@outputbox
2021 }% \vbox
2022 } %% TODO cf. revtexln.sty.
2023
2024 \def\@LN@column{1}
2025
2026 \ifdefined\IfFormatAtLeastTF
2027 \IfFormatAtLeastTF{2025-06-01}{
2028 % disable \@LN@makecol
2029 \AtBeginDocument{%
2030 \let\@LN@makecol\@makecol
2031 }
2032 % replace with hook code
2033 \AddToHook{build/column/after}{%
2034 \setbox\@outputbox \vbox to\ht\@outputbox{%
2035 \boxmaxdepth \@maxdepth
2036 \protected@write\@auxout{}{%
2037 \string\def\string\@LN@column{\if@firstcolumn1\else2\fi}%
2038 }%
2039 \unvbox\@outputbox
2040 }%
2041 }
2042 }{
2043 }
2044 \fi
2045
2046 %
2047 % \subsection{%
2048 % Numbering modulo $m$, starting at $f$
2049 %% Numbering modulo 5
2050 % \unskip}\label{ss:Mod}
2051 %
2052 % Most users want to have only one in five lines numbered.
2053 % ~\LineNumber~ is supposed to produce the outfit of the
2054 % line number attached to the line, while ~\thelinenumber~
2055 % is used also for references, which should appear even if
2056 % they are not multiples of five.
2057 %
2058 % (New v4.00) Moreover, some users want to
2059 % control which line number should be printed first. Support
2060 % of this is now introduced here---see ~\firstlinenumber~
2061 % below.---~numline.sty~ by Michael Jaegermann and
2062 % James Fortune offers controlling which \emph{final}
2063 % line numbers should not be printed. What is
2064 % it good for? We ignore this here until some user demands
2065 % it.---Peter Wilson's ~ledmac.sty~ offers much different
2066 % choices of line numbers to be printed, due to Wayne Sullivan.
2067 % (/New v4.00)
2068 %
2069 % (New v4.22) ~\c@linenumbermodulo~ is rendered a
2070 % fake counter, as discussed since v4.00. So it can
2071 % no longer be set by ~\setcounter~. ~\modulolinenumbers~
2072 % serves this purpose. Well, does anybody want to do
2073 % what worked with ~\addtocounter~? (Then please tell
2074 % me.)---At least, ~\value~ still works. For the same
2075 % purpose I rename the fake `firstlinenumber' counter
2076 % ~\n@...~ to ~\c@...~. (/New v4.22)
2077 % \begin{old}\begin{verbatim}
2078 % % \newcount\c@linenumbermodulo % removed for v4.22
2079 % \end{verbatim}
2080 % \end{old}
2081 %
2082 %% Removed for v4.22:
2083 %% (UL) On my question why, e.g.,
2084 %% ~\chardef~ would not have sufficed, Stephan couldn't remember
2085 %% exactly; guessed that he wanted to offer \LaTeX\ counter
2086 %% facilities. However, the typical ones don't come this way.
2087 %% So I'm quite sure that I will change this next time.
2088 %%
2089 %% However, I observed at least two times that users gave a very
2090 %% high value to ~\c@linenumbermodulo~ in order to suppress
2091 %% printing of the line number. One of these users preferred an
2092 %% own way of handling line numbers, just wanted to use
2093 %% ~\linelabel~ and ~ednotes.sty~ features. Should we support this?
2094 %% I rather would like to advise them to
2095 %% ~\let\makeLineNumber\relax~. (/UL)
2096 %
2097 % (New v4.00) \par
2098 % ~\themodulolinenumber~ waits for being declared
2099 % ~\LineNumber~ by ~\modulolinenumbers~. (This has
2100 % been so before, no change.) Here is how it
2101 % looked before:
2102 % \begin{old}\begin{verbatim}
2103 % % \def\themodulolinenumber{{\@tempcnta\c@linenumber
2104 % % \divide\@tempcnta\c@linenumbermodulo
2105 % % \multiply\@tempcnta\c@linenumbermodulo
2106 % % \ifnum\@tempcnta=\c@linenumber\thelinenumber\fi
2107 % % }}
2108 % \end{verbatim}
2109 % \end{old}
2110 % (UL) This was somewhat slow. This arithmetic
2111 % happens at every line. This time I tend to declare an extra
2112 %% TODO v4.4+
2113 % line counter (as opposed to my usual recommendations to use
2114 % counters as rarely as possible) which is stepped every line.
2115 % It could be incremented in the same way as ~\c@LN@truepage~
2116 % is incremented via ~\cl@page~! This is another point in favour
2117 % of ~{linenumber}~ being a \LaTeX\ counter!
2118 % When this new counter equals ~\c@linenumbermodulo~, it is reset,
2119 % and ~\thelinenumber~ is executed.---It gets much slower by my
2120 % support of controlling the first line number below. I should
2121 % improve this.---On
2122 %% %% TODO v4.4+--pagewise!?
2123 % the other hand, time expense means very little nowadays,
2124 % while the number of \TeX\ counters still is limited.
2125 %
2126 % For the same purpose, moreover, attaching the line number
2127 % box could be intercepted earlier (in ~\MakeLineNo~),
2128 % without changing ~\LineNumber~. However, this may be
2129 % bad for the latter's announcement as a wizard interface
2130 % in section_\ref{s:UserCmds}.
2131 %%
2132 %% I wonder about Stephan's group. Its only effect is that
2133 %% ~\@tempcnta~ is restored after using it. What for is this?
2134 %% I tend to remove the group braces. %% TODO v4.4+
2135 % (/UL)
2136 %
2137 % Here is the new code. It is very near to my ~lnopatch.sty~
2138 % code which introduced the first line number feature
2139 % before.---I add starting with a ~\relax~ which is so often
2140 % recommended---without understanding this really. At least,
2141 % it will not harm.---Former group braces appear as
2142 % ~\begingroup~/~\endgroup~ here.
2143
2144 \def\themodulolinenumber{\relax
2145 \ifnum\c@linenumber<\c@firstlinenumber \else
2146 \begingroup
2147 \@tempcnta\c@linenumber
2148 \advance\@tempcnta-\c@firstlinenumber
2149 \divide\@tempcnta\c@linenumbermodulo
2150 \multiply\@tempcnta\c@linenumbermodulo
2151 \advance\@tempcnta\c@firstlinenumber
2152 \ifnum\@tempcnta=\c@linenumber \thelinenumber \fi
2153 \endgroup
2154 \fi
2155 }
2156
2157 % (/New v4.00)
2158 %
2159 % The user command to set the modulo counter:
2160 % (New v4.31) \dots\ a star variant is introduced to implement
2161 % Hillel Chayim Yisraeli's idea to print the first line number
2162 % after an interruption of the edited text by some editor's
2163 % text, regardless of the modulo. If it is 1, it is printed only
2164 % with ~\firstlinenumber{1}~. I.e., you use ~\modulolinenumbers*~
2165 % for the new feature, without the star you get the simpler
2166 % behaviour that we have had so far. And you can switch back
2167 % from the refined behaviour to the simple one by using
2168 % ~\modulolinenumbers~ without the star.---This enhancement
2169 % is accompanied by a new package option ~modulo*~ which just
2170 % executes ~\modulolinenumbers*~
2171 % (subsection_\ref{ss:v3opts}).---`With ~\firstlinenumber{1}~'
2172 % exactly means: `1' is printed if and only if the last
2173 % ~\firstlinenumber~ before or in the paragraph that follows
2174 % the ``interruption'' has argument `1' (or something
2175 % \emph{expanding} to `1', or (to) something that \TeX\
2176 % ``reads'' as 1, e.g.: a \TeX\ count register storing
2177 % 1).---At present, this behaviour may be unsatisfactory with
2178 % pagewise line-numbering $\dots$ I'll make an experimental
2179 % extra package if someone complains \dots
2180
2181 \newcommand\modulolinenumbers{%
2182 \@ifstar
2183 {\def\@LN@maybe@moduloresume{%
2184 \global\let\@LN@maybe@normalLineNumber
2185 \@LN@normalLineNumber}%
2186 \@LN@modulolinenos}%
2187 {\let\@LN@maybe@moduloresume\relax \@LN@modulolinenos}%
2188 }
2189
2190 \global\let\@LN@maybe@normalLineNumber\relax
2191 \let\@LN@maybe@moduloresume\relax
2192 \gdef\@LN@normalLineNumber{%
2193 \ifnum\c@linenumber=\c@firstlinenumber \else
2194 \ifnum\c@linenumber>\@ne
2195 \def\LineNumber{\thelinenumber}%
2196 \fi
2197 \fi
2198 %%
2199 % ~\def~ instead of ~\let~ enables taking account of a
2200 % redefinition of ~\thelinenumber~ in a present numbering
2201 % environment (e.g.).
2202 %%
2203 \global\let\@LN@maybe@normalLineNumber\relax}
2204
2205 % Instead of changing ~\LineNumber~ directly by
2206 % ~LN@moduloresume~, these tricks enable ~\modulolinenumbers*~
2207 % to act as locally as I can make it. I don't know how to
2208 % avoid that the output routine switches back to the normal
2209 % modulo behaviour by a global change. (An ~\aftergroup~ may
2210 % fail in admittedly improbable cases.)
2211
2212 \newcommand*\@LN@modulolinenos[1][\z@]{%
2213 %%
2214 % The definition of this macro is that of the former
2215 % ~\modulolinenumbers~. (/New v4.31)
2216 %%
2217 \let\LineNumber\themodulolinenumber
2218 \ifnum#1>\@ne
2219 \chardef % v4.22, note below
2220 \c@linenumbermodulo#1\relax
2221 \else\ifnum#1=\@ne
2222 % \begin{old}\begin{verbatim}
2223 % % \def\LineNumber{\thelinenumber}%
2224 % \end{verbatim}
2225 % \end{old}
2226 % (New v4.00) I am putting something here to enable
2227 % ~\firstlinenumber~ with $~\c@linenumbermodulo~=1$.
2228 % With ~lnopatch.sty~, a trick was offered for this purpose.
2229 % It is now obsolete.
2230 %
2231 \def\LineNumber{\@LN@ifgreat\thelinenumber}%
2232 %%
2233 % (/New v4.00)
2234 %%
2235 \fi\fi
2236 }
2237
2238 % (New v4.00) The default of ~\@LN@ifgreat~ is
2239
2240 \let\@LN@ifgreat\relax
2241
2242 % The previous changes as soon as ~\firstlinenumber~ is used:
2243
2244 \newcommand*\firstlinenumber[1]{%
2245 \chardef\c@firstlinenumber#1\relax
2246 %%
2247 % No counter, little values allowed only---OK?---(UL)
2248 % The change is local---OK? The good thing is that
2249 % ~\global\firstlinenumber{~\angle{number}~}~ works. Moreover,
2250 % ~\modulolinenumbers~ acts locally as well. (/UL)
2251 %
2252 % (New v4.31)
2253 %%
2254 \let\@LN@ifgreat\@LN@ifgreat@critical}
2255
2256 \def\@LN@ifgreat@critical{%
2257 \ifnum\c@linenumber<\c@firstlinenumber
2258 \expandafter \@gobble
2259 \fi}%
2260
2261 % (/New v4.31)
2262 %
2263 % The default
2264 % value of ~\c@firstlinenumber~ %% v4.31
2265 % is 0. This is best for what one would expect from modulo
2266 % printing.
2267
2268 \let\c@firstlinenumber=\z@
2269
2270 %
2271 % For usage and effects of ~\modulolinenumbers~ and %% v4.31
2272 % ~\firstlinenumbers~, please consult section_\ref{s:UserCmds}.
2273 % Two details on ~\firstlinenumbers~ here:
2274 % (i)_~\firstlinenumber~ acts on a paragraph if and only if
2275 % (a)_the paragraph is broken into lines ``in line-numbering
2276 % mode'' (after ~\linenumbers~, e.g.);
2277 % (b)_it is the last occurrence of a ~\firstlinenumbers~
2278 % before or in the paragraph.
2279 % (The practical applications of this that I can imagine
2280 % don't seem appealing to me.)
2281 % Cf._the explanation above of how ~\modulolinenumbers~ and
2282 % ~\firstlinenumbers~ interact---for this and for (ii),
2283 % which is concerned with possible arguments for
2284 % ~\firstlinenumbers~.
2285 %
2286 % Note that the line numbers of the present section
2287 % demonstrate the two devices. (/New v4.00)
2288
2289 %%\setcounter{linenumbermodulo}{5}
2290 \chardef\c@linenumbermodulo=5 % v4.2; ugly?
2291 \modulolinenumbers[1]
2292
2293 % (New v4.22) The new implementation through ~\chardef~
2294 % decreases the functionality and raises certain compatibility
2295 % problems. I face this without fear. The maximum modulo value
2296 % is now ~255~. I expect that this suffices for usual applications.
2297 % However, some users have ``abused'' ~lineno.sty~ to get
2298 % ~ednotes.sty~ features without line numbers, so have set the
2299 % modulo to a value beyond the total number of lines in their
2300 % edition. This ought to be replaced by
2301 % ~\let\makeLineNumber\relax~. (/New v4.22)
2302 %
2303 % \section{%
2304 % Package options
2305 % \unskip}\label{s:Opts}
2306 %
2307 % (New v4.1)
2308 % The last heading formerly was the heading of what is now
2309 % subsection_\ref{ss:v3opts}. The options declared there were
2310 % said to execute user commands only. This was wrong already
2311 % concerning ~displaymath~ and ~hyperref~. At least, however,
2312 % these options were no or almost no occasion to skip definitions
2313 % or allocations. This is different with the options that we now
2314 % insert.
2315 %
2316 %% (New v4.2) v4.00 moved the ``options'' below the
2317 %% ``extensions''. This was bad with ~\do@mlineno~ in
2318 %% subsection_\ref{ss:v3opts} which is to control
2319 %% subsection_\ref{ss:display}---undone here. (/New v4.2)
2320 %
2321 % \subsection{%
2322 % Extended referencing to line numbers. (v4.2)
2323 % \unskip}
2324 % This subsection explains and declares package option ~addpageno~. %% v4.31
2325 %
2326 % If a line to whose number you refer by ~\ref~ is not on the
2327 % present page, it may be useful to add the number of the page
2328 % on which the line occurs---and perhaps it should not be added
2329 % otherwise. In general, you could use the Standard \LaTeX\
2330 % package varioref for this. However, the latter usually
2331 % produces verbose output like `on the preceding page'---
2332 % unless costumized---, while in critical editions, e.g., one
2333 % may prefer just adding the page number and some mark on the
2334 % left of the line number, irrespectively of how far the page is
2335 % apart etc. To support this, package option ~addpageno~
2336 % provides a command ~\vpagelineref~ to be used in place of
2337 % ~\ref~. This produces, e.g., `34.15' when referring to line_15
2338 % on page_34 while the present page is not 34. You can customize
2339 % the outcome, see the package file ~vplref.sty~ where the code
2340 % and further details are. You may conceive of
2341 % ~\vpagelineref~ as a certain customization of varioref's
2342 % ~\vref~.
2343 %
2344 % This implies that option ~addpageno~ requires the files
2345 % ~vplref.sty~ and ~varioref.sty~. ~addpageno~ automatically
2346 % loads both of them. Yet you can also load ~varioref.sty~
2347 % on your own to use its package options.
2348 %
2349 % Of course, you might better introduce a shorter command name
2350 % for ~\vpagelineref~ for your work, while we cannot predict
2351 % here what shorthand will fit your work. E.g.,
2352 % ~\newcommand{\lref}{\vpagelineref}~.
2353 %
2354 % If you really want to add the page number in \emph{any} case,
2355 % use, e.g., some ~\myref~ instead of ~\ref~, after
2356 % \[~newcommand*{\myref}{\pageref{#1}.\ref{#1}}~\]
2357 % or what you like. You don't need the ~addpageno~ option in
2358 % this case.
2359 %
2360 % ~addpageno~ is due to a suggestion by Sergei Mariev.
2361
2362 \DeclareVoidOption{addpageno}{%
2363 \AtEndOfPackage{\RequirePackage{vplref}[2005/04/25]}}
2364
2365 % \subsection{%
2366 % \scs{linelabel} in math mode
2367 % \unskip}\label{ss:MathRef}
2368 %
2369 % We have made some first steps towards allowing ~\linelabel~ in
2370 % math mode. Because our code for this is presently experimental,
2371 % we leave it to the user to decide for the experiment by calling
2372 % option ~mathrefs~. We are in a hurry now and thus leave the
2373 % code, explanations, and discussion in the separate package
2374 % ~ednmath0.sty~. Maybe we later find the time to improve the
2375 % code and move the relevant content of ~ednmath0.sty~ to here.
2376 % The optimal situation would be to define ~\linelabel~ from
2377 % the start so it works in math mode, omitting the ~mathrefs~
2378 % option.
2379 %
2380 % Actually, this package even provides adjustments for analogously
2381 % allowing ~ednotes.sty~ commands in math mode. Loading the package
2382 % is postponed to ~\AtBeginDocument~ when we know whether these
2383 % adjustments are needed.
2384
2385 \DeclareVoidOption{mathrefs}{\AtBeginDocument
2386 {\RequirePackage{ednmath0}[2004/08/20]}}
2387
2388 %
2389 % \subsection{%
2390 % Arrays, tabular environments (Revised v4.11)
2391 % \unskip}\label{ss:Tab}
2392 %
2393 % This subsection explains and declares package options %% v4.31
2394 % ~edtable~, ~longtable~, and ~nolongtablepatch~.
2395 %
2396 % The standard \LaTeX\ tabular environments come as single
2397 % boxes, so the ~lineno.sty~ versions before v4.00 treated them as
2398 % (parts of) single lines, printing (at most) one line number
2399 % beside each and stepping the line number counter once only.
2400 % Moreover, ~\linelabel~s got lost. Of course, tables are
2401 % usually so high that you will want to treat each row like a
2402 % line. (Christian Tapp even desires that the lines of table
2403 % entries belonging to a single row are treated like ordinary
2404 % lines.) Footnotes get lost in such environments as well, which
2405 % was bad for ~ednotes.sty~.
2406 %
2407 % We provide adjustments to count lines, print their numbers
2408 % etc.\ as desired at least for \emph{some} \LaTeX\ tabular
2409 % environments. (Like with other details, ``some'' is to some
2410 % extent explained in ~edtable.sty~.) We do this similarly as
2411 % with option ~mathrefs~ before. We leave code
2412 % and explanations in the separate package ~edtable.sty~.
2413 % (For wizards: this package provides adjustments for
2414 % ~ednotes.sty~ as well. However, in the present case we don't try
2415 % to avoid them unless ~ednotes.sty~ is loaded.)
2416 % Package option ~edtable~
2417 % defines---by loading ~edtable.sty~---an environment ~{edtable}~
2418 % which is able to change some \LaTeX\ tabular environments
2419 % with the desired effects. (v4.11: ~edtable.sty~ v1.3 counts
2420 % \LaTeX's ~{array}~ [etc.\@] as a ``tabular environment'' as
2421 % well.)
2422 %
2423 % The ~{edtable}~ environment doesn't help with ~longtable.sty~,
2424 % however. To make up for this, ~{longtable}~ is adjusted in a
2425 % different way---and this happens only when another ~lineno.sty~
2426 % option ~longtable~ is called. In this case, option ~edtable~
2427 % needn't be called explicitly: option ~longtable~ works as if
2428 % ~edtable~ had been called.
2429 %
2430 % Now, we are convinced that vertical spacing around
2431 % ~{longtable}~ works wrongly---see \LaTeX\ bugs database
2432 % tools/3180 and 3485, or see explanations in the package
2433 % ~ltabptch.sty~ (which is to be obtained from CTAN folder
2434 % \path{macros/latex/ltabptch}). Our conviction is so strong
2435 % that the ~longtable~ option loads---after ~longtable.sty~---the
2436 % patch package ~ltabptch.sty~. If the user doesn't want this
2437 % (maybe preferring her own arrangement with the vertical
2438 % spacing), she can forbid it by calling ~nolongtablepatch~.
2439 %
2440 % The following code just collects some choices, which are
2441 % then executed in section_\ref{ss:ExOpt}. We use an ~\if...~
2442 % without ~\newif~ since ~\if...true~ and ~\if...false~
2443 % would occur at most two times and only within the present
2444 % package. (~\AtEndOfClass{\RequirePackage{edtable}}~
2445 % could be used instead, I just overlooked this. Now I don't
2446 % change it because it allows to change the version requirement
2447 % at one place only.)
2448
2449 \let\if@LN@edtable\iffalse
2450
2451 \DeclareVoidOption{edtable}{\let\if@LN@edtable\iftrue}
2452
2453 \DeclareVoidOption{longtable}{\let\if@LN@edtable\iftrue
2454 \PassOptionsToPackage{longtable}{edtable}}
2455
2456 \DeclareVoidOption{nolongtablepatch}{%
2457 \PassOptionsToPackage{nolongtablepatch}{edtable}}
2458
2459 % (/New v4.1)
2460 %
2461 % \subsection{%
2462 % Switch among settings
2463 % \unskip}\label{ss:v3opts}
2464 %
2465 % There is a bunch of package options that execute %% v4.2
2466 %% There is a bunch of package options, all of them executing
2467 %% executing only user commands (see below). %% Cf. start of section.
2468 % user commands only.
2469 %
2470 % Options ~left~ (~right~) put the line numbers on the left
2471 % (right) margin. This works in all modes. ~left~ is the
2472 % default.
2473
2474 \DeclareVoidOption{left}{\leftlinenumbers*}
2475
2476 \DeclareVoidOption{right}{\rightlinenumbers*}
2477
2478 % Option ~switch~ (~switch*~) puts the line numbers on the
2479 % outer (inner) margin of the text. This requires running
2480 % the pagewise mode, but we turn off the page offset
2481 % subtraction, getting sort of running numbers again. The
2482 % ~pagewise~ option may restore true pagewise mode later.
2483
2484 \DeclareVoidOption{switch}{\setpagewiselinenumbers
2485 \switchlinenumbers
2486 \runningpagewiselinenumbers}
2487
2488 \DeclareVoidOption{switch*}{\setpagewiselinenumbers
2489 \switchlinenumbers*%
2490 \runningpagewiselinenumbers}
2491
2492 % In twocolumn mode, we can switch the line numbers to
2493 % the outer margin, and/or start with number 1 in each
2494 % column. Margin switching is covered by the ~switch~
2495 % options.
2496
2497 \DeclareVoidOption{columnwise}{\setpagewiselinenumbers
2498 \columnwiselinenumberstrue
2499 \realpagewiselinenumbers}
2500
2501 % The options ~pagewise~ and ~running~ select the major
2502 % line number mechanism. ~running~ line numbers refer to a real
2503 % counter value, which can be reset for any paragraph,
2504 % even getting multiple paragraphs on one page starting
2505 % with line number one. ~pagewise~ line numbers get a
2506 % unique hidden number within the document, but with the
2507 % opportunity to establish the page on which they finally
2508 % come to rest. This allows the subtraction of the page
2509 % offset, getting the numbers starting with 1 on top of each
2510 % page, and margin switching in twoside formats becomes
2511 % possible. The default mode is ~running~.
2512 %
2513 % The order of declaration of the options is important here
2514 % ~pagewise~ must come after ~switch~, to overide running
2515 % pagewise mode. ~running~ comes last, to reset the running
2516 % line number mode, e.g, after selecting margin switch mode
2517 % for ~pagewise~ running. Once more, if you specify all
2518 % three of the options ~[switch,pagewise,running]~, the
2519 % result is almost nothing, but if you later say
2520 % ~\pagewiselinenumbers~, you get margin switching, with
2521 % real pagewise line numbers.
2522 %
2523 \DeclareVoidOption{pagewise}{\setpagewiselinenumbers
2524 \realpagewiselinenumbers}
2525
2526 \DeclareVoidOption{running}{\setrunninglinenumbers}
2527
2528 % The option ~modulo~ causes only those linenumbers to be
2529 % printed which are multiples of five.
2530
2531 \DeclareVoidOption{modulo}{\modulolinenumbers\relax}
2532
2533 % Option ~modulo*~ modifies ~modulo~ in working like
2534 % ~\modulolinenumbers*~---see section_\ref{s:UserCmds}.
2535
2536 \DeclareVoidOption{modulo*}{\modulolinenumbers*\relax}
2537
2538 % The package option ~mathlines~ switches the behavior of
2539 % the ~{linenomath}~ environment with its star-form.
2540 % Without this option, the ~{linenomath}~ environment does
2541 % not number the lines of the display, while the star-form
2542 % does. With this option, its just the opposite.
2543 %
2544 %%% 1999-06-10: renamed ~displaymath~ to ~mathlines~.
2545
2546 \DeclareVoidOption{mathlines}{\linenumberdisplaymath}
2547
2548 % ~displaymath~ now calls for wrappers of the standard
2549 % \LaTeX\ display math environment. This was previously
2550 % done by ~mlineno.sty~.
2551 %
2552 % (New v4.3) Option `displaymath' becomes default according
2553 % to Erik \mbox{Luijten}'s suggestion. I was finally convinced
2554 % of this as soon as I discovered how to avoid a spurious line
2555 % number above ~\begin{linenomath}~ (subsection_\ref{ss:DM}).
2556 % ~\endlinenomath~ provides ~\ignorespaces~, so what could go
2557 % wrong now?
2558
2559 \DeclareVoidOption{displaymath}{%
2560 \PackageWarningNoLine{lineno}{Option [displaymath] is obsolete}}
2561
2562 %%\let\do@mlineno\relax
2563 %%\DeclareOption{displaymath}{\let\do@mlineno\@empty}
2564 % (/New v4.3)
2565 %
2566 % (New v5.3) Options `sep' and `width' set ~\linenumbersep~ (the separation of
2567 % the line number to the text) and ~\linenumberwidth~ (the width of the line
2568 % number box on the right margin) respectively; see section_\ref{s:CustHooks}.
2569
2570 \DeclareStringOption[\linenumbersep]{sep}
2571 \DeclareStringOption[\linenumberwidth]{width}
2572 \AtBeginDocument{%
2573 \linenumbersep=\lineno@sep%
2574 \linenumberwidth=\lineno@width%
2575 }
2576
2577 % (/New v5.3)
2578 %
2579 % \subsection{%
2580 % Compatibility with \texttt{hyperref} %% own subsec. v4.3.
2581 % \unskip}
2582 % The ~hyperref~ package, via ~nameref~, requires three more
2583 % groups in the second argment of a ~\newlabel~. Well, why
2584 % shouldn't it get them? (New v3.07) The presence of the
2585 % ~nameref~ package is now detected automatically
2586 % ~\AtBeginDocument~. (/New v3.07) (Fixed in v3.09) We try
2587 % to be smart, and test ~\AtBeginDocument~ if the ~nameref~
2588 % package is loaded, but ~hyperref~ postpones the loading of
2589 % ~nameref~ too, so this is all in vain.
2590 %
2591 % (New v4.3) But we can also test at the first ~\linelabel~.
2592 % Regarding the error-message for misplaced ~\linelabel~ from v4.11:
2593 % previously, ~\linenumbers~ rendered ~\linelabel~ the genuine
2594 % version of ~\linelabel~ from the start on. This doesn't work
2595 % now, since ~\@LN@linelabel~ may change its meaning after the
2596 % first ~\linenumbers~ and before a next one (if there is some).
2597 % (/New v4.3)
2598
2599 \DeclareVoidOption{hyperref}{%
2600 \PackageWarningNoLine{lineno}{Option [hyperref] is obsolete}}
2601
2602 \AtBeginDocument{%
2603 \@ifpackageloaded{nameref}{%
2604 %%
2605 % (New v4.3) ``Global'' is merely ``symbolic'' ~\AtBeginDoc...~.
2606 % If ~nameref~ is not detected here, the next ~\@LN@linelabel~
2607 % will do almost the same, then globally indeed.
2608 %%
2609 \gdef\@LN@ExtraLabelItems{{}{}{}}%
2610 }{%
2611 \global\let\@LN@@linelabel\@LN@linelabel
2612 \gdef\@LN@linelabel{%
2613 %%
2614 % ~\@ifpackageloaded~ is ``preamble only'', its---very
2615 % internal---preamble definition is replicated here:
2616 %%
2617 \expandafter
2618 \ifx\csname [email protected]\endcsname\relax \else
2619 \gdef\@LN@ExtraLabelItems{{}{}{}}%
2620 \fi
2621 %%
2622 % Now aim at the ``usual'' behaviour:
2623 %%
2624 \global\let\@LN@linelabel\@LN@@linelabel
2625 \global\let\@LN@@linelabel\relax
2626 \@LN@linelabel
2627 }%
2628 }%
2629 }
2630 %%
2631 % (New 5.4) Option to allow ~\linelabel~ with ~\nolinenumbers~.
2632
2633 \DeclareVoidOption{nolinelabelerror}{\def\@LN@LLerror{\relax}}
2634
2635 % (/New 5.4)
2636 %%
2637
2638 % (/New v4.3)
2639 %
2640 % (New v4.1)
2641 % \subsection{%
2642 % A note on calling so many options
2643 % \unskip}
2644 %
2645 % The number of package options may stimulate worrying about how to
2646 % \emph{enter} all the options that one would like to use---they may
2647 % not fit into one line. Fortunately, you can safely break code lines
2648 % after the commas separating the option names in the ~\usepackage~
2649 % command (no comment marks needed).
2650 %
2651 % \subsection{%
2652 % Execute options
2653 % \unskip}\label{ss:ExOpt}
2654 %
2655 % We stop declaring options and execute the ones that are
2656 % called by the user. (/New v4.1)
2657
2658 \ProcessKeyvalOptions*
2659
2660 % (New v4.1) Now we know whether ~edtable.sty~ is wanted
2661 % and (if it is) with which options it is to be called.
2662
2663 \if@LN@edtable \RequirePackage{edtable}[2005/03/07] \fi
2664
2665 % (/New v4.1)
2666 %
2667 % \section{%
2668 % Package extensions
2669 % \label{s:Xt}\unskip}
2670 %
2671 % Some of the extensions in this section were previously supplied
2672 % in separate ~.sty~ files.
2673 %
2674 % \subsection{%
2675 % \texttt{displaymath}
2676 % \unskip}\label{ss:display}
2677 %% (New v4.32)
2678 % (New v4.3) From now on, you no longer need to type
2679 % the ~{linenomath}~ environment with the ~\[~, ~{equation}~,
2680 % and ~{eqnarray}~ environments---and you no longer need to
2681 % use the former package option ~displaymath~ for this feature.
2682 % (/New v4.3)
2683 %% (/New v4.32)
2684 %
2685 % The standard \LaTeX\ display math environments are
2686 % wrapped in a ~{linenomath}~ environment.
2687 %
2688 % (New 3.05) The ~[fleqn]~ option of the standard
2689 % \LaTeX\ classes defines the display math
2690 % environments such that line numbers appear just
2691 % fine. Thus, we need not do any tricks when
2692 % ~[fleqn]~ is loaded, as indicated by presents of
2693 % the ~\mathindent~ register. (/New 3.05)
2694 %
2695 % (New 3.05a) for ~{eqnarray}~s we rather keep the
2696 % old trick. (/New 3.05a)
2697 %
2698 % (New 3.08) Wrap ~\[~ and ~\]~ into ~{linenomath}~,
2699 % instead of ~{displaymath}~. Also save the definition
2700 % of ~\equation~, instead of replicating the current
2701 % \LaTeX\ definition. (/New 3.08)
2702
2703 %%\ifx\do@mlineno\@empty
2704 \@ifundefined{mathindent}{
2705
2706 %% \AtBeginDocument{%
2707 \let\LN@displaymath\[%
2708 \let\LN@enddisplaymath\]%
2709 \renewcommand\[{\begin{linenomath}\LN@displaymath}%
2710 \renewcommand\]{\LN@enddisplaymath\end{linenomath}}%
2711 %
2712 \let\LN@equation\equation
2713 \let\LN@endequation\endequation
2714 \renewenvironment{equation}%
2715 {\linenomath\LN@equation}%
2716 {\LN@endequation\endlinenomath}%
2717 %% }
2718
2719 }{}% \@ifundefined{mathindent} -- 3rd arg v4.2, was \par!
2720
2721 %%\AtBeginDocument{%
2722 \let\LN@eqnarray\eqnarray
2723 \let\LN@endeqnarray\endeqnarray
2724 \renewenvironment{eqnarray}%
2725 {\linenomath\LN@eqnarray}%
2726 {\LN@endeqnarray\endlinenomath}%
2727 %%}
2728
2729 %%\fi
2730
2731 % (UL) Indeed. The \LaTeX\ macros are saved for
2732 % unnumbered mode, which is detected by ~\linenomath~.
2733 % (/UL)
2734 %
2735 % \subsection{%
2736 % Line numbers in internal vertical mode
2737 % \unskip}\label{ss:ILN}
2738 %
2739 % The command ~\internallinenumbers~ adds line numbers in
2740 % internal vertical mode, but with limitations: we assume
2741 % fixed baseline skip.
2742 %
2743 % (v4.22) v3.10 provided a global (~\global\advance~)
2744 % as well as a local version (star-form, using
2745 % ~\c@internallinenumber~). ~\resetlinenumbers~ acted
2746 % locally and was here used with the global version---save
2747 % stack danger, \TeX book p._301---in v4.00 I
2748 % disabled the global version therefore. Now I find that
2749 % it is better to keep a global version, and the now global
2750 % ~\resetlinenumbers~ is perfect for this. The global version
2751 % allows continuing the ``internal'' numbers in the ensuing
2752 % ``external'' text, and---unless reset by brackets
2753 % argument---continuing the above series of line numbers.
2754 % As with v3.10, the local version always starts with
2755 % line number one. A new ~\@LN@iglobal~ steps ~\global~ly
2756 % in the global version, otherwise it is ~\relax~.
2757 % (I also remove all my stupid discussions as of v4.00.
2758 % And I use ~\newcommand~.) (v4.22)
2759
2760 \let\@LN@iglobal\global % v4.22
2761
2762 \newcommand\internallinenumbers{\setrunninglinenumbers
2763 \let\@@par\internallinenumberpar
2764 \ifx\@par\@@@par\let\@par\internallinenumberpar\fi
2765 \ifx\par\@@@par\let\par\internallinenumberpar\fi
2766 \ifx\@par\linenumberpar\let\@par\internallinenumberpar\fi
2767 \ifx\par\linenumberpar\let\par\internallinenumberpar\fi
2768 \@ifnextchar[{\resetlinenumber}%]
2769 {\@ifstar{\let\c@linenumber\c@internallinenumber
2770 \let\@LN@iglobal\relax % v4.22
2771 \c@linenumber\@ne}{}}%
2772 }
2773
2774 \let\endinternallinenumbers\endlinenumbers
2775 \@namedef{internallinenumbers*}{\internallinenumbers*}
2776 \expandafter\let\csname endinternallinenumbers*\endcsname\endlinenumbers
2777
2778 \newcount\c@internallinenumber
2779 \newcount\c@internallinenumbers
2780
2781 \newcommand\internallinenumberpar{%
2782 \ifvmode\@@@par\else\ifinner\@@@par\else\@@@par
2783 \begingroup
2784 \c@internallinenumbers\prevgraf
2785 \setbox\@tempboxa\hbox{\vbox{\makeinternalLinenumbers}}%
2786 \ht\@tempboxa\z@
2787 \ifdim\prevdepth=-1000pt
2788 % \nointerlineskip is already set so we don't need set it again
2789 % (and we shouldn't back up)
2790 \else
2791 \dp\@tempboxa\prevdepth
2792 \nobreak\vskip-\prevdepth
2793 \nointerlineskip
2794 \fi
2795 \box\@tempboxa
2796 \endgroup
2797 \fi\fi
2798 }
2799
2800 \newcommand\makeinternalLinenumbers{%
2801 \ifnum\c@internallinenumbers>\z@ % v4.2
2802 \hb@xt@\z@{\makeLineNumber}%
2803 \@LN@iglobal % v4.22
2804 \advance\c@linenumber\@ne
2805 \advance\c@internallinenumbers\m@ne
2806 \expandafter\makeinternalLinenumbers\fi
2807 }
2808 % TODO v4.4+: star: line numbers right!? cf. lnocapt.sty
2809
2810 %
2811 % \subsection{%
2812 % Line number references with offset
2813 % \unskip}
2814 %
2815 % This extension defines macros to refer to line
2816 % numbers with an offset, e.g., to refer to a line
2817 % which cannot be labeled directly (display math).
2818 % This was formerly knows as ~rlineno.sty~.
2819 %
2820 % To refer to a pagewise line number with offset:
2821 % \begin{quote}
2822 % ~\linerefp[~\angle{OFFSET}~]{~\angle{LABEL}~}~
2823 % \end{quote}
2824 % To refer to a running line number with offset:
2825 % \begin{quote}
2826 % ~\linerefr[~\angle{OFFSET}~]{~\angle{LABEL}~}~
2827 % \end{quote}
2828 % To refer to a line number labeled in the same mode as currently
2829 % selected:
2830 % \begin{quote}
2831 % ~\lineref[~\angle{OFFSET}~]{~\angle{LABEL}~}~
2832 % \end{quote}
2833
2834 \newcommand\lineref{%
2835 \ifx\c@linenumber\c@runninglinenumber
2836 \expandafter\linerefr
2837 \else
2838 \expandafter\linerefp
2839 \fi
2840 }
2841
2842 \newcommand*\linerefp[2][\z@]{{%
2843 \let\@thelinenumber\thelinenumber
2844 \edef\thelinenumber{\advance\c@linenumber#1\relax
2845 \noexpand\@thelinenumber}%
2846 \ref{#2}%
2847 }}
2848
2849 % This goes deep into \LaTeX's internals.
2850
2851 \newcommand*\linerefr[2][\z@]{{%
2852 \def\@@linerefadd{\advance\c@linenumber#1}%
2853 \expandafter\@setref\csname r@#2\endcsname
2854 \@linerefadd{#2}%
2855 }}
2856
2857 \newcommand*\@linerefadd[2]{\c@linenumber=#1\@@linerefadd\relax
2858 \thelinenumber}
2859
2860 %% TODO v4.4+: Insert `LN' in internal command names?
2861 %
2862 % \subsection{%
2863 % Numbered quotation environments
2864 % \unskip}
2865 %
2866 % The ~{numquote}~ and ~{numquotation}~
2867 % environments are like ~{quote}~ and
2868 % ~{quotation}~, except there will be line
2869 % numbers.
2870 %
2871 % An optional argument gives the number to count
2872 % from. A star ~*~ (inside or outside the closing
2873 % ~}~) prevent the reset of the line numbers.
2874 % Default is to count from one.
2875 %
2876 % (v4.22: A local version using ~\c@internallinenumber~
2877 % might be useful, see subsection_\ref{ss:ILN}.) %% TODO v4.4+
2878
2879 \newcommand\quotelinenumbers
2880 {\@ifstar\linenumbers{\@ifnextchar[\linenumbers{\linenumbers*}}}
2881
2882 \newdimen\quotelinenumbersep
2883 \quotelinenumbersep=\linenumbersep
2884 \let\quotelinenumberfont\linenumberfont
2885
2886 \newcommand\numquotelist
2887 {\leftlinenumbers
2888 \linenumbersep\quotelinenumbersep
2889 \let\linenumberfont\quotelinenumberfont
2890 \addtolength{\linenumbersep}{-\@totalleftmargin}%
2891 \quotelinenumbers
2892 }
2893
2894 \newenvironment{numquote} {\quote\numquotelist}{\endquote}
2895 \newenvironment{numquotation} {\quotation\numquotelist}{\endquotation}
2896 \newenvironment{numquote*} {\quote\numquotelist*}{\endquote}
2897 \newenvironment{numquotation*}{\quotation\numquotelist*}{\endquotation}
2898
2899 %
2900 % \subsection{%
2901 % Frame around a paragraph
2902 % \unskip}
2903 %
2904 % The ~{bframe}~ environment draws a frame around
2905 % some text, across page breaks, if necessary.
2906 %
2907 % This works only for plain text paragraphs,
2908 % without special height lines. All lines must be
2909 % ~\baselineskip~ apart, no display math.
2910
2911 \newenvironment{bframe}
2912 {\par
2913 \@tempdima\columnwidth
2914 \advance\@tempdima 2\bframesep
2915 \setbox\bframebox\hb@xt@\columnwidth{%
2916 \hskip-\bframesep
2917 \vrule\@width\bframerule\@height\baselineskip\@depth\bframesep
2918 \advance\@tempdima-2\bframerule
2919 \hskip\@tempdima
2920 \vrule\@width\bframerule\@height\baselineskip\@depth\bframesep
2921 \hskip-\bframesep
2922 }%
2923 \hbox{\hskip-\bframesep
2924 \vrule\@width\@tempdima\@height\bframerule\@depth\z@}%
2925 \nointerlineskip
2926 \copy\bframebox
2927 \nobreak
2928 \kern-\baselineskip
2929 \runninglinenumbers
2930 \def\makeLineNumber{\copy\bframebox\hss}%
2931 }
2932 {\par
2933 \ifdim\prevdepth=-1000pt \else
2934 \kern-\prevdepth
2935 \fi
2936 \kern\bframesep
2937 \nointerlineskip
2938 \@tempdima\columnwidth
2939 \advance\@tempdima 2\bframesep
2940 \hbox{\hskip-\bframesep
2941 \vrule\@width\@tempdima\@height\bframerule\@depth\z@}%
2942 }
2943
2944 \newdimen\bframerule
2945 \bframerule=\fboxrule
2946
2947 \newdimen\bframesep
2948 \bframesep=\fboxsep
2949
2950 \newbox\bframebox
2951
2952 %
2953 % \subsection{%
2954 % \textsf{amsmath} patches
2955 % \unskip}\label{ss:AMSMath}
2956 %
2957 % (New v5.0) Patches ~amsmath~ to work with ~lineno~. These patches used to be
2958 % supplied by the ~linenoamsmath~ package. See ~linenoamsmathdemo.pdf~ for a
2959 % demonstration.
2960 % (/New v5.0)
2961 %
2962 % (New v5.1) ~lineno~ tries to use \LaTeX's hook management system to patch
2963 % ~amsmath~, so that the two packages may be loaded independently. This requires
2964 % the October 2020 release of \LaTeX. As a fallback for older releases, ~lineno~
2965 % tests whether ~amsmath~ had already been loaded (by testing for the presence
2966 % of the ~gather~ command) and if so applies the patches; otherwise if ~amsmath~
2967 % has not been loaded, no patches are applied, and a warning is issued.
2968 % (/New v5.1)
2969 %
2970 % (New v5.2) Fix ~lineno~ to work with ~amsmath~'s ~\allowdisplaybreaks~
2971 % option. A side effect is that now ~\\*~ suppresses a line number on that
2972 % line. This is because ~\\*~ prohibits a page break after a given line, and
2973 % ~lineno~ basically works by hijacking page breaks. It's probably not possible
2974 % to fix this without losing the behaviour of ~\\*~.
2975 % (/New v5.2)
2976 %
2977
2978 \ifdefined\AddToHook
2979 \def\@LN@amsmath@patches#1{\AddToHook{package/amsmath/after}{#1}}
2980 \else
2981 \ifdefined\endgather
2982 \def\@LN@amsmath@patches#1{#1}
2983 \else
2984 \PackageWarningNoLine{lineno}%
2985 {`amsmath' must be loaded before `lineno' for patches to be applied}
2986 \def\@LN@amsmath@patches#1{\relax}
2987 \fi
2988 \fi
2989
2990 \@LN@amsmath@patches{
2991 \newcommand*\@LN@amsmath@patch[1]{%
2992 \cspreto{#1}{\linenomath}%
2993 \cspreto{#1*}{\linenomath}%
2994 \csappto{end#1}{\endlinenomath}%
2995 \csappto{end#1*}{\endlinenomath}%
2996 }
2997 \newcount\@LN@amsmath@ams@eqpen
2998 \cspreto{math@cr@}{%
2999 %%% Uncommenting the following 2 lines restores the line number on a line
3000 %%% ended with \\*, by making \\* act just like \\. This is probably
3001 %%% undesirable, however, so these lines are disabled.
3002 % \global\@eqpen%
3003 % \ifnum\dspbrk@lvl <\z@ \interdisplaylinepenalty \else -\@getpen\dspbrk@lvl \fi%
3004 \advance\@eqpen\@LN@amsmath@ams@eqpen\relax%
3005 }
3006 \newcommand*\@LN@amsmath@patch@ams[1]{%
3007 \cspreto{#1}{%
3008 \linenomath%
3009 \postdisplaypenalty=0%
3010 \global\@LN@amsmath@ams@eqpen\interdisplaylinepenalty%
3011 }%
3012 \cspreto{#1*}{%
3013 \linenomath%
3014 \postdisplaypenalty=0%
3015 \global\@LN@amsmath@ams@eqpen\interdisplaylinepenalty%
3016 }%
3017 \csappto{end#1}{%
3018 \global\@LN@amsmath@ams@eqpen\z@%
3019 \endlinenomath%
3020 }%
3021 \csappto{end#1*}{%
3022 \global\@LN@amsmath@ams@eqpen\z@%
3023 \endlinenomath%
3024 }%
3025 }
3026 \@LN@amsmath@patch{equation}
3027 \@LN@amsmath@patch@ams{multline}
3028 \@LN@amsmath@patch@ams{gather}
3029 \@LN@amsmath@patch@ams{align}
3030 \@LN@amsmath@patch@ams{alignat}
3031 \@LN@amsmath@patch@ams{flalign}
3032 \let\@LN@amsmath@ams@mmeasure\mmeasure@
3033 \def\mmeasure@#1{%
3034 \global\@LN@amsmath@ams@eqpen\z@%
3035 \begingroup%
3036 \interdisplaylinepenalty=0%
3037 \@LN@amsmath@ams@mmeasure{#1\\}%
3038 \endgroup%
3039 \global\@LN@amsmath@ams@eqpen\interdisplaylinepenalty%
3040 }
3041 }
3042
3043 %
3044 %
3045 % \section{%
3046 % Move \scs{vadjust} items (New v4.00)
3047 % \unskip}\label{s:MVadj}
3048 %
3049 % This section completes reviving ~\pagebreak~, ~\nopagebreak~,
3050 % ~\vspace~, and the star and optional form of ~\\~. This was
3051 % started in section_\ref{ss:output} and resumed in
3052 % section_\ref{ss:MLN} and subsection_\ref{ss:calls}.
3053 % The problem was explained in section_\ref{ss:output}:
3054 % ~\vadjust~ items come out at a bad position, and the
3055 % \LaTeX\ commands named before work with ~\vadjust~ indeed.
3056 % Our solution was sketched there as well.
3057 %
3058 % According to the caveat in subsection_\ref{ss:OnOff} concerning
3059 % ~\ifLineNumbers~, the \LaTeX\ commands enumerated may go
3060 % wrong if you switch line numbering inside or at the end of
3061 % a paragraph.
3062 %% %% TODO v4.4+
3063 %
3064 % \subsection{%
3065 % Redefining \scs{vadjust}
3066 % \unskip}\label{ss:PVadj}
3067 %
3068 % ~\vadjust~ will temporarily be changed into the following
3069 % command.
3070
3071 \def\PostponeVadjust#1{%
3072 \global\let\vadjust\@LN@@vadjust
3073 %%
3074 % This undoes a ~\global\let\vadjust\PostponeVadjust~ which will
3075 % start each of the refined \LaTeX\ commands. The ~\global~s
3076 % are most probably superfluous. They might be useful should one
3077 % ~\vadjust~ appear in a group starting after the change of
3078 % ~\vadjust~ into ~\PostponeVadjust~.
3079 % (UL) Even the undoing may be superfluous, cf._discussion
3080 % in section_\ref{ss:ReDef} below. (UL)
3081 %%
3082 \vadjust{\penalty-\@Mppvacodepen}%
3083 \g@addto@macro\@LN@vadjustlist{#1\@lt}%
3084 }
3085 \let\@LN@@vadjust\vadjust
3086 \global\let\@LN@vadjustlist\@empty
3087 \global\let\@LN@do@vadjusts\relax
3088
3089 % These ~\global~s are just to remind that
3090 % all the changes of the strings after ~\let~ should be
3091 % ~\global~ (\TeX book p._301). ~\@LN@vadjustlist~ collects
3092 % the ~\vadjust~ items of a paragraph. ~\PassVadjustList~
3093 % tears one ~\vadjust~ item for the current line out of
3094 % ~\@LN@vadjustlist~ and puts it into ~\@LN@do@vadjusts~.
3095 % The latter is encountered each line in ~\MakeLineNo~
3096 % (section_\ref{ss:MLN}), while those \LaTeX\ ~\vadjust~
3097 % commands will come rather rarely. So I decided that
3098 % ~\@LN@do@vadjust~ is ~\relax~ until a ~\vadjust~ item
3099 % is waiting. In the latter case, ~\@LN@do@vadjusts~
3100 % is turned into a list macro which resets itself to
3101 % ~\relax~ when the other contents have been placed in
3102 % the vertical list.---~\PassVadjustList~ is invoked by
3103 % the output routine (section_\ref{ss:output}), so the
3104 % ~\box255~ must be put back.
3105
3106 \def\PassVadjustList{%
3107 \unvbox\@cclv
3108 \expandafter \@LN@xnext \@LN@vadjustlist \@@
3109 \@tempa \@LN@vadjustlist
3110 \ifx\@LN@do@vadjusts\relax
3111 \gdef\@LN@do@vadjusts{\global\let\@LN@do@vadjusts\relax}%
3112 \fi
3113 \expandafter \g@addto@macro \expandafter \@LN@do@vadjusts
3114 \expandafter {\@tempa}%
3115 }
3116
3117 %
3118 % \subsection{%
3119 % Redefining the \LaTeX\ commands
3120 % \unskip}\label{ss:ReDef}
3121 %
3122 % Now we change ~\pagebreak~ etc.\
3123 % so that they use ~\PostponeVadjust~ in place of ~\vadjust~.
3124 % We try to do this as independently as possible of the
3125 % implementation of the \LaTeX\ commands to be redefined.
3126 % Therefore, we don't just copy macro definition code from any
3127 % single implementation (say, latest \LaTeX) and insert our
3128 % changes, but attach a conditional
3129 % ~\global\let\vadjust\PostponeVadjust~
3130 % to their left ends in a way which should work rather
3131 % independantly of their actual code.
3132 % However, ~\vadjust~ should be the primitive again after
3133 % execution of the command. So the ~\global\let...~ may be used
3134 % only if it's guaranteed that a ~\vadjust~ is near.---(UL)
3135 % Sure? In line numbering mode, probably each ~\vadjust~
3136 % coming from a \LaTeX\ command should be ~\PostponeVadjust~.
3137 % ~\marginpar~s and floats seem to be the only cases which
3138 % are not explicitly dealt with in the present section.
3139 % This would be a way to avoid ~\@LN@nobreaktrue~!
3140 % Of course, the ~\vadjust~s that the present package uses
3141 % then must be replaced by ~\@LN@@vadjust~.---Maybe
3142 % next time. (/UL)
3143 %% %% TODO v4.4+
3144 %
3145 % The next command and something else will be added to the
3146 % \LaTeX\ commands we are concerned with here.
3147
3148 \DeclareRobustCommand\@LN@changevadjust{%
3149 \ifvmode\else\ifinner\else
3150 \global\let\vadjust\PostponeVadjust
3151 \fi\fi
3152 }
3153
3154 % (UL) What about math mode? Math display? Warn? (/UL)
3155 %% %% TODO v4.4+
3156 %
3157 % ~\@tempa~ will now become a two place macro which adds first
3158 % argument (single token), enclosed by ~\ifLineNumbers~\,\dots
3159 % ~\fi~ to the left of second argument. As long as we need it,
3160 % we can't use the star form of ~\DeclareRobustCommand~ or
3161 % the like, because AMS-\LaTeX\ uses ~\@tempa~ for ~\@ifstar~.
3162 % (New v4.41) And for the same reason, that ~\CheckCommand*~
3163 % had to be raised! (/New v4.41)
3164
3165 \CheckCommand*\@parboxrestore{\@arrayparboxrestore\let\\\@normalcr}
3166
3167 \def\@tempa#1#2{%
3168 \expandafter \def \expandafter#2\expandafter{\expandafter
3169 \ifLineNumbers\expandafter#1\expandafter\fi#2}%
3170 }
3171
3172 % (UL) This ~\ifLineNumber~ can be fooled by
3173 % ~\linenumbers~ ahead etc. It might be better to place
3174 % a signal penalty in any case and let the output routine
3175 % decide what to do.
3176 %%
3177 %% And when this has been done, remove warnings about this.
3178 % (/UL)
3179 %
3180 % We use the occasion to switch off linenumbers where they
3181 % don't work anyway and where we don't want them,
3182 % especially in footnotes:
3183
3184 \@tempa\nolinenumbers\@arrayparboxrestore
3185
3186 % We hope this suffices $\dots$ let's check one thing
3187 % at least: [(New v4.41) see ~\CheckCommand~ above (/New v4.41)]
3188 %
3189 % Now for the main theme of the section.
3190 % The next lines assume that ~\vspace~, ~\pagebreak~, and
3191 % ~\nopagebreak~ use ~\vadjust~ whenever they occur outside
3192 % vertical mode; moreover, that they don't directly read
3193 % an argument. Indeed ~\pagebreak~ and ~\nopagebreak~ first
3194 % call something which tests for a left bracket ahead,
3195 % while ~\vspace~ first tests for a star.
3196
3197 \@tempa\@LN@changevadjust\vspace
3198 \@tempa\@LN@changevadjust\pagebreak
3199 \@tempa\@LN@changevadjust\nopagebreak
3200
3201 % ~\\~, however, uses ~\vadjust~ only in star or optional form.
3202 % We relax independency of implementation in assuming
3203 % that ~\@normalcr~ is the fragile version of ~\\~
3204 % (and we use ~\@ifstar~!).
3205 %%
3206 %% \@ifstar reimplemented 1995/10/16, but seems to be much older.
3207 %% TODO v4.4+:
3208 %% \def\@LN@cr{%
3209 %% \@ifnextchar*{\@LN@changevadjust\@normalcr}%
3210 %% {\@ifnextchar[{\@LN@changevadjust\@normalcr}\@normalcr}%
3211 %% }
3212 %% ---same number of tokens, expansion step less.
3213 %%
3214 % (Using a copy of ~\\~ would be safer, but an ugly repetition
3215 % of ~\protect~.)
3216 %% %% TODO v4.4+
3217
3218 \protected\def\\{%
3219 \ifLineNumbers
3220 \expandafter \@LN@cr
3221 \else
3222 \expandafter \@normalcr
3223 \fi
3224 }
3225 \def\@LN@cr{%
3226 \@ifstar{\@LN@changevadjust\@normalcr*}%
3227 {\@ifnextchar[{\@LN@changevadjust\@normalcr}\@normalcr}%
3228 }
3229
3230 % Moreover we hope that ~\newline~ never leads to a ~\vadjust~,
3231 % although names of some commands invoked by ~\\~ contain
3232 % ~newline~. At last, this seems to have been OK since 1989 or
3233 % even earlier.
3234 %
3235 % \modulolinenumbers[1]
3236 % \firstlinenumber{0}
3237 % Let's have a few tests.\vspace*{.5\baselineskip}
3238 % Testing ~\pagebreak~ and ~\nopagebreak~ would be too expensive
3239 % here, but---oops!---we have just experienced a successful
3240 % ~\vspace*{.5\baselineskip}~. A
3241 % ~\\*[.5\baselineskip]~\\*[.5\baselineskip] may look even more
3242 % drastical, but this time we are happy about it. Note that the
3243 % line numbers have moved with the lines. Without our changes,
3244 % one line number\vadjust{\kern.5\baselineskip} would have
3245 % ``anticipated'' the move of the next line, just as you can
3246 % observe it now.
3247 % (/New v4.00)
3248 %
3249 % \switchlinenumbers
3250 %
3251 % \subsection{%
3252 % Reminder on obsoleteness
3253 % \unskip}
3254 %
3255 % (New v4.1) We have completed inclusion of the earlier
3256 % extension packages ~linenox0.sty~, ~linenox1.sty~, ~lnopatch.sty~,
3257 % and ~linenoamsmath~. If one of them is loaded, though,
3258 % we produce an error message before something weird happens.
3259 % We avoid ~\newif~ because the switchings occur so rarely.
3260
3261 \AtBeginDocument{%
3262 \let\if@LN@obsolete\iffalse
3263 \@ifpackageloaded{linenox0}{\let\if@LN@obsolete\iftrue}\relax
3264 \@ifpackageloaded{linenox1}{\let\if@LN@obsolete\iftrue}\relax
3265 \@ifpackageloaded{lnopatch}{\let\if@LN@obsolete\iftrue}\relax
3266 \@ifpackageloaded{linenoamsmath}{\let\if@LN@obsolete\iftrue}\relax
3267 \if@LN@obsolete
3268 \PackageError{lineno}{Obsolete extension package(s)}{%
3269 As of \fileversion, `lineno' includes the functionality of \MessageBreak
3270 `linenox0', `linenox1', `lnopatch', and `linenoamsmath'; \MessageBreak
3271 these packages are therefore obsolete and must not be loaded.}%
3272 \fi
3273 }
3274
3275 %
3276 % \modulolinenumbers[1]
3277 % \section{%
3278 % The final touch
3279 % \unskip}
3280 %
3281 % There is one deadcycle for each line number.
3282
3283 \advance\maxdeadcycles 100
3284
3285 \endinput
3286
3287 %
3288 % \section{%
3289 % The user commands
3290 % \unskip}\label{s:UserCmds}
3291 %
3292 % The user commands to turn on and off line numbering
3293 % are
3294 % \begin{description}\item
3295 % [|\linenumbers] \ \par
3296 % Turn on line numbering in the current mode.
3297 %
3298 % \item
3299 % [|\linenumbers*] \ \par$\qquad$
3300 % and reset the line number to 1.
3301 % \def\NL{\angle{number}]}\item
3302 %% %% Boldface italic occurs here, which is evil. (UL)
3303 % [|\linenumbers[\NL] \ \par$\qquad$
3304 % and start with \angle{number}.
3305 % \item
3306 % [|\nolinenumbers] \ \par
3307 % Turn off line numbering.
3308 % \item
3309 % [|\runninglinenumbers*[\NL] \ \par
3310 % Turn on ~running~ line numbers, with the same optional
3311 % arguments as ~\linenumbers~. The numbers are running
3312 % through the text over pagebreaks. When you turn
3313 % numbering off and on again, the numbers will continue,
3314 % except, of cause, if you ask to reset or preset the
3315 % counter.
3316 % \item
3317 % [|\pagewiselinenumbers] \ \par
3318 % Turn on ~pagewise~ line numbers. The lines on each
3319 % page are numbered beginning with one at the first
3320 % ~pagewise~ numbered line.
3321 % \item
3322 % [|\resetlinenumber[\NL] \ \par
3323 % Reset ~[~Set~]~ the line number to 1
3324 % ~[~\angle{number}~]~.
3325 % \item
3326 % [|\setrunninglinenumbers] \ \par
3327 % Switch to ~running~ line number mode. Do \emph{not}
3328 % turn it on or off.
3329 % \item
3330 % [|\setpagewiselinenumbers] \ \par
3331 % Switch to ~pagewise~ line number mode. Do \emph{not}
3332 % turn it on or off.
3333 % \item
3334 % [|\switchlinenumbers*] \ \par
3335 % Causes margin switching in pagewise modes. With the
3336 % star, put the line numbers on the inner margin.
3337 % \item
3338 % [|\leftlinenumbers*] \ \par
3339 % \item
3340 % [|\rightlinenumbers*] \ \par
3341 % Set the line numbers in the left/right margin. With the
3342 % star this works for both modes of operation, without
3343 % the star only for the currently selected mode.
3344 % \item
3345 % [|\runningpagewiselinenumbers] \ \par
3346 % When using the pagewise line number mode, do not
3347 % subtract the page offset. This results in running
3348 % line numbers again, but with the possibility to switch
3349 % margins. Be careful when doing line number
3350 % referencing, this mode status must be the same while
3351 % setting the paragraph and during references.
3352 % \item
3353 % [|\realpagewiselinenumbers] \ \par
3354 % Reverses the effect of ~\runningpagewiselinenumbers~.
3355 % \item
3356 % [|\modulolinenumbers[\NL] \ \par
3357 % Give a number only to lines which are multiples of
3358 % ~[~\angle{number}~]~. If \angle{number} is not specified, the
3359 % current value in the counter ~linenumbermodulo~ is
3360 % retained. \angle{number}=1 turns this off without changing
3361 % ~linenumbermodulo~. The counter is initialized to 5.
3362 %%
3363 %% %% TODO v4.4+: `counter', he says. Cf._above.
3364 %%
3365 %% (New v4.31)
3366 % \item
3367 % [|\modulolinenumbers*[\NL] \ \par
3368 % Like ~\modulolinenumbers~, the only difference being
3369 % that the first line number after a ~\linenumbers~
3370 % (or ~\runninglinenumbers~, ~\pagewiselinenumbers~,
3371 % ~\quotelinenumbers~) is printed regardless of the
3372 % modulo---yet `1' is printed only after (or \dots)
3373 % ~\firstlinenumber{1}~.
3374 % This also applies to the first line of a
3375 % ~{linenumbers}~ or respective environment.
3376 % See subsection_\ref{ss:Mod} for another explanation.
3377 % The behaviour may be unsatisfactory with pagewise
3378 % line-numbering.
3379 %% (/New v4.31)
3380 %% (New v4.00)
3381 % \item
3382 % [|\firstlinenumber] \ \par
3383 % ~\firstlinenumber{~\angle{filino}~}~ brings about that
3384 % (after it) line numbers less than \angle{filino} do
3385 % \emph{not} appear in the margin. Moreover, with
3386 % ~\modulolinenumbers[~\angle{number}~]~, just the line
3387 % numbers which are \angle{filino} plus a multiple of
3388 % \angle{number} are printed.---If you had
3389 % ~\firstlinenumber{~\angle{pos}~}~ with some $\mbox{\angle{pos}}>0$
3390 % and want to switch to printing multiples of, e.g.,
3391 % 4, you best do ~\modulolinenumbers[4]~ and
3392 % ~\firstlinenumber{0}~. (See subsection_\ref{ss:Mod}
3393 % for technical details.)
3394 %% (/New v4.00)
3395 % \item
3396 % [|\linenumberdisplaymath] \ \par
3397 % Number the lines of a display math in a ~{linenomath}~
3398 % environment, but do not in a ~{linenomath*}~
3399 % environment. This is used by the package option
3400 % ~[mathlines]~.
3401 % \item
3402 % [|\nolinenumberdisplaymath] \ \par
3403 % Do not Number the lines of a display math in a
3404 % ~{linenomath}~ environment, but do in a
3405 % ~{linenomath*}~ environment. This is the default.
3406 % \item
3407 % [|\linelabel] \ \par
3408 % Set a ~\linelabel{~\angle{foo}~}~ to the line number where
3409 % this commands is in. Refer to it with the \LaTeX\
3410 % referencing commands ~\ref{~\angle{foo}~}~ and
3411 % ~\pageref{~\angle{foo}~}~.
3412 % \end{description}
3413 % The commands can be used globally, locally within groups
3414 % or as environments. It is important to know that they
3415 %%
3416 %% %% TODO: \linelabel? others?
3417 %%
3418 % take action only when the ~\par~ is executed. The
3419 %%
3420 %% %% TODO: sure? ~\modulo...~, e.g.? well, in a sense ...
3421 %%
3422 % ~\end{~\angle{mode}~linenumbers}~ commands provide a ~\par~.
3423 % Examples:
3424 % \begin{verse}
3425 % ~{\linenumbers~ \angle{text} ~\par}~ \\
3426 % \ \\
3427 % ~\begin{linenumbers}~ \\
3428 % \angle{text} \\
3429 % ~\end{linenumbers}~ \\
3430 % \ \\
3431 % \angle{paragraph} ~{\linenumbers\par}~ \\
3432 % \ \\
3433 % ~\linenumbers~ \\
3434 % \angle{text} ~\par~ \\
3435 % ~\nolinenumbers~ \\
3436 % \ \\
3437 % ~\linenumbers~ \\
3438 % \angle{paragraph} ~{\nolinenumbers\par}~ \\
3439 % \end{verse}
3440 % (New v4.00)
3441 % However, the examples containing \angle{paragraph} show what you
3442 % should \emph{not} do, at least if you use ~\pagebreak~,
3443 % ~\nopagebreak~, ~\vspace~, ~\\*~ or
3444 % ~\\[~\angle{space}~]~---cf._section_\ref{s:MVadj}.
3445 %
3446 % The same care should be applied to the ``wizard'' devices
3447 % ~\ifLineNumbers~ (subsection_\ref{ss:OnOff}) and
3448 % ~\PostponeVadjust~ (section_\ref{ss:PVadj}).
3449 % (/New v4.00)
3450 %
3451 % (New v4.11) Oh, and the commands and environments of
3452 % section_{s:Xt} are missing. Sorry, I am in a hurry now.
3453 % May be next time.% %% TODO v4.4+
3454 % ---And the environments ~{linenomath}~ and ~{linenomath*}~should
3455 % get an own paragraph. In short, each math display, equation,
3456 % or ~{eqnarray}~ should be ``wrapped'' in one of ~{linenomath}~
3457 % and ~{linenomath*}~.
3458 %
3459 % \subsection{%
3460 % Customization hooks
3461 % \unskip}\label{s:CustHooks}
3462 %
3463 % There are several hooks to customize the appearance of the
3464 % line numbers, and some low level hooks for special
3465 % effects.
3466 % \begin{description}\item
3467 % [|\thelinenumber] \ \par
3468 % This macro should give the representation of the line
3469 % number in the \LaTeX-counter ~linenumber~. The
3470 % default is provided by \LaTeX: \par$\qquad$
3471 % ~\arabic{linenumber}~
3472 % \item
3473 % [|\makeLineNumberLeft] \ \par
3474 % This macro is used to attach a line number to the left
3475 % of the text page. This macro should fill an ~\hbox to 0pt~
3476 % which will be placed at the left margin of the
3477 % page, with the reference point aligned to the line to
3478 % which it should give a number. Please use the macro
3479 % ~\LineNumber~ to refer to the line number.
3480 %
3481 % The default definition is \par$\qquad$
3482 % ~\hss\linenumberfont\LineNumber\hskip\linenumbersep~
3483 % \item
3484 % [|\makeLineNumberRight] \ \par
3485 % Like ~\makeLineNumberLeft~, but for line numbers on
3486 % the right margin.
3487 %
3488 % The default definition is \par$\qquad$
3489 % ~\linenumberfont\hskip\linenumbersep\hskip\columnwidth~ \par$\qquad$
3490 % ~\hbox to\linenumberwidth{\hss\LineNumber}\hss~
3491 % \item
3492 % [|\linenumberfont] \ \par
3493 % This macro is initialized to \par$\qquad$
3494 % ~\normalfont\tiny\sffamily~
3495 % \item
3496 % [|\linenumbersep] \ \par
3497 % This dimension register sets the separation of the
3498 % line number to the text. Default value is ~10pt~.
3499 % \item
3500 % [|\linenumberwidth] \ \par
3501 % This dimension register sets the width of the line
3502 % number box on the right margin. The distance of the
3503 % right edge of the text to the right edge of the line
3504 % number is ~\linenumbersep~ + ~\linenumberwidth~. The
3505 % default value is ~10pt~.
3506 % \item
3507 % [|\theLineNumber] (for wizards) \ \par
3508 % This macro is called for printing a ~\newlabel~ entry
3509 % to the aux-file. Its definition depends on the mode.
3510 % For running line numbers it's just ~\thelinenumber~,
3511 % while in pagewise mode, the page offset subtraction
3512 % is done in here.
3513 % \item
3514 % [|\makeLineNumber] (for wizards) \ \par
3515 % This macro produces the line numbers. The definition
3516 % depends on the mode. In the running line numbers
3517 % mode it just expands ~\makeLineNumberLeft~.
3518 % \item
3519 % [|\LineNumber] (for wizards) \ \par
3520 % This macro is called by ~\makeLineNumber~ to typeset
3521 % the line number. This hook is changed by the modulo
3522 % mechanism
3523 %% %%%.
3524 % and by ~\firstlinenumber~.
3525 %% %% New v4.00
3526 % \end{description}
3527 %%
3528 %% TODO: \stepLineNumber---another wizard command!?
3529 %% Not sure, may be retreated.
3530 % \end{document}%D
3531 ------------------------------------------------------------------------------
3532 %SSTOPP
3533 %% TODO v4.4+: Check for unwanted comment marks in new comments
3534 %% (resulting from manual aligning): search `New v4.2'
3535 %% and/or ` % '!
3536 %% TODO v4.4+: Check for missing comment marks where a paragraph
3537 %% should end/start. Also to prevent empty "code" lines.
3538 %% Especially, new comments at section ends must be
3539 %% followed by comment mark lines.
3540 %% And prevent ~\par~s from blank lines in definitions!
3541 %% See `visual space' above.
3542 %% For proper appearance in lineno.tex, note that a comment
3543 %% in a final code line changes behaviour.
3544 %% TODO v4.4+: Require README for redistribution?
3545 %% TODO v4.4+: Since discussions of code have increased so much, it
3546 %% would be appropriate not to give to this file
3547 %% extension `.sty' (e.g., `dty'!??). ?? Is quickly read though!
3548 %% A .sty extraction may be possible even if the present
3549 %% file is neither a .doc nor a .dtx. (!???)
3550 %% Use awk line below (etc.) for .doc at least; + .ins or so.
3551 %% ^ must not be caps! To escape awk.
3552 %% TODO v4.4+: Underfull lines!? (due to long code quotations)
3553 %% TODO v4.4+: Sometimes paragraph indents may be appropriate.
3554 %% TODO Swap first line (`\iffalse...') with corresponding below.
3555 Or do *not* swap, maybe nawk is more reliable.
3556 %% TODO v4.4+: Ponder Stephan's mail from 2004/09/02.
3557 %% TODO v4.4+:
3558 %% use \@ET@makeLineNumber.
3559 %% plus almost all `(UL)'
3560 %% plus lots of bad boxes messages
3561 %% change v4.3 TODOs when postponed
3562 %% remove {old} environments.
3563
3564 ------------------------------------------------------------------------------
3565
3566 # awk command lines for v4.00, mixed with former ones:
3567
3568 echo "Don't bother about unknown 'iffalse'." # SHELL1
3569 nawk '/A[W]K/' lineno.sty | nawk -f - lineno.sty >lineno.tex; # SHELL1
3570
3571 BEGIN{DOC=-1; # AWK DOC A W K
3572 BEGINCODE = "\\begin{code}\\begin{verbatim}"; # AWK
3573 ENDCODE = "\\end{verbatim}\n\\end{code}"; } # AWK
3574 BEGINCODE = "% \\begin{macrocode}"; # DOC A W K
3575 ENDCODE = "% \\end{macrocode}"; } # DOC A W K
3576 /^[ \t]*$/ { ECNT++; next; } # AWK DOC A W K
3577 /\\documentclass/{ sub("article","ltxdoc") } # DOC A W K
3578 /%D$/ { sub("^%* *",""); sub("%D$",""); # DOC A W K
3579 print > "lineno.drv"; next } # DOC A W K
3580 /^%%/ { next; } # AWK DOC A W K
3581 /^%/ { if (!DOC) { print ENDCODE; } # AWK DOC A W K
3582 DOC=1; ECNT=0; # AWK DOC A W K
3583 sub("^% *",""); # AWK
3584 sub("^% *","% "); # DOC A W K
3585 print; next; } # AWK DOC A W K
3586 /%VERSION/ { sub("%VERSION",""); print; next; } # AWK
3587 /%SSTOPP/ { exit } # AWK
3588 DOC<0 { next } # AWK DOC A W K
3589 /^-+-$/ { if (!DOC) print ENDCODE; exit } # AWK DOC A W K
3590 { if (DOC) { ECNT=DOC=0; print BEGINCODE; } # AWK DOC A W K
3591 while (ECNT>0) { print " "; ECNT--; } # AWK DOC A W K
3592 print $0; } # AWK DOC A W K
3593
3594 # New v4.00, UL: know nothing about awk; found present solution
3595 # in hours of trial and error.
3596
3597 % Earlier (should be inhibited by %SSTOPP above and otherwise):
3598 echo "expect errors for unknown commands 'iffalse' and 'fi'";# SHELL0 SHELL#1
3599 awk '/A[W]K/' lineno.sty | awk -f - lineno.sty >lineno.tex; # SHELL0
3600 latex lineno; latex lineno; latex lineno; latex lineno; # SHELL0
3601 nawk '/A[W]K/' lineno4.sty | nawk -f - lineno4.sty >lineno4.tex; # SHELL#1
3602 latex lineno4; latex lineno4; latex lineno4; latex lineno4; # SHELL#1
3603
3604 awk '/DOC A [W] K/' lineno.sty | awk -f - lineno.sty >lineno.doc; # DOC SH
3605
3606 BEGIN{DOC=-1; # A#WK DOC A W K
3607 BEGINCODE = "\\begin{code}\\begin{verbatim}"; # A#WK
3608 ENDCODE = "\\end{verbatim}\n\\end{code}"; } # A#WK
3609 BEGINCODE = "% \\begin{macrocode}"; # DOC A W K
3610 ENDCODE = "% \\end{macrocode}"; } # DOC A W K
3611 /^[ \t]*$/ { ECNT++; next; } # A#WK DOC A W K
3612 /\\documentclass/{ sub("article","ltxdoc") } # DOC A W K
3613 /%D$/ { sub("^%* *",""); sub("%D$",""); # DOC A W K
3614 print > "lineno.drv"; next } # DOC A W K
3615 /^%%/ { next; } # A#WK DOC A W K
3616 /^%/ { if (!DOC) { print ENDCODE; } # A#WK DOC A W K
3617 DOC=1; ECNT=0; # A#WK DOC A W K
3618 sub("^% *",""); # A#WK
3619 sub("^% *","% "); # DOC A W K
3620 print; next; } # A#WK DOC A W K
3621 DOC<0 { next } # A#WK DOC A W K
3622 /^-+-$/ { if (!DOC) print ENDCODE; exit } # A#WK DOC A W K
3623 { if (DOC) { ECNT=DOC=0; print BEGINCODE; } # A#WK DOC A W K
3624 while (ECNT>0) { print " "; ECNT--; } # A#WK DOC A W K
3625 print $0; } # A#WK DOC A W K
3626
3627
3628 ------------------------------------------------------------------------------
3629
3630 If you are looking here because of the two top lines of the file:
3631
3632 A .tex documentation of this macro file can be obtained by
3633
3634 sh lineno.sty
3635
3636 under UNIX.--You may find this hint little helpful. One
3637 reason may be that the awk versions to which you have access
3638 don't work suitably. Another reason may be that you don't have
3639 access to UNIX (in some sense). However, a .tex, .dvi, or .pdf
3640 version of such a documentation should be available from CTAN,
3641 in the same folder as the present file. When we typed this, that
3642 folder was /macros/latex/contrib/lineno. If this has changed in
3643 the meantime, a CTAN search should lead you to a folder
3644 containing such a documentation. Or you may get help from one of
3645 the e-mail addresses above.