1 \iffalse; awk '/S[H]ELL1/' lineno.sty|sh;exit;
2 ... see bottom for .tex documentation ...
4 Macro file lineno.sty for LaTeX: attach line numbers, refer to them.
6 \def\fileversion{v4.41} \def\filedate{2005/11/02} %VERSION
8 %%% Copyright 1995--2003 Stephan I. B"ottcher <boettcher@physik.uni-kiel.de>;
9 %%% Copyright 2002--2005 Uwe L"uck, http://www.contact-ednotes.sty.de.vu
10 %%% for version 4 and code from former Ednotes bundle
11 %%% --author-maintained.
13 %%% This file can be redistributed and/or modified under
14 %%% the terms of the LaTeX Project Public License; either
15 %%% version 1.3a of the License, or any later version.
16 %%% The latest version of this license is in
17 %%% http://www.latex-project.org/lppl.txt
18 %%% We did our best to help you, but there is NO WARRANTY.
20 %%% $Id: lineno.sty,v 3.14.2.2 2004/09/13 19:30:39 stephan Exp $ %% was v4.00.
21 % \title{\texttt{\itshape
22 %% %% (UL 2004/10/09:) Italic TT is evil
23 %% %% ... or nice front page layout!?
25 % lineno.sty \ \fileversion\ \filedate
27 % A \LaTeX\ package to attach
28 % \\ line numbers to paragraphs
30 % Stephan I. B\"ottcher
33 % boettcher@physik.uni-kiel.de
34 % \\ http://contact-ednotes.sty.de.vu
35 %% \\ stephan@nevis.columbia.edu
36 %% \\ Stephan.Boettcher@cern.ch
39 % \documentclass[a4paper,12pt]{article}%D
40 % \usepackage{lineno}%D
42 % \catcode`\_\active\let_~
43 %% %% Beware math!? (/New v4.00)
47 % \def<#1>{$\langle${\itshape#1}\/$\rangle$}
49 %% (New v4.1: \tt star; in box anyway.)
50 % \def|#1{\ttfamily\string#1}
51 %% \def|#1{{\ttfamily\string#1}}
53 % \newenvironment{code}
54 % {\par\runninglinenumbers
55 % \modulolinenumbers[1]%
59 % {\normalfont\tiny\itshape}}
62 % {\makeatletter \gdef\scs#1{\texttt
63 % {\protect\@backslashchar#1}}}
64 % \def\old{\par\footnotesize}
68 % \gdef\path{\begingroup\catcode`\/\active
70 % \gdef\dopath#1{\slash\unpenalty#1\endgroup}}
74 %% \DocInput{lineno}%D
75 % \pagewiselinenumbers
77 % \pagestyle{headings}
81 %% %% New v4.00: `...section{%' + \unskip
87 % (New v4.00) Parts of former first section
88 % have been rendered separate subsections for package
89 % version_v4.00. (/New v4.00)
92 % Introduction to versions $\textrm{v}\lessthan4$
95 % This package provides line numbers on paragraphs.
96 % After \TeX\ has broken a paragraph into lines there will
97 % be line numbers attached to them, with the possibility to
98 % make references through the \LaTeX\ ~\ref~, ~\pageref~
99 % cross reference mechanism. This includes four issues:
101 % \item attach a line number on each line,
102 % \item create references to a line number,
103 % \item control line numbering mode,
104 % \item count the lines and print the numbers.
106 % The first two points are implemented through patches to
107 % the output routine. The third by redefining ~\par~, ~\@par~
108 % and ~\@@par~. The counting is easy, as long as you want
109 % the line numbers run through the text. If they shall
110 % start over at the top of each page, the aux-file as well
111 % as \TeX s memory have to carry a load for each counted line.
113 % I wrote this package for my wife Petra, who needs it for
114 % transcriptions of interviews. This allows her to
115 % precisely refer to passages in the text. It works well
116 % together with ~\marginpar~s, but not too well with displaymath.
117 % ~\footnote~s are a problem, especially when they
118 % are split, but we may get there.
119 % (New v4.00 UL) Version v4.00 overcomes the problem, I believe.
123 % surprisingly well with other packages, for
124 % example, ~wrapfig.sty~. So please try if it
125 % works with whatever you need, and if it does,
126 % please tell me, and if it does not, tell me as
127 % well, so I can try to fix it.
130 % Introduction to versions v4.00ff. (UL)
133 % ~lineno.sty~ has been maintained by Stephan until version_v3.14.
134 % From version_v4.00 onwards, maintenance is shifting towards
135 % Uwe L\"uck (UL), who is the author of v4\dots code and of v4\dots
136 % changes in documentation. This came about as follows.
138 % Since late 2002, Christian Tapp and Uwe L\"uck have employed
139 % ~lineno.sty~ for their ~ednotes.sty~, a package supporting
140 % critical editions---cf.
142 % http://ednotes.sty.de.vu
144 % ---while you find ~ednotes.sty~ and surrounding files in
145 % CTAN folder \path{macros/latex/contrib/ednotes}.
147 % Soon, some weaknesses of ~lineno.sty~ showed up, mainly since
148 % Christian's critical editions (using ~ednotes.sty~) needed lots
149 % of ~\linelabel~s and footnotes. (These weaknesses are due to
150 % weaknesses of \LaTeX's ~\marginpar~ mechanism that Stephan
151 % used for ~\linelabel~.) So we changed some ~lineno.sty~
152 % definitions in some extra files, which moreover offered new
153 % features. We sent these files to Stephan, hoping he would take
154 % the changes into ~lineno.sty~. However, he was too short of time.
156 % Writing a TUGboat article on Ednotes in 2004, we hoped to
157 % reduce the number of files in the Ednotes bundle and so asked
158 % Stephan again. Now he generously offered maintenance to me, so
159 % I could execute the changes on my own.
161 % The improvements are as follows:
162 % \begin{itemize}\item
163 % [(i)] Footnotes placement approaches intentions better
164 % (footnotes formerly liked to pile up at late pages).
166 % [(ii)] The number of ~\linelabel~s in one paragraph is no longer
169 % [(iii)] ~\pagebreak~, ~\nopagebreak~, ~\vspace~, and the star
170 % and optional versions of ~\\~ work as one would expect
171 % (section_\ref{s:MVadj}). %% Added for v4.1
173 % [(iv)] A command is offered which chooses the first line number
174 % to be printed in the margin
175 % (subsection_\ref{ss:Mod}). %% Added for v4.1
177 % [(v)] (New v4.1) \LaTeX\ tabular environments (optionally)
178 % get line numbers as well, and you can refer to them in the
179 % usual automatic way. (It may be considered a shortcoming that,
180 % precisely, \emph{rows} are numbered, not lines.---See
181 % subsection_\ref{ss:Tab}.)
183 % [(vi)] We are moving towards referring to math items
184 % (subsection_\ref{ss:MathRef} and the hooks in
185 % subsection_\ref{ss:LL}).
188 % (Thanks to Stephan for making this possible!)
191 %% You may trace the earlier developments of these changes by
192 %% requesting our files ~linenox0.sty~, ~linenox1.sty~, and
193 %% ~lnopatch.sty~. Most of our changes have been in ~linenox0.sty~.
194 %% Our ~linenox1.sty~ has extended ~linenox0.sty~ for one single
195 %% purpose in a not very stable way.
196 %%% (See ~\linenumberpar~ below).
197 %% ~lnopatch.sty~ has done the first line number thing referred
198 %% to in case_(iv) up to now.
200 %% Case_(v) earlier was provided by our ~edtab02.sty~---now
201 %% called ~edtable.sty~.
204 % Ednotes moreover profits from Stephan's offer with regard
205 % to the documentation of our code which yielded these
206 % improvements formerly. This documentation now becomes
207 % printable, being part of the ~lineno.sty~ documentation.
209 % Of course, Stephan's previous ~lineno.sty~ versions were a great
210 % and ingenious work and exhibit greatest \TeX pertise. I never
211 % could have done this. I learnt a lot in studying the code when
212 % Christian pointed out strange output results and error
213 % messages, and there are still large portions of ~lineno.sty~
214 % which I don't understand (consider only pagewise numbering of
215 % lines). Fortunately, Stephan has offered future help if
216 % needed.---My code for attaching line numbers to \emph{tabular
217 % environments} (as mentioned above, now still in
218 % ~edtable.sty~) %% %% TODO
219 % developed from macros which Stephan and Christian experimented
220 % with in December 2002. Stephan built the basics.
221 % (However, I then became too proud to follow his advice only to
222 % use and modify ~longtable.sty~.)
224 % There are some issues concerning use of counters on which I
225 % don't agree with Stephan and where I would like to change the
226 % code if ~lineno.sty~ is ``mine'' as Stephan offered. However,
227 % Stephan is afraid of compatibility problems from which, in
228 % particular, his wife could suffer in the near future. So he
229 % demanded that I change as little as possible for my first
230 % version. Instead of executing changes that I plan I just offer
231 % my opinions at the single occasions. I hope to get in touch
232 % this way with users who consider subtle features vital which I
235 % On the other hand, the sections on improvements of the
236 % implementation have been blown up very much and may be tiring
237 % and litte understandable for mere \emph{users}. These users
238 % may profit from the present presentation just by jumping to
239 % sections_\ref{s:Opts} and_\ref{s:UserCmds}. There is a user's
240 % guide ulineno.tex which may be even more helpful, but it has
241 % not been updated for a while. %% TODO
247 % In case you have found the present file otherwise than from
248 % CTAN: A recent version and documentation of this package
249 % should be available from CTAN folder
250 % \path{macros/latex/contrib/lineno}.
251 % Or mail to one of the addresses at top of file.
257 % This style option is written for \LaTeXe, November 1994 or later,
258 % since we need the ~\protected@write~ macro.
260 % (New v4.00) And we use ~\newcommand*~ for
261 % controlling length of user macro arguments, which has been
262 % available since December 1994.
265 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
267 \ProvidesPackage{lineno}
268 [\filedate\space line numbers on paragraphs \fileversion]
271 %% History of versions:
272 %% v1.00 1995/03/31 SIB: first release for Petra's interview transcriptions
273 %% v1.01 1995/10/28 SIB: added ~pagewise~ mode
274 %% v1.02 1995/11/15 SIB: added ~modulo~ option
275 %% v1.03 1995/12/05 SIB: pagewise: try to reduce the hash-size requirements
276 %% v2.00 1995/12/06 SIB: .. it works, new user interface
277 %% v2.01 1996/09/17 SIB: put into CVS
278 %% v2.02 1997/03/17 SIB: add: \@reinserts, for footnotes
279 %% v2.04 1998/03/09 SIB: add: linenomath environment
280 %% v2.05 1998/04/26 SIB: add: prevgraf test
281 %% v2.06 1999/03/02 SIB: LPPL added
282 %% v3.00 1999/06/11 SiB: include the extension in the main file
283 %% v3.01 1999/08/28 SiB: \@reinserts -> \holdinginserts
284 %% v3.02 2000/03/10 SiB: \@LN@output
285 %% v3.03 2000/07/01 SiB: \@LN@ExtraLabelItems, hyperref
286 %% v3.04 2000/12/17 SiB: longtable compatibility.
287 %% v3.05 2001/01/02 SiB: [fleqn] detection.
288 %% v3.05a 2001/01/04 SiB: [fleqn] detection reverted for eqnarray.
289 %% v3.06 2001/01/17 SiB: [twocolumn] mode support.
290 %% v3.07 2001/07/30 SiB: [hyperref] option obsoleted.
291 %% v3.08 2001/08/02 SiB: linenomath wrapping for \[ \]
292 %% v3.08a 2001/08/04 SiB: linenomath wrapping for \[ \] fixed
293 %% v3.08b 2002/01/27 SiB: enquotation typo fix
294 %% v3.09 2003/01/14 SIB: hyperref detection fix
295 %% v3.10 2003/04/15 FMi: \MakeLineNo fix for deep boxes
296 %% v3.10a 2003/11/12 Uwe Lück: \lineref typo fix
297 %% v4.00 2004/09/02 UL: included linenox0, linenox1, lnopatch code with
298 %% documentation, usually indicated by `New v4.00';
299 %% discussions of old code, indicated by `UL';
300 %% LPPL v.1 -> LPPL v1.3, `program' -> `file';
301 %% first lines with \filedate and \fileversion,
302 %% according nawk lines; `November 1994 or later',
303 %% some earlier documentation typos (including a few
304 %% bad minus signs), { -> {% and } -> \unskip} at
305 %% line ends (so, e.g., alignment in TOC works); \scs.
306 %% 2004/09/03 UL: removed everything which indicated that the
307 %% present file were named `lineno4.sty'.
308 %% v4.1 2004/09/19 UL: Inserted Stephan's identification line, removed
309 %% some TODOs and remarks from v4.00.
310 %% 2004/10/04 UL: Added acknowledgement for Daniel Doherty;
311 %% `(New v4.00)' with [|\firstlinenumber]; changed
312 %% TODOs; Refining -> Redefining (\vadjust).
313 %% 2004/10/05 UL: ednmath0 -> mathrefs; \catcode`\~ -> \active;
314 %% \path; refined section on options `mathrefs';
315 %% changes in introduction.
316 %% 2004/10/06 UL: Changed/removed TODOs, e.g., for edtable.sty.
317 %% 2004/10/11 UL: Reminders: linenox0/1/lnopatch.sty obsolete;
318 %% \tt star in list of commands.
319 %% 2004/10/12 UL: Corrected blank lines in lineno.tex.
320 %% 2004/10/19 UL: Fixed minor typos; remark on \if@LN@edtable.
321 %% v4.1a 2004/11/07 UL: LPPL v1.3a.
322 %% v4.1b 2004/11/13 UL: Comment on \outputpenalty values.
323 %% v4.1c 2005/01/10 UL: Contact via http.
324 %% v4.11 2005/02/20 UL: Error message with \linelabel when not numbering.
325 %% 2005/03/07 UL: Removed \linelabel from ss:Tab heading, consider
326 %% marginal line numbers as well, revised ss:Tab.
327 %% Added a few lines on missing explanations to
328 %% s:UserCmds. Corrected some code alignments.
329 %% 2005/03/08 UL: Require recent edtable.sty.
332 %% v4.2 2005/03/21 UL: "Physical page" counter works with \include.
333 %% 2005/04/17 UL: Raised options section above extensions section
334 %% (v4.00 disabled `displaymath' option);
335 %% third arg for \@ifundefined{mathindent};
336 %% "bunch of options";
337 %% 2005/04/24 UL: compatibility with tamefloats; vplref.sty.
338 %% 2005/04/25 UL: \number -> \the; wondered -> $$; subsec. appbas;
339 %% CrtlLN sec -> subsec.; \newcommand* wherever ...;
340 %% doc. on `other output routines' and `addpageno'
341 %% (this changed from `varioref').
342 %% 2005/04/27 UL: =1\relax -> =\@ne, 0\relax ..., \hb@xt@,
343 %% \ifx\@@par\@@@par -> \ifLineNumbers, typos,
344 %% \pagestyle{headings}, LaTeX -> \LaTeX.
345 %% v4.21 2005/04/28 UL: linenomath section: removed wrong \else's,
346 %% \holding...: \thr@@, \@LN@outer@holdins, \global.
347 %% v4.22 2005/05/01 UL: \unvbox\@outputbox; \@LN@col without #1,
348 %% 2005/05/08 UL: global/local \internall..., \resetl... global,
349 %% shortened discussions of this and of \newcounter.
350 %% 2005/05/09 UL: corr.: doc. typo, version history, bad lines;
351 %% percent; \chardef for modulo,
352 %% \value{firstlinenumber}.
353 %% v4.3 2005/05/10 UL: \@backslashchar -> \char`\\ in \scs.
354 %% 2005/05/11 UL: \linenumbers sets ...outer@holdins; tidied up
355 %% documentation regarding earlier versions.
356 %% 2005/05/12 UL: `linenomath' without spurious number above;
357 %% `displaymath' default; edmac homepage ->
358 %% ednotes.sty.de.vu, \endlinenomath without
359 %% numbers: no change of \holdinginserts;
360 %% \linelabel doesn't go to .aux or mark,
361 %% hyperref detected; undone 2005/05/10 (bad mark).
362 %% 2005/05/13 UL: Reworked hyperref detection (new subsec.).
363 %% 2005/05/15 UL: More typo fixes, corrected terrible confusions in
364 %% the discussion (v4.22/v4.3) of \new/\stepcounter;
365 %% new subsec. in `Line number ...'; another
366 %% implementation of `hyperref' detection.
367 %% 2005/05/16 UL: Final minor changes.
368 %% v4.31b /06/14 UL: Extended explanation of \firstlinenumbers
369 %% and package options; \@LN@ifgreat@critical;
370 %% \modulolinenumbers*. Sent to Ednotes.news only.
371 %% v4.31 2005/06/15 UL: \modulolinenumbers* with \firstlinenumber{1};
372 %% " -> ``/''; more doc. on \firstlinenumber .
373 %% 2005/06/20 UL: Typo fix.
374 %% 2005/10/01 UL: Warning about \mod...* with pagewise mode.
375 %% v4.31a /10/02 UL: Minor changes of appearance of doc., e.g.,
377 %% v4.32b /10/15 UL: Support for \addvspace; removed comments that
378 %% had been invisible already for some time;
379 %% made clear with which environments the
380 %% linenomath environment is not needed.
381 %% v4.32ab /10/15 UL: Observe \if@nobreak with support for \addvspace.
382 %% v4.32 2005/10/17 UL: Just made it official and sent it to CTAN.
383 %% v4.33b /10/23 UL: \if@nobreak\nobreak\fi -> \nobreak .
384 %% v4.33ab /10/24 UL: \LineNoLaTeXOutput without \@tempswafalse;
385 %% undid v4.22: \[unv]box\@outputbox (space is OK,
386 %% \unvbox pushes short columns down); \@LN@kern@z@ .
387 %% v4.4b 2005/10/24 UL: Another tidying-up of the discussion of
388 %% \stepcounter{linenumber}; \@LN@screenoff@pen
389 %% replaces \@LN@kern@z@, \@LN@depthbox .
390 %% v4.4 2005/10/27 UL: Just made official for CTAN.
391 %% v4.4a 2005/10/29 UL: Undid change of discussion of
392 %% \stepcounter{linenumber} (confusion again).
393 %% v4.41 2005/11/02 UL: Raised \CheckCommand*.
396 %% v3.06: Donald Arseneau, pointed to mparhack.sty.
397 %% v3.07+: Frank Mittelbach, points out inconsistencies in the
399 %% v3.10: Frank Mittelbach \MakeLineNo fix for deep boxes
400 %% v4.00: Daniel Doherty points out clash of \pagewise... with resetting
402 %% v4.21: Much testing work by Erik Luijten.
403 %% v4.3: `displaymath' default by Erik Luijten's suggestion.
404 %% v4.31: \modulolinenumbers* is an idea of Hillel Chayim Yisraeli's.
405 %% v4.32: Support for \addvspace due to Saravanan M.'s observation.
406 %% v4.33: Different support for \addvspace due to bug reports by
407 %% Saravanan M.'s and David Josef Dev.
408 %% v4.4: David Josef Dev points out that \kern\z@ after a paragraph
409 %% tends to place its final baseline wrongly.
413 % Put the line numbers to the lines
416 % (New v4.00) This section contained the most
417 % basic package code previously. For various purposes of
418 % version_4\dots, much of these basics have been to be modified.
419 % Much of my (UL's) reasoning on these modifications has been to
420 % be reported. Sorry, the present section has been blown up
421 % awfully thus and contains ramifications that may be difficult
422 % to trace. We add some ~\subsection~ commands in order to cope
423 % with the new situation. (/New v4.00)
426 % Basic code of \texttt{lineno.sty} \scs{output}
427 % \unskip}\label{ss:output}
429 % The line numbers have to be attached by the output
430 % routine. We simply set the ~\interlinepenalty~ to $-100000$.
431 % The output routine will be called after each line in the
432 % paragraph, except the last, where we trigger by ~\par~.
433 % The ~\linenopenalty~ is small enough to compensate a bunch of
434 % penalties (e.g., with ~\samepage~).
436 % (New v3.04) Longtable uses
437 % ~\penalty~$-30000$. The lineno penalty range was
438 % shrunk to $-188000 \dots -32000$. (/New v3.04)
439 % (New v4.00) New values are listed below (11111f.). (/New v4.00)
441 \newcount\linenopenalty\linenopenalty=-100000
444 % (UL) Hm. It is never needed below
445 % that this is a counter. ~\def\linenopenalty{-100000\relax}~
446 % would do. (I guess this consumes more memory, but it
447 % is more important to save counters than to save memory.)
448 % I was frightened by ~-\linenopenalty~ below, but indeed
449 % \TeX\ interprets the string ~--100000~ as 100000.
450 % Has any user or extension package writer ever called
451 % ~\linenopenalty=xxx~, or could I really change this?---The
452 % counter is somewhat faster than the macro. Together with the
453 % compatibility question this seems to support keeping the
455 %% Note that Stephan chose ~\mathchardef~ below,
456 %% so his choice above seems to have been deliberate.
457 %% <- no point, \mathchardef token is fast.
460 \mathchardef\linenopenaltypar=32000
462 % So let's make a hook to ~\output~, the direct way. The \LaTeX\
463 % macro ~\@reinserts~ puts the footnotes back on the page.
465 % (New v3.01) ~\@reinserts~ badly
466 % screws up split footnotes. The bottom part is
467 % still on the recent contributions list, and the
468 % top part will be put back there after the bottom
469 % part. Thus, since lineno.sty does not play well
470 % with ~\inserts~ anyway, we can safely experiment
471 % with ~\holdinginserts~, without making things
474 % Or that's what I thought, but: Just activating
475 % ~\holdinginserts~ while doing the ~\par~ will
476 % not do the trick: The ~\output~ routine may be
477 % called for a real page break before all line
478 % numbers are done, and how can we get control
479 % over ~\holdinginserts~ at that point?
481 % Let's try this: When the ~\output~ routine is
482 % run with ~\holdinginserts=3~ for a real page
483 % break, then we reset ~\holdinginserts~ and
486 % Then, again, how do we keep the remaining
487 % ~\inserts~ while doing further line numbers?
489 % If we find ~\holdinginserts~=$-3$ we activate it again
490 % after doing ~\output~. (/New v3.01)
492 % (New v3.02) To work with
493 % multicol.sty, the original output routine is now
494 % called indirectly, instead of being replaced.
495 % When multicol.sty changes ~\output~, it is a
496 % toks register, not the real thing. (/New v3.02)
498 % (New v4.00) Two further complications are added.
500 %% TODO v4.3+: Or three, ~\@nobreakfalse~ after ~\MakeLineNo~
501 %% for getting rid of ~\@LN@nopagebreak~.
502 % \begin{itemize}\item
503 % [(i)] Problems with footnotes formerly resulted from
504 % \LaTeX's ~\@reinserts~ in ~\@specialoutput~ which Stephan's
505 % ~\linelabel~ called via the ~\marginpar~ mechanism.
507 % [(ii)] \LaTeX\ commands using ~\vadjust~ formerly didn't work
508 % as one would have hoped. The problem is as follows:
509 % Printing the line number results from
510 % a box that the output routine inserts at the place of the
511 % ~\interlinepenalty~. ~\vadjust~ items appear \emph{above} the
512 % ~\interlinepenalty~ (\TeX book p._105). So ~\pagebreak~, e.g.,
513 % formerly sent the line number to the next page, while the
514 % penalty from ~\nopagebreak~ could not tie the following line,
515 % since it was screened off by the line number box.---Our trick
516 % is putting the ~\vadjust~ items into a list macro from which
517 % the output routine transfers them into the vertical list,
518 % below the line number box.
520 % In this case_(ii), like in case_(i), footnotes would suffer
521 % if ~\holdinginserts~ were non-positive. Indeed, in both
522 % cases_(i) and_(ii) we tackle the footnote problem by extending
523 % that part of Stephan's output routine that is active when
524 % ~\holdinginserts~ is positive. This extension writes the line
525 % number ~\newlabel~ to the .aux file (which was formerly done
526 % under $~\holdinginserts~=-3$) and handles the ~\vadjust~
527 % items.---To trigger ~\output~ and its ~\linelabel~ or, resp.,
528 % ~\vadjust~ part, the list of signal penalties started
529 % immediately before is increased here (first for ~\linelabel~,
530 % second for postponed ~\vadjust~ items):
532 \mathchardef\@Mllbcodepen=11111
533 \mathchardef\@Mppvacodepen=11112
535 % (/New v4.00) (New v4.2) David Kastrup urges to use a private
536 % name instead of ~\the\output~ (LaTeX-L-list). Otherwise an
537 % ~\output~ routine loaded later and using ~\newtoks\output~
538 % again may get lost entirely. So we change use of ~\@LN@output~,
539 % using it for the former purpose. Reference to what appeared
540 % with the name of ~\output~ here lasts for a few lines and then
545 \let\@LN@output\output
546 \output=\expandafter{\the\@tempa}
548 % Now we add two cases to Stephan's output routine. (New v4.00)
555 %% (UL) Learnt that even in def.s blank line means ~\par~.
556 %% to leave visual space in present file with having a
557 %% blank line neither in present nor in .tex file,
558 %% use double comment mark (`%%'). (/UL)
561 % We insert recognition of waiting ~\linelabel~ items---
563 \ifnum\outputpenalty=-\@Mllbcodepen
566 % ---and of waiting ~\vadjust~ items:
569 \ifnum\outputpenalty=-\@Mppvacodepen
573 %% Now we give control back to Stephan.
574 % (/New v4.00) (New v4.2) Outsource ``Standard'' output
575 % ---which occurs so rarely---to subsection_\ref{ss:LLO}:
578 % (/New v4.2) (New v4.00)
579 % Two new ~\fi~s for the ~\linelabel~ and ~\vadjust~ tests---
584 % ---and the remaining is
585 %%%next three lines are
586 % Stephan's code again:
594 % (New v4.00) Our new macros
595 % ~\WriteLineNo~ and ~\PassVadjustList~ will be dealt with in
596 % sections_\ref{s:LNref} and_\ref{ss:PVadj}. (/New v4.00)
602 % The float mechanism inserts ~\interlinepenalty~s during
603 % ~\output~. So carefully reset it before going on. Else
604 % we get doubled line numbers on every float placed in
605 % horizontal mode, e.g, from ~\linelabel~.
607 % Sorry, neither a ~\linelabel~ nor a ~\marginpar~ should
608 % insert a penalty, else the following linenumber
609 % could go to the next page. Nor should any other
610 % float. So let us suppress the ~\interlinepenalty~
611 % altogether with the ~\@nobreak~ switch.
613 % Since (ltspace.dtx, v1.2p)[1996/07/26], the ~\@nobreaktrue~ does
614 % it's job globally. We need to do it locally here.
618 \ifnum\interlinepenalty<-\linenopenaltypar
619 \advance\interlinepenalty-\linenopenalty
623 \ifnum\outputpenalty>-\linenopenaltypar\else
624 \ifnum\outputpenalty>-188000\relax
630 \def\@LN@nobreaktrue{\let\if@nobreak\iftrue} % renamed v4.33
632 % (UL) I thought here were
633 % another case of the save stack problem explained in \TeX book,
634 % p._301, namely through both local and global changing
635 % ~\if@nobreak~. However, ~\@LN@nobreak~ is called during
636 % ~\@LN@output~ only, while ~\@nobreaktrue~ is called by \LaTeX's
637 % ~\@startsection~ only. The latter never happens during
638 % ~\@LN@output~. So there is no local value of ~\if@nobreak~ on
639 % save stack when ~\@nobreaktrue~ acts, since ~\the\@LN@output~
640 % (where ~\@LN@output~ is a new name for the original ~\output~)
641 % is executed within a group (\TeX book p._21).
643 %% 2004/09/19 Removed nonsense here according to Stephan 2004/09/04.
648 % Other output routines (v4.2)
649 % \unskip}\label{ss:LLO}
651 % I had thought of dealing with bad interference of footnotes
652 % (and ~\enlargethispage~) with (real) ~\marginpar~s and floats
653 % \emph{here}. Yet this is done in
655 % ~http://~\mbox{[CTAN]}
656 % ~/macros/latex/contrib/tamefloats/tameflts.sty~
658 % now, and I prefer striving for compatibility with the latter.
659 % (See there for expanding on the problem.)
660 % This requires returning the special absolute value of
661 % ~\holdinginserts~ that ~lineno.sty~ finds at the end of a newly
662 % typeset paragraph---now done in subsection_\ref{ss:calls}
663 % (~\linenumberpar~).
664 % The former ~\LineNoHoldInsertsTest~ has been filled into here.
665 %% ---`3' is replaced by ~\thr@@~ for a while. ~\thr@@~ is
666 %% useful practice since plain \TeX, but Stephan may have been
667 %% wise in suspecting that \LaTeX\ once could forsake ~\thr@@~.
668 %% The same holds for ~\@M=10000~.
669 % Note: when the following code is invoked, we have
670 % ~\if@tempswa~_ =_~\iftrue~.
671 % WARNING: I am still not sure whether the present code is good
672 % for cooperating with other packages that use ~\holdinginserts~.
674 \def\LineNoLaTeXOutput{%
675 \ifnum \holdinginserts=\thr@@ % v4.33 without \@tempswafalse
676 \global\holdinginserts-\thr@@
678 \ifnum \outputpenalty=\@M \else \penalty\outputpenalty \fi
680 \if@twocolumn \let\@makecol\@LN@makecol \fi
681 \the\@LN@output % finally following David Kastrup's advice.
682 \ifnum \holdinginserts=-\thr@@
683 \global\holdinginserts\thr@@ \fi
687 % \textit{More on dealing with output routines from other
689 % Since ~lineno.sty~'s output routine is called at least once
690 % for each output line, I think it should be in \TeX's
691 % original ~\output~, while output routines dealing with
692 % building pages and with floats etc.\ should be filled into
693 % registers addressed by ~\output~ after ~\newtoks\output~.
694 % Therefore \begin{enumerate}
696 % ~tameflts.sty~ should be loaded \emph{after} ~lineno.sty~;
698 % if a class changes ~\output~ (APS journal class revtex4,
699 % e.g.), ~lineno.sty~ should be loaded by ~\RequirePackage~
700 % [here presumably following some options in
701 % brackets]~{lineno}~ \emph{preceding} ~\documentclass~.
703 % If you actually maintain such a class, please consider
704 % loading ~lineno.sty~ on some draft option. The bunch of
705 % lineno's package options may be a problem, but perhaps the
706 % purpose of your class is offering only very few of lineno's
707 % options anyway, maybe just one.
709 % The latter may also be needed with classes that don't follow
710 % David Kastrup's rule on changing ~\output~.
713 % \scs{MakeLineNo}: Actually attach line number
714 % \unskip}\label{ss:MLN}
716 % We have to return all the page to the current page, and
717 % add a box with the line number, without adding
718 % breakpoints, glue or space. The depth of our line number
719 % should be equal to the previous depth of the page, in
720 % case the page breaks here, and the box has to be moved up
723 % The ~\interlinepenalty~ comes after the ~\vadjust~ from a
724 % ~\linelabel~, so we increment the line number \emph{after}
725 % printing it. The macro ~\makeLineNumber~ produces the
726 % text of the line number, see section \ref{appearance}.
728 % (UL) I needed a while to understand
729 % the sentence on incrementing. Correctly: writing the
730 % ~\newlabel~ to the .aux file is triggered by the signal
731 % penalty that ~\end@float~ inserts via ~\vadjust~.
732 % However, this could be changed by our new ~\PostponeVadjust~.
733 % After ~\c@linenumber~ has been introduced as a \LaTeX\
734 % counter, it might be preferable that it behaved like standard
735 % \LaTeX\ counters which are incremented shortly before printing.
736 % But this may be of little practical relevance in this case,
737 % as ~\c@linenumber~ is driven in a very non-standard
738 % way.---However still, this behaviour of ~\c@linenumber~
739 % generates a problem with our ~edtable.sty~.
741 %% I thought that Stephan had reported his reasoning incorrectly
742 %% and rather did this because of his ~\resetlinenumber~ which
743 %% initializes ~\c@linenumber~ to 1 instead of 0---the latter is
744 %% usual with \LaTeX\ counters. Cf._additional comment at
745 %% ~\resetlinenumber~.
748 % Finally we put in the natural ~\interlinepenalty~, except
749 % after the last line.
751 % (New v3.10) Frank Mittelbach points out that box255 may be
752 % less deep than the last box inside, so he proposes to
753 % measure the page depth with ~\boxmaxdepth=\maxdimen~.
756 % (UL, New v4.00) We also resume the matter of
757 % ~\vadjust~ items that was started in section_\ref{ss:output}.
759 % \TeX\ puts only nonzero interline
760 % penalties into the vertical list (\TeX book p._105), while
761 % ~lineno.sty~ formerly replaced the signal interline penalty by
762 % something closing with an explicit penalty of the value that
763 % the interline penalty would have without ~lineno.sty~.
764 % This is usually 0. Now, explicit vertical penalties can be
765 % very nasty with respect to ~\nopagebreak~, e.g., a low (even
766 % positive) ~\widowpenalty~ may force a widow where you
767 % explicitly tried to forbid it by ~\nopagebreak~
768 % (see explanation soon below).
769 % The ~\nopagebreak~ we create here would never work if all
770 % those zero penalties were present.---On
771 % the other hand, we cannot just omit Stephan's zero penalties,
772 % because \TeX\ puts a penalty of 10000 after what ~lineno.sty~
773 % inserts (\TeX book p._125). This penalty must be overridden
774 % to allow page breaks between ordinary lines. To revive
775 % ~\nopagebreak~, we therefore replace those zero (or low)
776 % penalties by penalties that the user demanded by
777 % ~\nopagebreak~.---This mechanism is not perfect and does not
778 % exactly restore the original \LaTeX\ working of ~\pagebreak~
779 % and ~\nopagebreak~. Viz., if there are several vertical
780 % penalties after a line which were produced by closely sitting
781 % ~\[no]pagebreak~s, without ~lineno.sty~ the lowest penalty would
782 % be effective (cf._\TeX book exercise_14.10). Our mechanism, by
783 % contrast, chooses the \emph{last} user-set penalty of the line
784 % as the effective one. It would not be very difficult to come
785 % more close to the original mechanism, but until someone urges
786 % us we will cling to the present simple way. You may consider an
787 % advantage of the difference between our mechanism and the
788 % original one that the user here can actually override low
789 % penalties by ~\nopagebreak~, which may be what a lay \LaTeX\
791 %% ---Zero glue would do instead of zero
792 %% penalty! This could make things easier. Maybe next time.
793 %% <- v4.4: No, problem with column depth.
797 \@LN@maybe@normalLineNumber % v4.31
798 \boxmaxdepth\maxdimen\setbox\z@\vbox{\unvbox\@cclv}%
799 \@tempdima\dp\z@ \unvbox\z@
800 \sbox\@tempboxa{\hb@xt@\z@{\makeLineNumber}}%
802 % (New v4.00) Previously,
803 % \begin{old}\begin{verbatim}
804 % % \stepcounter{linenumber}%
807 %% %% TODO: Still first `\begin{old}'?
808 % followed. (Of course, there was no
809 % comment mark; I put it there to make
810 % reading the actual code easy.)
812 % (New v4.22: improved) Why not just
813 % \[~\global\advance\c@linenumber\@ne~?\]
814 % ~\stepcounter~ additionally resets ``subordinate''
815 % counters, but which could these (usefully) be?
816 % Again, may be column counters with ~edtable.sty~!?
818 % But then, our ~edtable.sty~ and its ~longtable~ option
819 % should use it as well. So use a shorthand supporting
820 % uniformity. You can even use it as a hook for choosing
821 % ~\global\advance\c@linenumber\@ne~ instead of our choice.
828 \ht\@tempboxa\z@ \@LN@depthbox
830 % appends the box containing the line number without changing
831 % ~\prevdepth~---see end of section.
832 % Now is the time for inserting the $\dots$ (/New v4.4)
833 %% The line number has now been placed (it may be invisible
834 %% depending on the modulo feature), so
836 % ~\vadjust~ items. We cannot do this much later, because
837 % their right place is above the artificial interline
838 % penalty which Stephan's code will soon insert
839 % (cf._\TeX book p._105). The next command is just ~\relax~
840 % if no ~\vadjust~ items have been accumulated for the
841 % current line. Otherwise it is a list macro inserting
842 % the ~\vadjust~ items and finally resetting itself.
843 % (This is made in section_\ref{ss:PVadj} below.)
844 % If the final item is a penalty, it is stored so it can
845 % compete with other things about page breaking.
851 % \begin{old}\begin{verbatim}
852 % % \ifnum\outputpenalty=-\linenopenaltypar\else
855 % originally followed. We need something \emph{before} the
858 \ifnum\outputpenalty=-\linenopenaltypar
859 \ifnum\count@=\z@ \else
861 % So final ~\pagebreak[0]~ or ~\nopagebreak[0]~ has no
862 % effect---but this will make a difference after headings only,
863 % where nobody should place such a thing anyway.
867 \global\let\noexpand\@LN@parpgbrk
868 \noexpand\@LN@screenoff@pen}% v4.4
870 % That penalty will replace former ~\kern\z@~ in
871 % ~\linenumberpar~, see subsection_\ref{ss:calls}.---A
872 % few days earlier, I tried to send just a penalty value.
873 % However, the ~\kern\z@~ in ~\linenumberpar~ is crucial,
874 % as I then found out. See below.---The final penalty is
875 % repeated, but this does no harm. (It would not be very
876 % difficult to avoid the repeating, but it may even be
877 % less efficient.) It may be repeated due to the previous
878 % ~\xdef~, but it may be repeated as well below in the
879 % present macro where artificial interline penalty is to
886 %% Corrected code alignment with v4.11.
887 \@tempcnta\outputpenalty
888 \advance\@tempcnta -\linenopenalty
891 % \begin{old}\begin{verbatim}
892 % % \penalty\@tempcnta
895 % followed previously. To give ~\nopagebreak~ a chance,
897 %% Corrected code alignment with v4.11.
898 \penalty \ifnum\count@<\@tempcnta \@tempcnta \else \count@ \fi
900 % instead.---In ~linenox0.sty~, the ~\else~ thing once was omitted.
901 % Sergei Mariev's complaint (thanks!) showed that it is vital
902 % (see comment before ~\MakeLineNo~).
903 % The remaining ~\fi~ from previous package version closes the
904 % ~\ifnum\outputpenalty~\dots
912 \newcommand\stepLineNumber{\stepcounter{linenumber}}
914 % For reason, see use above. (/New v4.00)
915 %% %% TODO v4.4+: ~\newcommand~ more often!?
917 % (New v4.4) The depth preserving trick is drawn here from
918 % ~\MakeLineNo~ because it will be used again in
919 % section_\ref{ss:calls}.
922 \dp\@tempboxa=\@tempdima
923 \nointerlineskip \kern-\@tempdima \box\@tempboxa}
928 % Control line numbering
931 % Inserting \scs{output} calls %% own subsec. v4.4.
932 % \unskip}\label{ss:calls}
933 % The line numbering is controlled via ~\par~. \LaTeX\
934 % saved the \TeX-primitive ~\par~ in ~\@@par~. We push it
935 % one level further out, and redefine ~\@@par~ to insert
936 % the ~\interlinepenalty~ needed to trigger the
937 % line numbering. And we need to allow pagebreaks after a
940 % New (2.05beta): the prevgraf test. A paragraph that ends with a
941 % displayed equation, a ~\noindent\par~ or ~wrapfig.sty~ produce empty
942 % paragraphs. These should not get a spurious line number via
943 % ~\linenopenaltypar~.
946 \newcount\linenoprevgraf
948 % (UL) And needs ~\linenoprevgraf~
949 % to be a counter? Perhaps there may be a paragraph having
950 % thousands of lines, so ~\mathchardef~ doesn't suffice (really??).
952 %% %% TODO: limitations of lines per paragraph elsewhere?
953 %% %% Signal penalties, e.g.!? ~\deadcycles~!?
955 % A macro ending on ~\relax~ might suffice, but would be
956 % somewhat slow. I think I will use ~\mathchardef~ next time.
957 % Or has any user used ~\linenoprevgraf~? (/UL)
959 %% v4.33: changed code alignment for better understanding.
961 \ifvmode \@@@par \else
962 \ifinner \@@@par \else
963 \xdef\@LN@outer@holdins{\the\holdinginserts}% v4.2
964 \advance \interlinepenalty \linenopenalty
965 \linenoprevgraf \prevgraf
966 \global \holdinginserts \thr@@
968 \ifnum\prevgraf>\linenoprevgraf
969 \penalty-\linenopenaltypar
973 % \begin{old}\begin{verbatim}
977 % was here previously. What for?
978 % According to \TeX book p._125, Stephan's
979 % interline penalty is changed into 10000. At the end of a
980 % paragraph, the ~\parskip~ would follow that penalty of 10000,
981 % so there could be a page break neither at the
982 % ~\parskip~ nor at the ~\baselineskip~ (\TeX book p._110)---so
983 % there could never be a page break between two paragraphs.
984 % So something must screen off the 10000 penalty.
985 % Indeed, the ~\kern~ is a place to break.
986 % (Stephan once knew this: see `allow pagebreaks' above.)
988 % Formerly, I tried to replace ~\kern\z@~ by
989 % \begin{old}\begin{verbatim}
990 % % \penalty\@LN@parpgpen\relax
993 % ---but this allows a page break after heading. So:
997 %% After heading, ~\kern\z@~ resulting from previous line
998 %% (see below) is followed by ~\write~ or ~\penalty10000~,
999 %% so causes no page break.
1001 % These and similar changes were formerly done by ~linenox1.sty~.
1005 % A ~\belowdisplayskip~ may precede the previous when the paragraph
1006 % ends on a display-math; or there may be a ~\topsep~ from a list, etc.
1007 % ~\addvspace~ couldn't take account for it with ~\kern\z@~
1008 % here. v4.32 therefore moved the space down -- with at least two
1010 % Moreover, David Josef Dev observes that ~\kern\z@~ may
1011 % inappropriately yield column depth 0pt.
1012 % For these reasons, we introduce ~\@LN@screenoff@pen~ below.
1015 \global\holdinginserts\@LN@outer@holdins % v4.2
1016 \advance\interlinepenalty -\linenopenalty
1017 \fi % from \ifinner ... \else
1018 \fi} % from \ifvmode ... \else
1020 % (New v4.00, v4.4) Initialize ~\@LN@parpgbrk~, accounting
1021 % for earlier space and for appropriate columndepth.
1022 % We use former ~\MakeLineNo~'s depth-preverving trick
1023 % ~\@LN@depthbox~ again:
1025 \def\@LN@screenoff@pen{%
1027 \@tempdima\prevdepth \setbox\@tempboxa\null
1030 \global\let\@LN@parpgbrk\@LN@screenoff@pen
1032 % (/New v4.4, v4.00)
1034 % Turning on/off %% own subsec. v4.4.
1035 % \unskip}\label{ss:OnOff}
1036 % The basic commands to enable and disable line numbers.
1037 % ~\@par~ and ~\par~ are only touched, when they are ~\let~
1038 % to ~\@@@par~/~\linenumberpar~. The line number may be
1039 % reset to 1 with the star-form, or set by an optional
1040 % argument ~[~<number>~]~.
1042 % (New v4.00) We add ~\ifLineNumbers~ etc.\ since
1043 % a number of our new adjustments need to know whether
1044 % linenumbering is active. This just provides a kind of
1045 % shorthand for ~\ifx\@@par\linenumberpar~; moreover it is
1046 % more stable: who knows what may happen to ~\@@par~?---A
1047 % caveat: ~\ifLineNumbers~ may be wrong. E.g., it may be
1048 % ~\iffalse~ where it acts, while a ~\linenumbers~ a few
1049 % lines below---in the same paragraph---brings about that
1050 % the line where the ~\ifLineNumbers~ appears gets a
1052 %% Better implementation suggested below.
1054 % (New v4.3) Just noticed: Such tricks have been
1055 % disallowed with v4.11, see subsections_\ref{ss:LL}
1056 % and_\ref{ss:OnOff}.---Moreover, the switching between
1057 % meanings of ~\linelabel~ for a possible error message
1058 % as of v4.11 is removed. Speed is difficult to esteem
1059 % and also depends on applications. Just use the most
1060 % simple code you find. (/New v4.3)
1062 \newif\ifLineNumbers \LineNumbersfalse
1067 \LineNumberstrue % v4.00
1068 \xdef\@LN@outer@holdins{\the\holdinginserts}% v4.3
1070 % (New v4.3) The previous line is for ~{linenomath}~
1071 % in a first numbered paragraph. (/New v4.3)
1073 \let\@@par\linenumberpar
1074 % \let\linelabel\@LN@linelabel % v4.11, removed v4.3
1075 \ifx\@par\@@@par\let\@par\linenumberpar\fi
1076 \ifx\par\@@@par\let\par\linenumberpar\fi
1077 \@LN@maybe@moduloresume % v4.31
1078 \@ifnextchar[{\resetlinenumber}%]
1079 {\@ifstar{\resetlinenumber}{}}%
1082 \def\nolinenumbers{%
1083 \LineNumbersfalse % v4.00
1085 % \let\linelabel\@LN@LLerror % v4.11, removed v4.3
1086 \ifx\@par\linenumberpar\let\@par\@@@par\fi
1087 \ifx\par\linenumberpar\let\par\@@@par\fi
1090 % (New v4.00) Moreover, it is useful to switch to
1091 % ~\nolinenumbers~ in ~\@arrayparboxrestore~. We postpone this
1092 % to section_\ref{ss:ReDef} where we'll have an appending macro
1093 % for doing this. (/New v4.00)
1095 % What happens with a display math? Since ~\par~ is not executed,
1096 % when breaking the lines before a display, they will not get
1097 % line numbers. Sorry, but I do not dare to change
1098 % ~\interlinepenalty~ globally, nor do I want to redefine
1099 % the display math environments here.
1100 % \begin{displaymath}
1103 % See the subsection below, for a wrapper environment to make
1104 % it work. But that requires to wrap each and every display
1105 % in your \LaTeX\ source %%.
1107 % (see option ~displaymath~ in subsections_\ref{ss:v3opts}
1108 % and_\ref{ss:display} for some relief [UL]).
1110 % The next two commands are provided to turn on line
1111 % numbering in a specific mode. Please note the difference:
1112 % for pagewise numbering, ~\linenumbers~ comes first to
1113 % inhibit it from seeing optional arguments, since
1114 % re-/presetting the counter is useless.
1116 \def\pagewiselinenumbers{\linenumbers\setpagewiselinenumbers}
1117 \def\runninglinenumbers{\setrunninglinenumbers\linenumbers}
1119 % Finally, it is a \LaTeX\ style, so we provide for the use
1120 % of environments, including the suppression of the
1121 % following paragraph's indentation.
1124 % (UL) I am drawing the following
1125 % private thoughts of Stephan's to publicity so that others may
1126 % think about them---or to remind myself of them in an efficient
1128 %% UL changed `%%%' to `% %' below.
1129 %% TODO: add \par to \linenumbers, if called from an environment. %% v4.3
1130 %% ToDO: add an \@endpe hack if \linenumbers are turned on
1131 % \begin{old}\begin{verbatim}
1132 % % TO DO: add \par to \linenumbers, if called from an environment.
1133 % % To DO: add an \@endpe hack if \linenumbers are turned on
1134 % % in horizontal mode. {\par\parskip\z@\noindent} or
1138 % (UL) However, I rather think that ~\linenumbers~ and %% v4.31
1139 % ~\nolinenumbers~ should execute a ~\par~ already. (Then the
1140 % ~\par~s in the following definitions should be removed.) (/UL)
1142 \@namedef{linenumbers*}{\par\linenumbers*}
1143 \@namedef{runninglinenumbers*}{\par\runninglinenumbers*}
1145 \def\endlinenumbers{\par\@endpetrue}
1146 \let\endrunninglinenumbers\endlinenumbers
1147 \let\endpagewiselinenumbers\endlinenumbers
1148 \expandafter\let\csname endlinenumbers*\endcsname\endlinenumbers
1149 \expandafter\let\csname endrunninglinenumbers*\endcsname\endlinenumbers
1150 \let\endnolinenumbers\endlinenumbers
1155 % \unskip}\label{ss:DM}
1157 % Now we tackle the problem to get display math working.
1158 % There are different options.
1159 % \begin{enumerate}\item[
1160 % 1.] Precede every display math with a ~\par~.
1163 % 2.] Change ~\interlinepenalty~ and associates globally.
1166 % 3.] Wrap each display math with a ~{linenomath}~
1169 % We'll go for option 3. See if it works:
1170 % \begin{linenomath}
1175 % The star form ~{linenomath*}~ should also number the lines
1176 % of the display itself,
1177 % \begin{linenomath*}
1180 % display && math \\
1189 % including multline displays.
1191 % First, here are two macros to turn
1192 % on linenumbering on paragraphs preceeding displays, with
1193 % numbering the lines of the display itself, or without.
1194 % The ~\ifx..~ tests if line numbering is turned on. It
1195 % does not harm to add these wrappers in sections that are
1196 % not numbered. Nor does it harm to wrap a display
1197 % twice, e.q, in case you have some ~{equation}~s wrapped
1198 % explicitely, and later you redefine ~\equation~ to do it
1201 % (New v4.3) To avoid the spurious line number above a
1202 % display in vmode, I insert ~\ifhmode~. (/New v4.3)
1204 \newcommand\linenomathNonumbers{%
1206 %% \ifx\@@par\@@@par\else
1207 \ifnum\interlinepenalty>-\linenopenaltypar
1208 \global\holdinginserts\thr@@
1209 \advance\interlinepenalty \linenopenalty
1211 \advance\predisplaypenalty \linenopenalty
1218 \newcommand\linenomathWithnumbers{%
1220 %% \ifx\@@par\@@@par\else
1221 \ifnum\interlinepenalty>-\linenopenaltypar
1222 \global\holdinginserts\thr@@
1223 \advance\interlinepenalty \linenopenalty
1225 \advance\predisplaypenalty \linenopenalty
1227 \advance\postdisplaypenalty \linenopenalty
1228 \advance\interdisplaylinepenalty \linenopenalty
1234 % The ~{linenomath}~ environment has two forms, with and
1235 % without a star. The following two macros define the
1236 % environment, where the stared/non-stared form does/doesn't number the
1237 % lines of the display or vice versa.
1239 \newcommand\linenumberdisplaymath{%
1240 \def\linenomath{\linenomathWithnumbers}%
1241 \@namedef{linenomath*}{\linenomathNonumbers}%
1244 \newcommand\nolinenumberdisplaymath{%
1245 \def\linenomath{\linenomathNonumbers}%
1246 \@namedef{linenomath*}{\linenomathWithnumbers}%
1249 \def\endlinenomath{%
1250 \ifLineNumbers % v4.3
1251 \global\holdinginserts\@LN@outer@holdins % v4.21
1253 \global % v4.21 support for LaTeX2e earlier than 1996/07/26.
1256 \expandafter\let\csname endlinenomath*\endcsname\endlinenomath
1258 % The default is not to number the lines of a display. But
1259 % the package option ~mathlines~ may be used to switch
1262 \nolinenumberdisplaymath
1266 % Line number references
1267 % \unskip}\label{s:LNref}
1269 % Internals %% New subsec. v4.3.
1271 % The only way to get a label to a line number in a
1272 % paragraph is to ask the output routine to mark it.
1274 % (New v4.00) The following two paragraphs don't hold any
1275 % longer, see below. (/New v4.00)
1276 % \begin{old}\begin{verbatim}
1277 % % We use the marginpar mechanism to hook to ~\output~ for a
1278 % % second time. Marginpars are floats with number $-1$, we
1279 % % fake marginpars with No $-2$. Originally, every negative
1280 % % numbered float was considered to be a marginpar.
1282 % % The float box number ~\@currbox~ is used to transfer the
1283 % % label name in a macro called ~\@LNL@~<box-number>.
1286 % A ~\newlabel~ is written to the aux-file. The reference
1287 % is to ~\theLineNumber~, \emph{not} ~\thelinenumber~.
1288 % This allows to hook in, as done below for pagewise line
1291 % (New v3.03) The ~\@LN@ExtraLabelItems~ are added for a hook
1292 % to keep packages like ~{hyperref}~ happy. (/New v3.03)
1295 % We fire the ~\marginpar~ mechanism, so we leave \LaTeX's
1296 % ~\@addmarginpar~ untouched.
1297 % \begin{old}\begin{verbatim}
1298 % % \let\@LN@addmarginpar\@addmarginpar
1299 % % \def\@addmarginpar{%
1300 % % \ifnum\count\@currbox>-2\relax
1301 % % \expandafter\@LN@addmarginpar
1303 % % \@cons\@freelist\@currbox
1304 % % \protected@write\@auxout{}{%
1305 % % \string\newlabel
1306 % % {\csname @LNL@\the\@currbox\endcsname}%
1307 % % {{\theLineNumber}{\thepage}\@LN@ExtraLabelItems}}%
1311 % OK, we keep Stephan's ~\@LN@ExtraLabelItems~:
1314 \let\@LN@ExtraLabelItems\@empty
1317 % We imitate the ~\marginpar~ mechanism without using the
1318 % ~\@freelist~ boxes. ~\linelabel~ will indeed place a signal
1319 % penalty (~\@Mllbcodepen~, new), and it will put a label into
1320 % some list macro ~\@LN@labellist~. A new part of the output
1321 % routine will take the labels from the list and will write
1322 % ~\newlabel~s to the .aux file.
1324 % The following is a version of \LaTeX's ~\@xnext~.
1326 \def\@LN@xnext#1\@lt#2\@@#3#4{\def#3{#1}\gdef#4{#2}}
1328 % This takes an item ~#1~ from a list ~#4~ into ~#3~;
1329 % to be used as ~\expandafter\@LN@xnext#4\@@#3#4~.
1330 % Our lists use ~\@lt~ after each item for separating.
1331 % Indeed, there will be another list macro which can
1332 % appear as argument ~#4~, this will be used for moving
1333 % ~\vadjust~ items (section_\ref{ss:PVadj}).
1334 % The list for ~\linelabel~s is the following:
1336 \global\let\@LN@labellist\@empty
1338 % The next is the new part of the output routine writing the
1339 % ~\newlabel~ to the .aux file. Since it is no real page output,
1340 % the page is put back to top of the main vertical list.
1344 \expandafter \@LN@xnext \@LN@labellist \@@
1345 \@LN@label \@LN@labellist
1346 \protected@write\@auxout{}{\string\newlabel{\@LN@label}%
1347 {{\theLineNumber}{\thepage}\@LN@ExtraLabelItems}}%
1353 % The \scs{linelabel} command
1354 % \unskip}\label{ss:LL}
1355 % To refer to a place in line ~\ref{~<foo>~}~ at page
1356 % ~\pageref{~<foo>~}~ you place a ~\linelabel{~<foo>~}~ at
1360 % \marginpar{\tiny\raggedright
1361 % See if it works: This paragraph
1362 % starts on page \pageref{demo}, line
1366 % \begin{old}\begin{verbatim}
1367 % % If you use this command outside a ~\linenumbers~
1368 % % paragraph, you will get references to some bogus
1369 % % line numbers, sorry. But we don't disable the command,
1370 % % because only the ~\par~ at the end of a paragraph may
1371 % % decide whether to print line numbers on this paragraph
1372 % % or not. A ~\linelabel~ may legally appear earlier than
1376 % This trick is better not allowed---see subsections_\ref{ss:LL}
1377 % and_\ref{ss:OnOff}.
1381 % \begin{old}\begin{verbatim}
1382 % %, via a fake float number $-2$, %% new mechanism v4.00
1386 % ~\penalty~ into a ~\vadjust~, which triggers the
1387 % pagebuilder after putting the current line to the main
1388 % vertical list. A ~\write~ is placed on the main vertical
1389 % list, which prints a reference to the current value of
1390 % ~\thelinenumber~ and ~\thepage~ at the time of the
1393 % A ~\linelabel~ is allowed only in outer horizontal mode.
1394 % In outer vertical mode we start a paragraph, and ignore
1395 % trailing spaces (by fooling ~\@esphack~).
1397 % (New v4.00) We aim at relaxing the previous condition.
1398 % We insert a hook ~\@LN@mathhook~ and a shorthand
1399 % ~\@LN@postlabel~ to support the ~mathrefs~ option which
1400 % allows ~\linelabel~ in math mode.
1402 % The next paragraph is no longer valid.
1403 % \begin{old}\begin{verbatim}
1404 % % The argument of ~\linelabel~ is put into a macro with a
1405 % % name derived from the number of the allocated float box.
1406 % % Much of the rest is dummy float setup.
1412 % \begin{old}\begin{verbatim}
1413 % % \def\linelabel#1{%
1416 % I forgot ~\linenumbers~ today, costed me hours or so.
1418 \def\@LN@LLerror{\PackageError{lineno}{%
1419 \string\linelabel\space without \string\linenumbers}{%
1420 Just see documentation. (New feature v4.11)}\@gobble}
1422 % (New v4.3) Here some things have changed for v4.3.
1423 % The previous ~#1~ has been replaced by ~\@gobble~.
1424 % Ensuing, the ~\linelabel~ error message is re-implemented.
1425 % I find it difficult to compare efficiency of slight
1426 % alternatives---so choose an easy one. Explicit switching
1427 % in ~\linenumbers~ and ~\nolinenumbers~ is an additional
1428 % command that may better be avoided.
1430 \newcommand\linelabel{%
1431 \ifLineNumbers \expandafter \@LN@linelabel
1432 \else \expandafter \@LN@LLerror \fi}
1433 %%\let\linelabel\@LN@LLerror
1435 \gdef\@LN@linelabel#1{%
1437 % ~\gdef~ for hyperref ``symbolically''. (/New v4.11)
1439 \ifx\protect\@typeset@protect
1441 % $\gets$ And a ~\linelabel~ should never be replicated in a
1442 % mark or a TOC entry. (/New v4.3)
1446 \leavevmode \@bsphack \@savsk\p@
1459 % \begin{old}\begin{verbatim}
1460 % % \@floatpenalty -\@Mii
1461 % % \@next\@currbox\@freelist
1462 % % {\global\count\@currbox-2%
1463 % % \expandafter\gdef\csname @LNL@\the\@currbox\endcsname{#1}}%
1464 % % {\@floatpenalty\z@ \@fltovf \def\@currbox{\@tempboxa}}%
1466 % % \setbox\@currbox \color@vbox \vbox \bgroup \end@float
1468 % % \@ignorefalse \@esphack
1476 % The ~\@ignorefalse~ was appropriate before because the
1477 % ~\@Esphack~ in ~\end@float~ set ~\@ignoretrue~. Cf._\LaTeX's
1478 % ~\@xympar~. (/New v4.00)
1486 % \begin{old}\begin{verbatim}
1490 % Instead of complaining, you may just do your job.
1497 % (New v4.00) The shorthand just does what happened
1498 % with ~linenox0.sty~ before ~ednmath0.sty~ (New v4.1:
1499 % now ~mathrefs~ option) appeared, and
1500 % the hook is initialized to serve the same purpose.
1501 % So errors come just where Stephan had built them in,
1502 % and this is just the \LaTeX\ ~\marginpar~ behaviour.
1504 \def\@LN@postlabel#1{\g@addto@macro\@LN@labellist{#1\@lt}%
1505 \vadjust{\penalty-\@Mllbcodepen}}
1506 \def\@LN@mathhook#1{\@parmoderr}
1510 % \modulolinenumbers[3]
1511 % \firstlinenumber{1}
1513 % The appearance of the line numbers
1514 % \unskip}\label{appearance}
1516 % Basic code %% own subsec. v4.2.
1519 % The line numbers are set as ~\tiny\sffamily\arabic{linenumber}~,
1520 % $10pt$ left of the text. With options to place it
1521 % right of the text, or . . .
1523 % . . . here are the hooks:
1525 \def\makeLineNumberLeft{%
1526 \hss\linenumberfont\LineNumber\hskip\linenumbersep}
1528 \def\makeLineNumberRight{%
1529 \linenumberfont\hskip\linenumbersep\hskip\columnwidth
1530 \hb@xt@\linenumberwidth{\hss\LineNumber}\hss}
1532 \def\linenumberfont{\normalfont\tiny\sffamily}
1534 \newdimen\linenumbersep
1535 \newdimen\linenumberwidth
1537 \linenumberwidth=10pt
1540 % Margin switching requires ~pagewise~ numbering mode, but
1541 % choosing the left or right margin for the numbers always
1544 \def\switchlinenumbers{\@ifstar
1545 {\let\makeLineNumberOdd\makeLineNumberRight
1546 \let\makeLineNumberEven\makeLineNumberLeft}%
1547 {\let\makeLineNumberOdd\makeLineNumberLeft
1548 \let\makeLineNumberEven\makeLineNumberRight}%
1551 \def\setmakelinenumbers#1{\@ifstar
1552 {\let\makeLineNumberRunning#1%
1553 \let\makeLineNumberOdd#1%
1554 \let\makeLineNumberEven#1}%
1555 {\ifx\c@linenumber\c@runninglinenumber
1556 \let\makeLineNumberRunning#1%
1558 \let\makeLineNumberOdd#1%
1559 \let\makeLineNumberEven#1%
1563 \def\leftlinenumbers{\setmakelinenumbers\makeLineNumberLeft}
1564 \def\rightlinenumbers{\setmakelinenumbers\makeLineNumberRight}
1568 % ~\LineNumber~ is a hook which is used for the modulo stuff.
1569 % It is the command to use for the line number, when you
1570 % customize ~\makeLineNumber~. Use ~\thelinenumber~ to
1571 % change the outfit of the digits.
1574 % We will implement two modes of operation:
1576 % \item numbers ~running~ through (parts of) the text
1577 % \item ~pagewise~ numbers starting over with one on top of
1580 % Both modes have their own count register, but only one is
1581 % allocated as a \LaTeX\ counter, with the attached
1582 % facilities serving both.
1584 \newcounter{linenumber}
1585 \newcount\c@pagewiselinenumber
1586 \let\c@runninglinenumber\c@linenumber
1588 % Only the running mode counter may be reset, or preset,
1589 % for individual paragraphs. The pagewise counter must
1590 % give a unique anonymous number for each line.
1592 % (New v4.3) ~\newcounter{linenumber}~
1593 % was the only ~\newcounter~ in the whole package, and
1594 % formerly I was near using ~\newcount~ instead. Yet
1595 % ~\newcounter~ may be quite useful for ~\includeonly~.
1596 % It also supports resetting ``subcounters'', but what
1597 % could these be? Well, ~edtable~ might introduce a
1598 % subcounter for columns.
1599 % (Note that \LaTeX's setting commands would work with
1600 % ~\newcount\c@linenumber~ already, apart from this.
1601 % And perhaps sometimes ~\refstepcounter{linenumber}~
1602 % wouldn't work---cf._my discussion of ~\stepcounter~ in
1603 % subsection_\ref{ss:MLN}, similarly ~\refstep...~ would
1605 % Even the usual redefinitions of ~\thelinenumber~ would
1606 % work. It is nice, on the other hand, that
1607 % ~\thelinenumber~ is predefined here. \LaTeX's
1608 % initialization of the value perhaps just serves making
1609 % clear \LaTeX\ counters should always be changed
1610 % globally.---Shortened and improved the discussion here.)
1614 % ~\c@linenumber~ usually is---globally---incremented by
1615 % ~\stepcounter~ (at present), so resetting it locally would
1616 % raise the save stack problem of \TeX book p._301, moreover
1617 % it would be is useless, there is no hope of keeping the
1618 % values local (but see subsection_\ref{ss:ILN}). So I insert
1619 % ~\global~: (/New v4.22)
1621 \newcommand*\resetlinenumber[1][\@ne]{%
1623 \c@runninglinenumber#1\relax}
1626 % \begin{old}\begin{verbatim}
1627 % % \newcommand\resetlinenumber[1][1]{\c@runninglinenumber#1}
1630 % Added ~\relax~, being quite sure that this does no harm
1631 % and is quite important, as with ~\setcounter~ etc.
1632 % I consider this a bug fix (although perhaps no user has
1633 % ever had a problem with this). (/New v4.00)
1635 % (v4.22: I had made much fuss about resetting subordinate
1636 % counters here---removed, somewhat postponed.)
1639 %% \newcommand*\resetlinenumber[1][\@ne]{%
1640 %% \ifx\c@linenumber\c@runninglinenumber
1641 %% \global\c@linenumber#1\relax
1642 %% \global\advance\c@linenumber\m@ne
1645 %% \PackageError{lineno}%% Shorthand!?
1646 %% {You can't reset line number in pagewise mode}%
1647 %% {This should suffice.}%
1652 % Running line numbers
1655 % Running mode is easy, ~\LineNumber~ and ~\theLineNumber~
1656 % produce ~\thelinenumber~, which defaults to
1657 % ~\arabic{linenumber}~, using the ~\c@runninglinenumber~
1658 % counter. This is the default mode of operation.
1660 \def\makeRunningLineNumber{\makeLineNumberRunning}
1662 \def\setrunninglinenumbers{%
1663 \def\theLineNumber{\thelinenumber}%
1664 \let\c@linenumber\c@runninglinenumber
1665 \let\makeLineNumber\makeRunningLineNumber
1668 \setrunninglinenumbers\resetlinenumber
1672 % Pagewise line numbers
1673 % \unskip}\label{ss:PW}
1675 % Difficult, if you think about it. The number has to be
1676 % printed when there is no means to know on which page it
1677 % will end up, except through the aux-file. My solution
1678 % is really expensive, but quite robust.
1680 % With version ~v2.00~ the hashsize requirements are
1681 % reduced, because we do not need one controlsequence for
1682 % each line any more. But this costs some computation time
1683 % to find out on which page we are.
1685 % ~\makeLineNumber~ gets a hook to log the line and page
1686 % number to the aux-file. Another hook tries to find out
1687 % what the page offset is, and subtracts it from the counter
1688 % ~\c@linenumber~. Additionally, the switch
1689 % ~\ifoddNumberedPage~ is set true for odd numbered pages,
1692 \def\setpagewiselinenumbers{%
1693 \let\theLineNumber\thePagewiseLineNumber
1694 \let\c@linenumber\c@pagewiselinenumber
1695 \let\makeLineNumber\makePagewiseLineNumber
1698 \def\makePagewiseLineNumber{\logtheLineNumber\getLineNumber
1706 % Each numbered line gives a line to the aux file
1708 % ~\@LN{~<line>~}{~<page>~}~
1710 % very similar to the ~\newlabel~ business, except that we need
1711 % an arabic representation of the page number, not what
1712 % there might else be in ~\thepage~.
1714 \def\logtheLineNumber{\protected@write\@auxout{}{%
1717 % As Daniel Doherty observed, the earlier line
1718 % \begin{old}\begin{verbatim}
1719 % % \string\@LN{\the\c@linenumber}{\noexpand\the\c@page}}}
1722 % here may lead into an infinite loop when the user resets
1723 % the page number (think of ~\pagenumbering~, e.g.).
1724 % Stephan and I brief\/ly discussed the matter and decided
1725 % to introduce a ``physical''-page counter to which
1726 % ~\logtheLineNumber~ refers. It was Stephan's idea to use
1727 % ~\cl@page~ for reliably augmenting the ``physical''-page
1728 % counter. However, this relies on the output routine once
1729 % doing ~\stepcounter{page}~. Before Stephan's
1730 % suggestion, I had thought of appending the stepping to
1731 % \LaTeX's ~\@outputpage~.---So the macro definition ends
1734 \string\@LN{\the\c@linenumber}{%
1737 %% \noexpand\number\n@LN@truepage}}}
1739 % The `truepage' counter must start with ~\c@~ so it works
1740 % with ~\include~, and the ~\@addtoreset~ below is needed
1741 % for the same purpose.
1743 \noexpand\the\c@LN@truepage}}}
1745 %% \newcount\n@LN@truepage
1746 %% \g@addto@macro\cl@page{\global\advance\n@LN@truepage\@ne}
1747 \newcount\c@LN@truepage
1748 \g@addto@macro\cl@page{\global\advance\c@LN@truepage\@ne}
1749 \@addtoreset{LN@truepage}{@ckpt}
1751 % (/New v4.2) I had thought of offering more
1752 % features of a \LaTeX\ counter. However, the user should
1753 % better \emph{not} have access to this counter. ~\c@page~
1754 % should suffice as a pagewise master counter.---To be sure,
1755 % along the present lines the user \emph{can} manipulate
1756 % ~\c@LN@truepage~ by ~\stepcounter{page}~. E.g., she might
1757 % do this in order to manually insert a photograph. Well,
1758 % seems not to harm.
1760 % The above usage of ~\g@addto@macro~ and ~\cl@page~ may be
1761 % not as stable as Stephan intended. His proposal used
1762 % ~\xdef~ directly. But he used ~\cl@page~ as well, and who
1763 % knows \dots{} And as to ~\g@addto@macro~, I have introduced
1764 % it for list macros anyway.
1765 % (/UL) (/New v4.00)
1767 % From the aux-file we get one macro ~\LN@P~<page> for each
1768 % page with line numbers on it. This macro calls four other
1769 % macros with one argument each. These macros are
1770 % dynamically defined to do tests and actions, to find out
1771 % on which page the current line number is located.
1773 % We need sort of a pointer to the first page with line
1774 % numbers, initiallized to point to nothing:
1776 \def\LastNumberedPage{first}
1777 \def\LN@Pfirst{\nextLN\relax}
1779 % The four dynamic macros are initiallized to reproduce
1780 % themselves in an ~\xdef~
1782 \let\lastLN\relax % compare to last line on this page
1783 \let\firstLN\relax % compare to first line on this page
1784 \let\pageLN\relax % get the page number, compute the linenumber
1785 \let\nextLN\relax % move to the next page
1787 % During the end-document run through the aux-files, we
1788 % disable ~\@LN~. I may put in a check here later, to give
1789 % a rerun recommendation.
1791 \AtEndDocument{\let\@LN\@gobbletwo}
1793 % Now, this is the tricky part. First of all, the whole
1794 % definition of ~\@LN~ is grouped, to avoid accumulation
1795 % on the save stack. Somehow ~\csname~<cs>~\endcsname~ pushes
1796 % an entry, which stays after an ~\xdef~ to that <cs>.
1798 % If ~\LN@P~<page> is undefined, initialize it with the
1799 % current page and line number, with the
1800 % \emph{pointer-to-the-next-page} pointing to nothing. And
1801 % the macro for the previous page will be redefined to point
1802 % to the current one.
1804 % If the macro for the current page already exists, just
1805 % redefine the \emph{last-line-number} entry.
1807 % Finally, save the current page number, to get the pointer to the
1808 % following page later.
1810 \def\@LN#1#2{{\expandafter\@@LN
1811 \csname LN@P#2C\@LN@column\expandafter\endcsname
1812 \csname LN@PO#2\endcsname
1815 \def\@@LN#1#2#3#4{\ifx#1\relax
1816 \ifx#2\relax\gdef#2{#3}\fi
1817 \expandafter\@@@LN\csname LN@P\LastNumberedPage\endcsname#1%
1818 \xdef#1{\lastLN{#3}\firstLN{#3}%
1819 \pageLN{#4}{\@LN@column}{#2}\nextLN\relax}%
1821 \def\lastLN##1{\noexpand\lastLN{#3}}%
1824 \xdef\LastNumberedPage{#4C\@LN@column}}
1826 % The previous page macro gets its pointer to the
1827 % current one, replacing the ~\relax~ with the cs-token
1830 \def\@@@LN#1#2{{\def\nextLN##1{\noexpand\nextLN\noexpand#2}%
1833 % Now, to print a line number, we need to find the page,
1834 % where it resides. This will most probably be the page where
1835 % the last one came from, or maybe the next page. However, it can
1836 % be a completely different one. We maintain a cache,
1837 % which is ~\let~ to the last page's macro. But for now
1838 % it is initialized to expand ~\LN@first~, where the poiner
1839 % to the first numbered page has been stored in.
1841 \def\NumberedPageCache{\LN@Pfirst}
1843 % To find out on which page the current ~\c@linenumber~ is,
1844 % we define the four dynamic macros to do something usefull
1845 % and execute the current cache macro. ~\lastLN~ is run
1846 % first, testing if the line number in question may be on a
1847 % later page. If so, disable ~\firstLN~, and go on to the
1848 % next page via ~\nextLN~.
1850 \def\testLastNumberedPage#1{\ifnum#1<\c@linenumber
1851 \let\firstLN\@gobble
1854 % Else, if ~\firstLN~ finds out that we need an earlier
1855 % page, we start over from the beginning. Else, ~\nextLN~
1856 % will be disabled, and ~\pageLN~ will run
1857 % ~\gotNumberedPage~ with four arguments: the first line
1858 % number on this column, the page number, the column
1859 % number, and the first line on the page.
1861 \def\testFirstNumberedPage#1{\ifnum#1>\c@linenumber
1862 \def\nextLN##1{\testNextNumberedPage\LN@Pfirst}%
1865 \def\pageLN{\gotNumberedPage{#1}}%
1868 % We start with ~\pageLN~ disabled and ~\nextLN~ defined to
1869 % continue the search with the next page.
1871 \long\def \@gobblethree #1#2#3{}
1873 \def\testNumberedPage{%
1874 \let\lastLN\testLastNumberedPage
1875 \let\firstLN\testFirstNumberedPage
1876 \let\pageLN\@gobblethree
1877 \let\nextLN\testNextNumberedPage
1881 % When we switch to another page, we first have to make
1882 % sure that it is there. If we are done with the last
1883 % page, we probably need to run \TeX\ again, but for the
1884 % rest of this run, the cache macro will just return four
1885 % zeros. This saves a lot of time, for example if you have
1886 % half of an aux-file from an aborted run, in the next run
1887 % the whole page-list would be searched in vain again and
1888 % again for the second half of the document.
1890 % If there is another page, we iterate the search.
1892 \def\testNextNumberedPage#1{\ifx#1\relax
1893 \global\def\NumberedPageCache{\gotNumberedPage0000}%
1894 \PackageWarningNoLine{lineno}%
1895 {Linenumber reference failed,
1896 \MessageBreak rerun to get it right}%
1898 \global\let\NumberedPageCache#1%
1904 % \marginpar{\tiny\raggedright
1905 % Let's see if it finds the label
1906 % on page \pageref{demo},
1907 % line \ref{demo}, and back here
1908 % on page \pageref{demo2}, line
1911 % To separate the official hooks from the internals there is
1912 % this equivalence, to hook in later for whatever purpose:
1914 \let\getLineNumber\testNumberedPage
1916 % So, now we got the page where the number is on. We
1917 % establish if we are on an odd or even page, and calculate
1918 % the final line number to be printed.
1920 \newif\ifoddNumberedPage
1921 \newif\ifcolumnwiselinenumbers
1922 \columnwiselinenumbersfalse
1924 \def\gotNumberedPage#1#2#3#4{\oddNumberedPagefalse
1925 \ifodd \if@twocolumn #3\else #2\fi\relax\oddNumberedPagetrue\fi
1926 \advance\c@linenumber\@ne
1927 \ifcolumnwiselinenumbers
1928 \subtractlinenumberoffset{#1}%
1930 \subtractlinenumberoffset{#4}%
1934 % You might want to run the pagewise mode with running line
1935 % numbers, or you might not. It's your choice:
1937 \def\runningpagewiselinenumbers{%
1938 \let\subtractlinenumberoffset\@gobble
1941 \def\realpagewiselinenumbers{%
1942 \def\subtractlinenumberoffset##1{\advance\c@linenumber-##1\relax}%
1945 \realpagewiselinenumbers
1947 % For line number references, we need a protected call to
1948 % the whole procedure, with the requested line number stored
1949 % in the ~\c@linenumber~ counter. This is what gets printed
1950 % to the aux-file to make a label:
1952 \def\thePagewiseLineNumber{\protect
1953 \getpagewiselinenumber{\the\c@linenumber}}%
1955 % And here is what happens when the label is refered to:
1957 \def\getpagewiselinenumber#1{{%
1958 \c@linenumber #1\relax\testNumberedPage
1963 % A summary of all per line expenses:
1964 % \begin{description}\item
1965 % [CPU:] The ~\output~ routine is called for each line,
1966 % and the page-search is done.
1968 % [DISK:] One line of output to the aux-file for each
1971 % [MEM:] One macro per page. Great improvement over v1.02,
1972 % which had one control sequence per line in
1973 % addition. It blew the hash table after some five
1978 % Twocolumn mode (New v3.06)
1981 % Twocolumn mode requires another patch to the ~\output~
1982 % routine, in order to print a column tag to the .aux
1985 \AtBeginDocument{% v4.2, revtex4.cls (e.g.).
1986 % <- TODO v4.4+: Or better in \LineNoLaTeXOutput!?
1987 \let\@LN@orig@makecol\@makecol}
1990 \setbox\@outputbox \vbox{%
1991 \boxmaxdepth \@maxdepth
1992 \protected@write\@auxout{}{%
1993 \string\@LN@col{\if@firstcolumn1\else2\fi}%
1997 } %% TODO cf. revtexln.sty.
1999 \def\@LN@col{\def\@LN@column} % v4.22, removed #1.
2004 % Numbering modulo $m$, starting at $f$
2005 %% Numbering modulo 5
2006 % \unskip}\label{ss:Mod}
2008 % Most users want to have only one in five lines numbered.
2009 % ~\LineNumber~ is supposed to produce the outfit of the
2010 % line number attached to the line, while ~\thelinenumber~
2011 % is used also for references, which should appear even if
2012 % they are not multiples of five.
2014 % (New v4.00) Moreover, some users want to
2015 % control which line number should be printed first. Support
2016 % of this is now introduced here---see ~\firstlinenumber~
2017 % below.---~numline.sty~ by Michael Jaegermann and
2018 % James Fortune offers controlling which \emph{final}
2019 % line numbers should not be printed. What is
2020 % it good for? We ignore this here until some user demands
2021 % it.---Peter Wilson's ~ledmac.sty~ offers much different
2022 % choices of line numbers to be printed, due to Wayne Sullivan.
2025 % (New v4.22) ~\c@linenumbermodulo~ is rendered a
2026 % fake counter, as discussed since v4.00. So it can
2027 % no longer be set by ~\setcounter~. ~\modulolinenumbers~
2028 % serves this purpose. Well, does anybody want to do
2029 % what worked with ~\addtocounter~? (Then please tell
2030 % me.)---At least, ~\value~ still works. For the same
2031 % purpose I rename the fake `firstlinenumber' counter
2032 % ~\n@...~ to ~\c@...~. (/New v4.22)
2033 % \begin{old}\begin{verbatim}
2034 % % \newcount\c@linenumbermodulo % removed for v4.22
2038 %% Removed for v4.22:
2039 %% (UL) On my question why, e.g.,
2040 %% ~\chardef~ would not have sufficed, Stephan couldn't remember
2041 %% exactly; guessed that he wanted to offer \LaTeX\ counter
2042 %% facilities. However, the typical ones don't come this way.
2043 %% So I'm quite sure that I will change this next time.
2045 %% However, I observed at least two times that users gave a very
2046 %% high value to ~\c@linenumbermodulo~ in order to suppress
2047 %% printing of the line number. One of these users preferred an
2048 %% own way of handling line numbers, just wanted to use
2049 %% ~\linelabel~ and ~ednotes.sty~ features. Should we support this?
2050 %% I rather would like to advise them to
2051 %% ~\let\makeLineNumber\relax~. (/UL)
2054 % ~\themodulolinenumber~ waits for being declared
2055 % ~\LineNumber~ by ~\modulolinenumbers~. (This has
2056 % been so before, no change.) Here is how it
2058 % \begin{old}\begin{verbatim}
2059 % % \def\themodulolinenumber{{\@tempcnta\c@linenumber
2060 % % \divide\@tempcnta\c@linenumbermodulo
2061 % % \multiply\@tempcnta\c@linenumbermodulo
2062 % % \ifnum\@tempcnta=\c@linenumber\thelinenumber\fi
2066 % (UL) This was somewhat slow. This arithmetic
2067 % happens at every line. This time I tend to declare an extra
2069 % line counter (as opposed to my usual recommendations to use
2070 % counters as rarely as possible) which is stepped every line.
2071 % It could be incremented in the same way as ~\c@LN@truepage~
2072 % is incremented via ~\cl@page~! This is another point in favour
2073 % of ~{linenumber}~ being a \LaTeX\ counter!
2074 % When this new counter equals ~\c@linenumbermodulo~, it is reset,
2075 % and ~\thelinenumber~ is executed.---It gets much slower by my
2076 % support of controlling the first line number below. I should
2077 % improve this.---On
2078 %% %% TODO v4.4+--pagewise!?
2079 % the other hand, time expense means very little nowadays,
2080 % while the number of \TeX\ counters still is limited.
2082 % For the same purpose, moreover, attaching the line number
2083 % box could be intercepted earlier (in ~\MakeLineNo~),
2084 % without changing ~\LineNumber~. However, this may be
2085 % bad for the latter's announcement as a wizard interface
2086 % in section_\ref{s:UserCmds}.
2088 %% I wonder about Stephan's group. Its only effect is that
2089 %% ~\@tempcnta~ is restored after using it. What for is this?
2090 %% I tend to remove the group braces. %% TODO v4.4+
2093 % Here is the new code. It is very near to my ~lnopatch.sty~
2094 % code which introduced the first line number feature
2095 % before.---I add starting with a ~\relax~ which is so often
2096 % recommended---without understanding this really. At least,
2097 % it will not harm.---Former group braces appear as
2098 % ~\begingroup~/~\endgroup~ here.
2100 \def\themodulolinenumber{\relax
2101 \ifnum\c@linenumber<\c@firstlinenumber \else
2103 \@tempcnta\c@linenumber
2104 \advance\@tempcnta-\c@firstlinenumber
2105 \divide\@tempcnta\c@linenumbermodulo
2106 \multiply\@tempcnta\c@linenumbermodulo
2107 \advance\@tempcnta\c@firstlinenumber
2108 \ifnum\@tempcnta=\c@linenumber \thelinenumber \fi
2115 % The user command to set the modulo counter:
2116 % (New v4.31) \dots\ a star variant is introduced to implement
2117 % Hillel Chayim Yisraeli's idea to print the first line number
2118 % after an interruption of the edited text by some editor's
2119 % text, regardless of the modulo. If it is 1, it is printed only
2120 % with ~\firstlinenumber{1}~. I.e., you use ~\modulolinenumbers*~
2121 % for the new feature, without the star you get the simpler
2122 % behaviour that we have had so far. And you can switch back
2123 % from the refined behaviour to the simple one by using
2124 % ~\modulolinenumbers~ without the star.---This enhancement
2125 % is accompanied by a new package option ~modulo*~ which just
2126 % executes ~\modulolinenumbers*~
2127 % (subsection_\ref{ss:v3opts}).---`With ~\firstlinenumber{1}~'
2128 % exactly means: `1' is printed if and only if the last
2129 % ~\firstlinenumber~ before or in the paragraph that follows
2130 % the ``interruption'' has argument `1' (or something
2131 % \emph{expanding} to `1', or (to) something that \TeX\
2132 % ``reads'' as 1, e.g.: a \TeX\ count register storing
2133 % 1).---At present, this behaviour may be unsatisfactory with
2134 % pagewise line-numbering $\dots$ I'll make an experimental
2135 % extra package if someone complains \dots
2137 \newcommand\modulolinenumbers{%
2139 {\def\@LN@maybe@moduloresume{%
2140 \global\let\@LN@maybe@normalLineNumber
2141 \@LN@normalLineNumber}%
2142 \@LN@modulolinenos}%
2143 {\let\@LN@maybe@moduloresume\relax \@LN@modulolinenos}%
2146 \global\let\@LN@maybe@normalLineNumber\relax
2147 \let\@LN@maybe@moduloresume\relax
2148 \gdef\@LN@normalLineNumber{%
2149 \ifnum\c@linenumber=\c@firstlinenumber \else
2150 \ifnum\c@linenumber>\@ne
2151 \def\LineNumber{\thelinenumber}%
2155 % ~\def~ instead of ~\let~ enables taking account of a
2156 % redefinition of ~\thelinenumber~ in a present numbering
2157 % environment (e.g.).
2159 \global\let\@LN@maybe@normalLineNumber\relax}
2161 % Instead of changing ~\LineNumber~ directly by
2162 % ~LN@moduloresume~, these tricks enable ~\modulolinenumbers*~
2163 % to act as locally as I can make it. I don't know how to
2164 % avoid that the output routine switches back to the normal
2165 % modulo behaviour by a global change. (An ~\aftergroup~ may
2166 % fail in admittedly improbable cases.)
2168 \newcommand*\@LN@modulolinenos[1][\z@]{%
2170 % The definition of this macro is that of the former
2171 % ~\modulolinenumbers~. (/New v4.31)
2173 \let\LineNumber\themodulolinenumber
2175 \chardef % v4.22, note below
2176 \c@linenumbermodulo#1\relax
2178 % \begin{old}\begin{verbatim}
2179 % % \def\LineNumber{\thelinenumber}%
2182 % (New v4.00) I am putting something here to enable
2183 % ~\firstlinenumber~ with $~\c@linenumbermodulo~=1$.
2184 % With ~lnopatch.sty~, a trick was offered for this purpose.
2185 % It is now obsolete.
2187 \def\LineNumber{\@LN@ifgreat\thelinenumber}%
2194 % (New v4.00) The default of ~\@LN@ifgreat~ is
2196 \let\@LN@ifgreat\relax
2198 % The previous changes as soon as ~\firstlinenumber~ is used:
2200 \newcommand*\firstlinenumber[1]{%
2201 \chardef\c@firstlinenumber#1\relax
2203 % No counter, little values allowed only---OK?---(UL)
2204 % The change is local---OK? The good thing is that
2205 % ~\global\firstlinenumber{~<number>~}~ works. Moreover,
2206 % ~\modulolinenumbers~ acts locally as well. (/UL)
2210 \let\@LN@ifgreat\@LN@ifgreat@critical}
2212 \def\@LN@ifgreat@critical{%
2213 \ifnum\c@linenumber<\c@firstlinenumber
2214 \expandafter \@gobble
2220 % value of ~\c@firstlinenumber~ %% v4.31
2221 % is 0. This is best for what one would expect from modulo
2224 \let\c@firstlinenumber=\z@
2227 % For usage and effects of ~\modulolinenumbers~ and %% v4.31
2228 % ~\firstlinenumbers~, please consult section_\ref{s:UserCmds}.
2229 % Two details on ~\firstlinenumbers~ here:
2230 % (i)_~\firstlinenumber~ acts on a paragraph if and only if
2231 % (a)_the paragraph is broken into lines ``in line-numbering
2232 % mode'' (after ~\linenumbers~, e.g.);
2233 % (b)_it is the last occurrence of a ~\firstlinenumbers~
2234 % before or in the paragraph.
2235 % (The practical applications of this that I can imagine
2236 % don't seem appealing to me.)
2237 % Cf._the explanation above of how ~\modulolinenumbers~ and
2238 % ~\firstlinenumbers~ interact---for this and for (ii),
2239 % which is concerned with possible arguments for
2240 % ~\firstlinenumbers~.
2242 % Note that the line numbers of the present section
2243 % demonstrate the two devices. (/New v4.00)
2245 %%\setcounter{linenumbermodulo}{5}
2246 \chardef\c@linenumbermodulo=5 % v4.2; ugly?
2247 \modulolinenumbers[1]
2249 % (New v4.22) The new implementation through ~\chardef~
2250 % decreases the functionality and raises certain compatibility
2251 % problems. I face this without fear. The maximum modulo value
2252 % is now ~255~. I expect that this suffices for usual applications.
2253 % However, some users have ``abused'' ~lineno.sty~ to get
2254 % ~ednotes.sty~ features without line numbers, so have set the
2255 % modulo to a value beyond the total number of lines in their
2256 % edition. This ought to be replaced by
2257 % ~\let\makeLineNumber\relax~. (/New v4.22)
2261 % \unskip}\label{s:Opts}
2264 % The last heading formerly was the heading of what is now
2265 % subsection_\ref{ss:v3opts}. The options declared there were
2266 % said to execute user commands only. This was wrong already
2267 % concerning ~displaymath~ and ~hyperref~. At least, however,
2268 % these options were no or almost no occasion to skip definitions
2269 % or allocations. This is different with the options that we now
2272 %% (New v4.2) v4.00 moved the ``options'' below the
2273 %% ``extensions''. This was bad with ~\do@mlineno~ in
2274 %% subsection_\ref{ss:v3opts} which is to control
2275 %% subsection_\ref{ss:display}---undone here. (/New v4.2)
2278 % Extended referencing to line numbers. (v4.2)
2280 % This subsection explains and declares package option ~addpageno~. %% v4.31
2282 % If a line to whose number you refer by ~\ref~ is not on the
2283 % present page, it may be useful to add the number of the page
2284 % on which the line occurs---and perhaps it should not be added
2285 % otherwise. In general, you could use the Standard \LaTeX\
2286 % package varioref for this. However, the latter usually
2287 % produces verbose output like `on the preceding page'---
2288 % unless costumized---, while in critical editions, e.g., one
2289 % may prefer just adding the page number and some mark on the
2290 % left of the line number, irrespectively of how far the page is
2291 % apart etc. To support this, package option ~addpageno~
2292 % provides a command ~\vpagelineref~ to be used in place of
2293 % ~\ref~. This produces, e.g., `34.15' when referring to line_15
2294 % on page_34 while the present page is not 34. You can customize
2295 % the outcome, see the package file ~vplref.sty~ where the code
2296 % and further details are. You may conceive of
2297 % ~\vpagelineref~ as a certain customization of varioref's
2300 % This implies that option ~addpageno~ requires the files
2301 % ~vplref.sty~ and ~varioref.sty~. ~addpageno~ automatically
2302 % loads both of them. Yet you can also load ~varioref.sty~
2303 % on your own to use its package options.
2305 % Of course, you might better introduce a shorter command name
2306 % for ~\vpagelineref~ for your work, while we cannot predict
2307 % here what shorthand will fit your work. E.g.,
2308 % ~\newcommand{\lref}{\vpagelineref}~.
2310 % If you really want to add the page number in \emph{any} case,
2311 % use, e.g., some ~\myref~ instead of ~\ref~, after
2312 % \[~newcommand*{\myref}{\pageref{#1}.\ref{#1}}~\]
2313 % or what you like. You don't need the ~addpageno~ option in
2316 % ~addpageno~ is due to a suggestion by Sergei Mariev.
2318 \DeclareOption{addpageno}{%
2319 \AtEndOfPackage{\RequirePackage{vplref}[2005/04/25]}}
2322 % \scs{linelabel} in math mode
2323 % \unskip}\label{ss:MathRef}
2325 % We have made some first steps towards allowing ~\linelabel~ in
2326 % math mode. Because our code for this is presently experimental,
2327 % we leave it to the user to decide for the experiment by calling
2328 % option ~mathrefs~. We are in a hurry now and thus leave the
2329 % code, explanations, and discussion in the separate package
2330 % ~ednmath0.sty~. Maybe we later find the time to improve the
2331 % code and move the relevant content of ~ednmath0.sty~ to here.
2332 % The optimal situation would be to define ~\linelabel~ from
2333 % the start so it works in math mode, omitting the ~mathrefs~
2336 % Actually, this package even provides adjustments for analogously
2337 % allowing ~ednotes.sty~ commands in math mode. Loading the package
2338 % is postponed to ~\AtBeginDocument~ when we know whether these
2339 % adjustments are needed.
2341 \DeclareOption{mathrefs}{\AtBeginDocument
2342 {\RequirePackage{ednmath0}[2004/08/20]}}
2346 % Arrays, tabular environments (Revised v4.11)
2347 % \unskip}\label{ss:Tab}
2349 % This subsection explains and declares package options %% v4.31
2350 % ~edtable~, ~longtable~, and ~nolongtablepatch~.
2352 % The standard \LaTeX\ tabular environments come as single
2353 % boxes, so the ~lineno.sty~ versions before v4.00 treated them as
2354 % (parts of) single lines, printing (at most) one line number
2355 % beside each and stepping the line number counter once only.
2356 % Moreover, ~\linelabel~s got lost. Of course, tables are
2357 % usually so high that you will want to treat each row like a
2358 % line. (Christian Tapp even desires that the lines of table
2359 % entries belonging to a single row are treated like ordinary
2360 % lines.) Footnotes get lost in such environments as well, which
2361 % was bad for ~ednotes.sty~.
2363 % We provide adjustments to count lines, print their numbers
2364 % etc.\ as desired at least for \emph{some} \LaTeX\ tabular
2365 % environments. (Like with other details, ``some'' is to some
2366 % extent explained in ~edtable.sty~.) We do this similarly as
2367 % with option ~mathrefs~ before. We leave code
2368 % and explanations in the separate package ~edtable.sty~.
2369 % (For wizards: this package provides adjustments for
2370 % ~ednotes.sty~ as well. However, in the present case we don't try
2371 % to avoid them unless ~ednotes.sty~ is loaded.)
2372 % Package option ~edtable~
2373 % defines---by loading ~edtable.sty~---an environment ~{edtable}~
2374 % which is able to change some \LaTeX\ tabular environments
2375 % with the desired effects. (v4.11: ~edtable.sty~ v1.3 counts
2376 % \LaTeX's ~{array}~ [etc.\@] as a ``tabular environment'' as
2379 % The ~{edtable}~ environment doesn't help with ~longtable.sty~,
2380 % however. To make up for this, ~{longtable}~ is adjusted in a
2381 % different way---and this happens only when another ~lineno.sty~
2382 % option ~longtable~ is called. In this case, option ~edtable~
2383 % needn't be called explicitly: option ~longtable~ works as if
2384 % ~edtable~ had been called.
2386 % Now, we are convinced that vertical spacing around
2387 % ~{longtable}~ works wrongly---see \LaTeX\ bugs database
2388 % tools/3180 and 3485, or see explanations in the package
2389 % ~ltabptch.sty~ (which is to be obtained from CTAN folder
2390 % \path{macros/latex/ltabptch}). Our conviction is so strong
2391 % that the ~longtable~ option loads---after ~longtable.sty~---the
2392 % patch package ~ltabptch.sty~. If the user doesn't want this
2393 % (maybe preferring her own arrangement with the vertical
2394 % spacing), she can forbid it by calling ~nolongtablepatch~.
2396 % The following code just collects some choices, which are
2397 % then executed in section_\ref{ss:ExOpt}. We use an ~\if...~
2398 % without ~\newif~ since ~\if...true~ and ~\if...false~
2399 % would occur at most two times and only within the present
2400 % package. (~\AtEndOfClass{\RequirePackage{edtable}}~
2401 % could be used instead, I just overlooked this. Now I don't
2402 % change it because it allows to change the version requirement
2403 % at one place only.)
2405 \let\if@LN@edtable\iffalse
2407 \DeclareOption{edtable}{\let\if@LN@edtable\iftrue}
2409 \DeclareOption{longtable}{\let\if@LN@edtable\iftrue
2410 \PassOptionsToPackage{longtable}{edtable}}
2412 \DeclareOption{nolongtablepatch}{%
2413 \PassOptionsToPackage{nolongtablepatch}{edtable}}
2418 % Switch among settings
2419 % \unskip}\label{ss:v3opts}
2421 % There is a bunch of package options that execute %% v4.2
2422 %% There is a bunch of package options, all of them executing
2423 %% executing only user commands (see below). %% Cf. start of section.
2424 % user commands only.
2426 % Options ~left~ (~right~) put the line numbers on the left
2427 % (right) margin. This works in all modes. ~left~ is the
2430 \DeclareOption{left}{\leftlinenumbers*}
2432 \DeclareOption{right}{\rightlinenumbers*}
2434 % Option ~switch~ (~switch*~) puts the line numbers on the
2435 % outer (inner) margin of the text. This requires running
2436 % the pagewise mode, but we turn off the page offset
2437 % subtraction, getting sort of running numbers again. The
2438 % ~pagewise~ option may restore true pagewise mode later.
2440 \DeclareOption{switch}{\setpagewiselinenumbers
2442 \runningpagewiselinenumbers}
2444 \DeclareOption{switch*}{\setpagewiselinenumbers
2445 \switchlinenumbers*%
2446 \runningpagewiselinenumbers}
2448 % In twocolumn mode, we can switch the line numbers to
2449 % the outer margin, and/or start with number 1 in each
2450 % column. Margin switching is covered by the ~switch~
2453 \DeclareOption{columnwise}{\setpagewiselinenumbers
2454 \columnwiselinenumberstrue
2455 \realpagewiselinenumbers}
2457 % The options ~pagewise~ and ~running~ select the major
2458 % linenumber mechanism. ~running~ line numbers refer to a real
2459 % counter value, which can be reset for any paragraph,
2460 % even getting multiple paragraphs on one page starting
2461 % with line number one. ~pagewise~ line numbers get a
2462 % unique hidden number within the document, but with the
2463 % opportunity to establish the page on which they finally
2464 % come to rest. This allows the subtraction of the page
2465 % offset, getting the numbers starting with 1 on top of each
2466 % page, and margin switching in twoside formats becomes
2467 % possible. The default mode is ~running~.
2469 % The order of declaration of the options is important here
2470 % ~pagewise~ must come after ~switch~, to overide running
2471 % pagewise mode. ~running~ comes last, to reset the running
2472 % line number mode, e.g, after selecting margin switch mode
2473 % for ~pagewise~ running. Once more, if you specify all
2474 % three of the options ~[switch,pagewise,running]~, the
2475 % result is almost nothing, but if you later say
2476 % ~\pagewiselinenumbers~, you get margin switching, with
2477 % real pagewise line numbers.
2479 \DeclareOption{pagewise}{\setpagewiselinenumbers
2480 \realpagewiselinenumbers}
2482 \DeclareOption{running}{\setrunninglinenumbers}
2484 % The option ~modulo~ causes only those linenumbers to be
2485 % printed which are multiples of five.
2487 \DeclareOption{modulo}{\modulolinenumbers\relax}
2489 % Option ~modulo*~ modifies ~modulo~ in working like
2490 % ~\modulolinenumbers*~---see section_\ref{s:UserCmds}.
2492 \DeclareOption{modulo*}{\modulolinenumbers*\relax}
2494 % The package option ~mathlines~ switches the behavior of
2495 % the ~{linenomath}~ environment with its star-form.
2496 % Without this option, the ~{linenomath}~ environment does
2497 % not number the lines of the display, while the star-form
2498 % does. With this option, its just the opposite.
2500 %%% 1999-06-10: renamed ~displaymath~ to ~mathlines~.
2502 \DeclareOption{mathlines}{\linenumberdisplaymath}
2504 % ~displaymath~ now calls for wrappers of the standard
2505 % \LaTeX\ display math environment. This was previously
2506 % done by ~mlineno.sty~.
2508 % (New v4.3) Option `displaymath' becomes default according
2509 % to Erik \mbox{Luijten}'s suggestion. I was finally convinced
2510 % of this as soon as I discovered how to avoid a spurious line
2511 % number above ~\begin{linenomath}~ (subsection_\ref{ss:DM}).
2512 % ~\endlinenomath~ provides ~\ignorespaces~, so what could go
2515 \DeclareOption{displaymath}{\PackageWarningNoLine{lineno}{%
2516 Option [displaymath] is obsolete -- default now!}}
2518 %%\let\do@mlineno\relax
2519 %%\DeclareOption{displaymath}{\let\do@mlineno\@empty}
2523 % Compatibility with \texttt{hyperref} %% own subsec. v4.3.
2525 % The ~hyperref~ package, via ~nameref~, requires three more
2526 % groups in the second argment of a ~\newlabel~. Well, why
2527 % shouldn't it get them? (New v3.07) The presence of the
2528 % ~nameref~ package is now detected automatically
2529 % ~\AtBeginDocument~. (/New v3.07) (Fixed in v3.09) We try
2530 % to be smart, and test ~\AtBeginDocument~ if the ~nameref~
2531 % package is loaded, but ~hyperref~ postpones the loading of
2532 % ~nameref~ too, so this is all in vain.
2534 % (New v4.3) But we can also test at the first ~\linelabel~.
2535 % Regarding the error-message for misplaced ~\linelabel~ from v4.11:
2536 % previously, ~\linenumbers~ rendered ~\linelabel~ the genuine
2537 % version of ~\linelabel~ from the start on. This doesn't work
2538 % now, since ~\@LN@linelabel~ may change its meaning after the
2539 % first ~\linenumbers~ and before a next one (if there is some).
2542 \DeclareOption{hyperref}{\PackageWarningNoLine{lineno}{%
2543 Option [hyperref] is obsolete.
2544 \MessageBreak The hyperref package is detected automatically.}}
2547 \@ifpackageloaded{nameref}{%
2549 % (New v4.3) ``Global'' is merely ``symbolic'' ~\AtBeginDoc...~.
2550 % If ~nameref~ is not detected here, the next ~\@LN@linelabel~
2551 % will do almost the same, then globally indeed.
2553 \gdef\@LN@ExtraLabelItems{{}{}{}}%
2555 \global\let\@LN@@linelabel\@LN@linelabel
2556 \gdef\@LN@linelabel{%
2558 % ~\@ifpackageloaded~ is ``preamble only'', its---very
2559 % internal---preamble definition is replicated here:
2562 \ifx\csname ver@nameref.sty\endcsname\relax \else
2563 \gdef\@LN@ExtraLabelItems{{}{}{}}%
2566 % Now aim at the ``usual'' behaviour:
2568 \global\let\@LN@linelabel\@LN@@linelabel
2569 \global\let\@LN@@linelabel\relax
2579 % A note on calling so many options
2582 % The number of package options may stimulate worrying about how to
2583 % \emph{enter} all the options that one would like to use---they may
2584 % not fit into one line. Fortunately, you can safely break code lines
2585 % after the commas separating the option names in the ~\usepackage~
2586 % command (no comment marks needed).
2590 % \unskip}\label{ss:ExOpt}
2592 % We stop declaring options and execute the ones that are
2593 % called by the user. (/New v4.1)
2597 % (New v4.1) Now we know whether ~edtable.sty~ is wanted
2598 % and (if it is) with which options it is to be called.
2600 \if@LN@edtable \RequirePackage{edtable}[2005/03/07] \fi
2605 % Former package extensions
2606 % \label{s:Xt}\unskip}
2608 % The extensions in this section were previously supplied
2609 % in separate ~.sty~ files.
2613 % \unskip}\label{ss:display}
2615 % (New v4.3) From now on, you no longer need to type
2616 % the ~{linenomath}~ environment with the ~\[~, ~{equation}~,
2617 % and ~{eqnarray}~ environments---and you no longer need to
2618 % use the former package option ~displaymath~ for this feature.
2622 % The standard \LaTeX\ display math environments are
2623 % wrapped in a ~{linenomath}~ environment.
2625 % (New 3.05) The ~[fleqn]~ option of the standard
2626 % \LaTeX\ classes defines the display math
2627 % environments such that line numbers appear just
2628 % fine. Thus, we need not do any tricks when
2629 % ~[fleqn]~ is loaded, as indicated by presents of
2630 % the ~\mathindent~ register. (/New 3.05)
2632 % (New 3.05a) for ~{eqnarray}~s we rather keep the
2633 % old trick. (/New 3.05a)
2635 % (New 3.08) Wrap ~\[~ and ~\]~ into ~{linenomath}~,
2636 % instead of ~{displaymath}~. Also save the definition
2637 % of ~\equation~, instead of replicating the current
2638 % \LaTeX\ definition. (/New 3.08)
2640 %%\ifx\do@mlineno\@empty
2641 \@ifundefined{mathindent}{
2643 %% \AtBeginDocument{%
2644 \let\LN@displaymath\[%
2645 \let\LN@enddisplaymath\]%
2646 \renewcommand\[{\begin{linenomath}\LN@displaymath}%
2647 \renewcommand\]{\LN@enddisplaymath\end{linenomath}}%
2649 \let\LN@equation\equation
2650 \let\LN@endequation\endequation
2651 \renewenvironment{equation}%
2652 {\linenomath\LN@equation}%
2653 {\LN@endequation\endlinenomath}%
2656 }{}% \@ifundefined{mathindent} -- 3rd arg v4.2, was \par!
2658 %%\AtBeginDocument{%
2659 \let\LN@eqnarray\eqnarray
2660 \let\LN@endeqnarray\endeqnarray
2661 \renewenvironment{eqnarray}%
2662 {\linenomath\LN@eqnarray}%
2663 {\LN@endeqnarray\endlinenomath}%
2668 % (UL) Indeed. The \LaTeX\ macros are saved for
2669 % unnumbered mode, which is detected by ~\linenomath~.
2673 % Line numbers in internal vertical mode
2674 % \unskip}\label{ss:ILN}
2676 % The command ~\internallinenumbers~ adds line numbers in
2677 % internal vertical mode, but with limitations: we assume
2678 % fixed baseline skip.
2680 % (v4.22) v3.10 provided a global (~\global\advance~)
2681 % as well as a local version (star-form, using
2682 % ~\c@internallinenumber~). ~\resetlinenumbers~ acted
2683 % locally and was here used with the global version---save
2684 % stack danger, \TeX book p._301---in v4.00 I
2685 % disabled the global version therefore. Now I find that
2686 % it is better to keep a global version, and the now global
2687 % ~\resetlinenumbers~ is perfect for this. The global version
2688 % allows continuing the ``internal'' numbers in the ensuing
2689 % ``external'' text, and---unless reset by brackets
2690 % argument---continuing the above series of line numbers.
2691 % As with v3.10, the local version always starts with
2692 % line number one. A new ~\@LN@iglobal~ steps ~\global~ly
2693 % in the global version, otherwise it is ~\relax~.
2694 % (I also remove all my stupid discussions as of v4.00.
2695 % And I use ~\newcommand~.) (v4.22)
2697 \let\@LN@iglobal\global % v4.22
2699 \newcommand\internallinenumbers{\setrunninglinenumbers
2700 \let\@@par\internallinenumberpar
2701 \ifx\@par\@@@par\let\@par\internallinenumberpar\fi
2702 \ifx\par\@@@par\let\par\internallinenumberpar\fi
2703 \ifx\@par\linenumberpar\let\@par\internallinenumberpar\fi
2704 \ifx\par\linenumberpar\let\par\internallinenumberpar\fi
2705 \@ifnextchar[{\resetlinenumber}%]
2706 {\@ifstar{\let\c@linenumber\c@internallinenumber
2707 \let\@LN@iglobal\relax % v4.22
2708 \c@linenumber\@ne}{}}%
2711 \let\endinternallinenumbers\endlinenumbers
2712 \@namedef{internallinenumbers*}{\internallinenumbers*}
2713 \expandafter\let\csname endinternallinenumbers*\endcsname\endlinenumbers
2715 \newcount\c@internallinenumber
2716 \newcount\c@internallinenumbers
2718 \newcommand\internallinenumberpar{%
2719 \ifvmode\@@@par\else\ifinner\@@@par\else\@@@par
2721 \c@internallinenumbers\prevgraf
2722 \setbox\@tempboxa\hbox{\vbox{\makeinternalLinenumbers}}%
2723 \dp\@tempboxa\prevdepth
2725 \nobreak\vskip-\prevdepth
2726 \nointerlineskip\box\@tempboxa
2731 \newcommand\makeinternalLinenumbers{%
2732 \ifnum\c@internallinenumbers>\z@ % v4.2
2733 \hb@xt@\z@{\makeLineNumber}%
2734 \@LN@iglobal % v4.22
2735 \advance\c@linenumber\@ne
2736 \advance\c@internallinenumbers\m@ne
2737 \expandafter\makeinternalLinenumbers\fi
2739 % TODO v4.4+: star: line numbers right!? cf. lnocapt.sty
2743 % Line number references with offset
2746 % This extension defines macros to refer to line
2747 % numbers with an offset, e.g., to refer to a line
2748 % which cannot be labeled directly (display math).
2749 % This was formerly knows as ~rlineno.sty~.
2751 % To refer to a pagewise line number with offset:
2753 % ~\linerefp[~<OFFSET>~]{~<LABEL>~}~
2755 % To refer to a running line number with offset:
2757 % ~\linerefr[~<OFFSET>~]{~<LABEL>~}~
2759 % To refer to a line number labeled in the same mode as currently
2762 % ~\lineref[~<OFFSET>~]{~<LABEL>~}~
2765 \newcommand\lineref{%
2766 \ifx\c@linenumber\c@runninglinenumber
2767 \expandafter\linerefr
2769 \expandafter\linerefp
2773 \newcommand*\linerefp[2][\z@]{{%
2774 \let\@thelinenumber\thelinenumber
2775 \edef\thelinenumber{\advance\c@linenumber#1\relax
2776 \noexpand\@thelinenumber}%
2780 % This goes deep into \LaTeX's internals.
2782 \newcommand*\linerefr[2][\z@]{{%
2783 \def\@@linerefadd{\advance\c@linenumber#1}%
2784 \expandafter\@setref\csname r@#2\endcsname
2788 \newcommand*\@linerefadd[2]{\c@linenumber=#1\@@linerefadd\relax
2791 %% TODO v4.4+: Insert `LN' in internal command names?
2794 % Numbered quotation environments
2797 % The ~{numquote}~ and ~{numquotation}~
2798 % environments are like ~{quote}~ and
2799 % ~{quotation}~, except there will be line
2802 % An optional argument gives the number to count
2803 % from. A star ~*~ (inside or outside the closing
2804 % ~}~) prevent the reset of the line numbers.
2805 % Default is to count from one.
2807 % (v4.22: A local version using ~\c@internallinenumber~
2808 % might be useful, see subsection_\ref{ss:ILN}.) %% TODO v4.4+
2810 \newcommand\quotelinenumbers
2811 {\@ifstar\linenumbers{\@ifnextchar[\linenumbers{\linenumbers*}}}
2813 \newdimen\quotelinenumbersep
2814 \quotelinenumbersep=\linenumbersep
2815 \let\quotelinenumberfont\linenumberfont
2817 \newcommand\numquotelist
2819 \linenumbersep\quotelinenumbersep
2820 \let\linenumberfont\quotelinenumberfont
2821 \addtolength{\linenumbersep}{-\@totalleftmargin}%
2825 \newenvironment{numquote} {\quote\numquotelist}{\endquote}
2826 \newenvironment{numquotation} {\quotation\numquotelist}{\endquotation}
2827 \newenvironment{numquote*} {\quote\numquotelist*}{\endquote}
2828 \newenvironment{numquotation*}{\quotation\numquotelist*}{\endquotation}
2832 % Frame around a paragraph
2835 % The ~{bframe}~ environment draws a frame around
2836 % some text, across page breaks, if necessary.
2838 % This works only for plain text paragraphs,
2839 % without special height lines. All lines must be
2840 % ~\baselineskip~ apart, no display math.
2842 \newenvironment{bframe}
2844 \@tempdima\textwidth
2845 \advance\@tempdima 2\bframesep
2846 \setbox\bframebox\hb@xt@\textwidth{%
2848 \vrule\@width\bframerule\@height\baselineskip\@depth\bframesep
2849 \advance\@tempdima-2\bframerule
2851 \vrule\@width\bframerule\@height\baselineskip\@depth\bframesep
2854 \hbox{\hskip-\bframesep
2855 \vrule\@width\@tempdima\@height\bframerule\@depth\z@}%
2861 \def\makeLineNumber{\copy\bframebox\hss}%
2867 \@tempdima\textwidth
2868 \advance\@tempdima 2\bframesep
2869 \hbox{\hskip-\bframesep
2870 \vrule\@width\@tempdima\@height\bframerule\@depth\z@}%
2873 \newdimen\bframerule
2874 \bframerule=\fboxrule
2884 % Move \scs{vadjust} items (New v4.00)
2885 % \unskip}\label{s:MVadj}
2887 % This section completes reviving ~\pagebreak~, ~\nopagebreak~,
2888 % ~\vspace~, and the star and optional form of ~\\~. This was
2889 % started in section_\ref{ss:output} and resumed in
2890 % section_\ref{ss:MLN} and subsection_\ref{ss:calls}.
2891 % The problem was explained in section_\ref{ss:output}:
2892 % ~\vadjust~ items come out at a bad position, and the
2893 % \LaTeX\ commands named before work with ~\vadjust~ indeed.
2894 % Our solution was sketched there as well.
2896 % According to the caveat in subsection_\ref{ss:OnOff} concerning
2897 % ~\ifLineNumbers~, the \LaTeX\ commands enumerated may go
2898 % wrong if you switch line numbering inside or at the end of
2903 % Redefining \scs{vadjust}
2904 % \unskip}\label{ss:PVadj}
2906 % ~\vadjust~ will temporarily be changed into the following
2909 \def\PostponeVadjust#1{%
2910 \global\let\vadjust\@LN@@vadjust
2912 % This undoes a ~\global\let\vadjust\PostponeVadjust~ which will
2913 % start each of the refined \LaTeX\ commands. The ~\global~s
2914 % are most probably superfluous. They might be useful should one
2915 % ~\vadjust~ appear in a group starting after the change of
2916 % ~\vadjust~ into ~\PostponeVadjust~.
2917 % (UL) Even the undoing may be superfluous, cf._discussion
2918 % in section_\ref{ss:ReDef} below. (UL)
2920 \vadjust{\penalty-\@Mppvacodepen}%
2921 \g@addto@macro\@LN@vadjustlist{#1\@lt}%
2923 \let\@LN@@vadjust\vadjust
2924 \global\let\@LN@vadjustlist\@empty
2925 \global\let\@LN@do@vadjusts\relax
2927 % These ~\global~s are just to remind that
2928 % all the changes of the strings after ~\let~ should be
2929 % ~\global~ (\TeX book p._301). ~\@LN@vadjustlist~ collects
2930 % the ~\vadjust~ items of a paragraph. ~\PassVadjustList~
2931 % tears one ~\vadjust~ item for the current line out of
2932 % ~\@LN@vadjustlist~ and puts it into ~\@LN@do@vadjusts~.
2933 % The latter is encountered each line in ~\MakeLineNo~
2934 % (section_\ref{ss:MLN}), while those \LaTeX\ ~\vadjust~
2935 % commands will come rather rarely. So I decided that
2936 % ~\@LN@do@vadjust~ is ~\relax~ until a ~\vadjust~ item
2937 % is waiting. In the latter case, ~\@LN@do@vadjusts~
2938 % is turned into a list macro which resets itself to
2939 % ~\relax~ when the other contents have been placed in
2940 % the vertical list.---~\PassVadjustList~ is invoked by
2941 % the output routine (section_\ref{ss:output}), so the
2942 % ~\box255~ must be put back.
2944 \def\PassVadjustList{%
2946 \expandafter \@LN@xnext \@LN@vadjustlist \@@
2947 \@tempa \@LN@vadjustlist
2948 \ifx\@LN@do@vadjusts\relax
2949 \gdef\@LN@do@vadjusts{\global\let\@LN@do@vadjusts\relax}%
2951 \expandafter \g@addto@macro \expandafter \@LN@do@vadjusts
2952 \expandafter {\@tempa}%
2957 % Redefining the \LaTeX\ commands
2958 % \unskip}\label{ss:ReDef}
2960 % Now we change ~\pagebreak~ etc.\
2961 % so that they use ~\PostponeVadjust~ in place of ~\vadjust~.
2962 % We try to do this as independently as possible of the
2963 % implementation of the \LaTeX\ commands to be redefined.
2964 % Therefore, we don't just copy macro definition code from any
2965 % single implementation (say, latest \LaTeX) and insert our
2966 % changes, but attach a conditional
2967 % ~\global\let\vadjust\PostponeVadjust~
2968 % to their left ends in a way which should work rather
2969 % independantly of their actual code.
2970 % However, ~\vadjust~ should be the primitive again after
2971 % execution of the command. So the ~\global\let...~ may be used
2972 % only if it's guaranteed that a ~\vadjust~ is near.---(UL)
2973 % Sure? In line numbering mode, probably each ~\vadjust~
2974 % coming from a \LaTeX\ command should be ~\PostponeVadjust~.
2975 % ~\marginpar~s and floats seem to be the only cases which
2976 % are not explicitly dealt with in the present section.
2977 % This would be a way to avoid ~\@LN@nobreaktrue~!
2978 % Of course, the ~\vadjust~s that the present package uses
2979 % then must be replaced by ~\@LN@@vadjust~.---Maybe
2983 % The next command and something else will be added to the
2984 % \LaTeX\ commands we are concerned with here.
2986 \DeclareRobustCommand\@LN@changevadjust{%
2987 \ifvmode\else\ifinner\else
2988 \global\let\vadjust\PostponeVadjust
2992 % (UL) What about math mode? Math display? Warn? (/UL)
2995 % ~\@tempa~ will now become a two place macro which adds first
2996 % argument (single token), enclosed by ~\ifLineNumbers~\,\dots
2997 % ~\fi~ to the left of second argument. As long as we need it,
2998 % we can't use the star form of ~\DeclareRobustCommand~ or
2999 % the like, because AMS-\LaTeX\ uses ~\@tempa~ for ~\@ifstar~.
3000 % (New v4.41) And for the same reason, that ~\CheckCommand*~
3001 % had to be raised! (/New v4.41)
3003 \CheckCommand*\@parboxrestore{\@arrayparboxrestore\let\\\@normalcr}
3006 \expandafter \def \expandafter#2\expandafter{\expandafter
3007 \ifLineNumbers\expandafter#1\expandafter\fi#2}%
3010 % (UL) This ~\ifLineNumber~ can be fooled by
3011 % ~\linenumbers~ ahead etc. It might be better to place
3012 % a signal penalty in any case and let the output routine
3013 % decide what to do.
3015 %% And when this has been done, remove warnings about this.
3018 % We use the occasion to switch off linenumbers where they
3019 % don't work anyway and where we don't want them,
3020 % especially in footnotes:
3022 \@tempa\nolinenumbers\@arrayparboxrestore
3024 % We hope this suffices $\dots$ let's check one thing
3025 % at least: [(New v4.41) see ~\CheckCommand~ above (/New v4.41)]
3027 % Now for the main theme of the section.
3028 % The next lines assume that ~\vspace~, ~\pagebreak~, and
3029 % ~\nopagebreak~ use ~\vadjust~ whenever they occur outside
3030 % vertical mode; moreover, that they don't directly read
3031 % an argument. Indeed ~\pagebreak~ and ~\nopagebreak~ first
3032 % call something which tests for a left bracket ahead,
3033 % while ~\vspace~ first tests for a star.
3035 \@tempa\@LN@changevadjust\vspace
3036 \@tempa\@LN@changevadjust\pagebreak
3037 \@tempa\@LN@changevadjust\nopagebreak
3039 % ~\\~, however, uses ~\vadjust~ only in star or optional form.
3040 % We relax independency of implementation in assuming
3041 % that ~\@normalcr~ is the fragile version of ~\\~
3042 % (and we use ~\@ifstar~!).
3044 %% \@ifstar reimplemented 1995/10/16, but seems to be much older.
3047 %% \@ifnextchar*{\@LN@changevadjust\@normalcr}%
3048 %% {\@ifnextchar[{\@LN@changevadjust\@normalcr}\@normalcr}%
3050 %% ---same number of tokens, expansion step less.
3052 % (Using a copy of ~\\~ would be safer, but an ugly repetition
3056 \DeclareRobustCommand\\{%
3058 \expandafter \@LN@cr
3060 \expandafter \@normalcr
3064 \@ifstar{\@LN@changevadjust\@normalcr*}%
3065 {\@ifnextchar[{\@LN@changevadjust\@normalcr}\@normalcr}%
3068 % Moreover we hope that ~\newline~ never leads to a ~\vadjust~,
3069 % although names of some commands invoked by ~\\~ contain
3070 % ~newline~. At last, this seems to have been OK since 1989 or
3073 % \modulolinenumbers[1]
3074 % \firstlinenumber{0}
3075 % Let's have a few tests.\vspace*{.5\baselineskip}
3076 % Testing ~\pagebreak~ and ~\nopagebreak~ would be too expensive
3077 % here, but---oops!---we have just experienced a successful
3078 % ~\vspace*{.5\baselineskip}~. A
3079 % ~\\*[.5\baselineskip]~\\*[.5\baselineskip] may look even more
3080 % drastical, but this time we are happy about it. Note that the
3081 % line numbers have moved with the lines. Without our changes,
3082 % one line number\vadjust{\kern.5\baselineskip} would have
3083 % ``anticipated'' the move of the next line, just as you can
3087 % \switchlinenumbers
3090 % Reminder on obsoleteness
3093 % (New v4.1) We have completed inclusion of the earlier
3094 % extension packages ~linenox0.sty~, ~linenox1.sty~, and
3095 % ~lnopatch.sty~. If one of them is loaded, though,
3096 % we produce an error message before something weird happens.
3097 % We avoid ~\newif~ because the switchings occur so rarely.
3100 \let\if@LN@obsolete\iffalse
3101 \@ifpackageloaded{linenox0}{\let\if@LN@obsolete\iftrue}\relax
3102 \@ifpackageloaded{linenox1}{\let\if@LN@obsolete\iftrue}\relax
3103 \@ifpackageloaded{lnopatch}{\let\if@LN@obsolete\iftrue}\relax
3105 \PackageError{lineno}{Obsolete extension package(s)}{%
3106 With lineno.sty version 4.00 or later,\MessageBreak
3107 linenox0/linenox1/lnopatch.sty must no longer be loaded.}%
3112 % \modulolinenumbers[1]
3117 % There is one deadcycle for each line number.
3119 \advance\maxdeadcycles 100
3126 % \unskip}\label{s:UserCmds}
3128 % The user commands to turn on and off line numbering
3130 % \begin{description}\item
3131 % [|\linenumbers] \ \par
3132 % Turn on line numbering in the current mode.
3135 % [|\linenumbers*] \ \par$\qquad$
3136 % and reset the line number to 1.
3137 % \def\NL{<number>]}\item
3138 %% %% Boldface italic occurs here, which is evil. (UL)
3139 % [|\linenumbers[\NL] \ \par$\qquad$
3140 % and start with <number>.
3142 % [|\nolinenumbers] \ \par
3143 % Turn off line numbering.
3145 % [|\runninglinenumbers*[\NL] \ \par
3146 % Turn on ~running~ line numbers, with the same optional
3147 % arguments as ~\linenumbers~. The numbers are running
3148 % through the text over pagebreaks. When you turn
3149 % numbering off and on again, the numbers will continue,
3150 % except, of cause, if you ask to reset or preset the
3153 % [|\pagewiselinenumbers] \ \par
3154 % Turn on ~pagewise~ line numbers. The lines on each
3155 % page are numbered beginning with one at the first
3156 % ~pagewise~ numbered line.
3158 % [|\resetlinenumber[\NL] \ \par
3159 % Reset ~[~Set~]~ the line number to 1
3162 % [|\setrunninglinenumbers] \ \par
3163 % Switch to ~running~ line number mode. Do \emph{not}
3164 % turn it on or off.
3166 % [|\setpagewiselinenumbers] \ \par
3167 % Switch to ~pagewise~ line number mode. Do \emph{not}
3168 % turn it on or off.
3170 % [|\switchlinenumbers*] \ \par
3171 % Causes margin switching in pagewise modes. With the
3172 % star, put the line numbers on the inner margin.
3174 % [|\leftlinenumbers*] \ \par
3176 % [|\rightlinenumbers*] \ \par
3177 % Set the line numbers in the left/right margin. With the
3178 % star this works for both modes of operation, without
3179 % the star only for the currently selected mode.
3181 % [|\runningpagewiselinenumbers] \ \par
3182 % When using the pagewise line number mode, do not
3183 % subtract the page offset. This results in running
3184 % line numbers again, but with the possibility to switch
3185 % margins. Be careful when doing line number
3186 % referencing, this mode status must be the same while
3187 % setting the paragraph and during references.
3189 % [|\realpagewiselinenumbers] \ \par
3190 % Reverses the effect of ~\runningpagewiselinenumbers~.
3192 % [|\modulolinenumbers[\NL] \ \par
3193 % Give a number only to lines which are multiples of
3194 % ~[~<number>~]~. If <number> is not specified, the
3195 % current value in the counter ~linenumbermodulo~ is
3196 % retained. <number>=1 turns this off without changing
3197 % ~linenumbermodulo~. The counter is initialized to 5.
3199 %% %% TODO v4.4+: `counter', he says. Cf._above.
3203 % [|\modulolinenumbers*[\NL] \ \par
3204 % Like ~\modulolinenumbers~, the only difference being
3205 % that the first line number after a ~\linenumbers~
3206 % (or ~\runninglinenumbers~, ~\pagewiselinenumbers~,
3207 % ~\quotelinenumbers~) is printed regardless of the
3208 % modulo---yet `1' is printed only after (or \dots)
3209 % ~\firstlinenumber{1}~.
3210 % This also applies to the first line of a
3211 % ~{linenumbers}~ or respective environment.
3212 % See subsection_\ref{ss:Mod} for another explanation.
3213 % The behaviour may be unsatisfactory with pagewise
3218 % [|\firstlinenumber] \ \par
3219 % ~\firstlinenumber{~<filino>~}~ brings about that
3220 % (after it) line numbers less than <filino> do
3221 % \emph{not} appear in the margin. Moreover, with
3222 % ~\modulolinenumbers[~<number>~]~, just the line
3223 % numbers which are <filino> plus a multiple of
3224 % <number> are printed.---If you had
3225 % ~\firstlinenumber{~<pos>~}~ with some $\mbox{<pos>}>0$
3226 % and want to switch to printing multiples of, e.g.,
3227 % 4, you best do ~\modulolinenumbers[4]~ and
3228 % ~\firstlinenumber{0}~. (See subsection_\ref{ss:Mod}
3229 % for technical details.)
3232 % [|\linenumberdisplaymath] \ \par
3233 % Number the lines of a display math in a ~{linenomath}~
3234 % environment, but do not in a ~{linenomath*}~
3235 % environment. This is used by the package option
3238 % [|\nolinenumberdisplaymath] \ \par
3239 % Do not Number the lines of a display math in a
3240 % ~{linenomath}~ environment, but do in a
3241 % ~{linenomath*}~ environment. This is the default.
3243 % [|\linelabel] \ \par
3244 % Set a ~\linelabel{~<foo>~}~ to the line number where
3245 % this commands is in. Refer to it with the \LaTeX\
3246 % referencing commands ~\ref{~<foo>~}~ and
3247 % ~\pageref{~<foo>~}~.
3249 % The commands can be used globally, locally within groups
3250 % or as environments. It is important to know that they
3252 %% %% TODO: \linelabel? others?
3254 % take action only when the ~\par~ is executed. The
3256 %% %% TODO: sure? ~\modulo...~, e.g.? well, in a sense ...
3258 % ~\end{~<mode>~linenumbers}~ commands provide a ~\par~.
3261 % ~{\linenumbers~ <text> ~\par}~ \\
3263 % ~\begin{linenumbers}~ \\
3265 % ~\end{linenumbers}~ \\
3267 % <paragraph> ~{\linenumbers\par}~ \\
3271 % ~\nolinenumbers~ \\
3274 % <paragraph> ~{\nolinenumbers\par}~ \\
3277 % However, the examples containing <paragraph> show what you
3278 % should \emph{not} do, at least if you use ~\pagebreak~,
3279 % ~\nopagebreak~, ~\vspace~, ~\\*~ or
3280 % ~\\[~<space>~]~---cf._section_\ref{s:MVadj}.
3282 % The same care should be applied to the ``wizard'' devices
3283 % ~\ifLineNumbers~ (subsection_\ref{ss:OnOff}) and
3284 % ~\PostponeVadjust~ (section_\ref{ss:PVadj}).
3287 % (New v4.11) Oh, and the commands and environments of
3288 % section_{s:Xt} are missing. Sorry, I am in a hurry now.
3289 % May be next time.% %% TODO v4.4+
3290 % ---And the environments ~{linenomath}~ and ~{linenomath*}~should
3291 % get an own paragraph. In short, each math display, equation,
3292 % or ~{eqnarray}~ should be ``wrapped'' in one of ~{linenomath}~
3293 % and ~{linenomath*}~.
3296 % Customization hooks
3299 % There are several hooks to customize the appearance of the
3300 % line numbers, and some low level hooks for special
3302 % \begin{description}\item
3303 % [|\thelinenumber] \ \par
3304 % This macro should give the representation of the line
3305 % number in the \LaTeX-counter ~linenumber~. The
3306 % default is provided by \LaTeX: \par$\qquad$
3307 % ~\arabic{linenumber}~
3309 % [|\makeLineNumberLeft] \ \par
3310 % This macro is used to attach a line number to the left
3311 % of the text page. This macro should fill an ~\hbox to 0pt~
3312 % which will be placed at the left margin of the
3313 % page, with the reference point aligned to the line to
3314 % which it should give a number. Please use the macro
3315 % ~\LineNumber~ to refer to the line number.
3317 % The default definition is \par$\qquad$
3318 % ~\hss\linenumberfont\LineNumber\hskip\linenumbersep~
3320 % [|\makeLineNumberRight] \ \par
3321 % Like ~\makeLineNumberLeft~, but for line numbers on
3324 % The default definition is \par$\qquad$
3325 % ~\linenumberfont\hskip\linenumbersep\hskip\textwidth~ \par$\qquad$
3326 % ~\hbox to\linenumberwidth{\hss\LineNumber}\hss~
3328 % [|\linenumberfont] \ \par
3329 % This macro is initialized to \par$\qquad$
3330 % ~\normalfont\tiny\sffamily~
3332 % [|\linenumbersep] \ \par
3333 % This dimension register sets the separation of the
3334 % linenumber to the text. Default value is ~10pt~.
3336 % [|\linenumberwidth] \ \par
3337 % This dimension register sets the width of the line
3338 % number box on the right margin. The distance of the
3339 % right edge of the text to the right edge of the line
3340 % number is ~\linenumbersep~ + ~\linenumberwidth~. The
3341 % default value is ~10pt~.
3343 % [|\theLineNumber] (for wizards) \ \par
3344 % This macro is called for printing a ~\newlabel~ entry
3345 % to the aux-file. Its definition depends on the mode.
3346 % For running line numbers it's just ~\thelinenumber~,
3347 % while in pagewise mode, the page offset subtraction
3350 % [|\makeLineNumber] (for wizards) \ \par
3351 % This macro produces the line numbers. The definition
3352 % depends on the mode. In the running line numbers
3353 % mode it just expands ~\makeLineNumberLeft~.
3355 % [|\LineNumber] (for wizards) \ \par
3356 % This macro is called by ~\makeLineNumber~ to typeset
3357 % the line number. This hook is changed by the modulo
3360 % and by ~\firstlinenumber~.
3364 %% TODO: \stepLineNumber---another wizard command!?
3365 %% Not sure, may be retreated.
3367 ------------------------------------------------------------------------------
3369 %% TODO v4.4+: Check for unwanted comment marks in new comments
3370 %% (resulting from manual aligning): search `New v4.2'
3372 %% TODO v4.4+: Check for missing comment marks where a paragraph
3373 %% should end/start. Also to prevent empty "code" lines.
3374 %% Especially, new comments at section ends must be
3375 %% followed by comment mark lines.
3376 %% And prevent ~\par~s from blank lines in definitions!
3377 %% See `visual space' above.
3378 %% For proper appearance in lineno.tex, note that a comment
3379 %% in a final code line changes behaviour.
3380 %% TODO v4.4+: Require README for redistribution?
3381 %% TODO v4.4+: Since discussions of code have increased so much, it
3382 %% would be appropriate not to give to this file
3383 %% extension `.sty' (e.g., `dty'!??). ?? Is quickly read though!
3384 %% A .sty extraction may be possible even if the present
3385 %% file is neither a .doc nor a .dtx. (!???)
3386 %% Use awk line below (etc.) for .doc at least; + .ins or so.
3387 %% ^ must not be caps! To escape awk.
3388 %% TODO v4.4+: Underfull lines!? (due to long code quotations)
3389 %% TODO v4.4+: Sometimes paragraph indents may be appropriate.
3390 %% TODO Swap first line (`\iffalse...') with corresponding below.
3391 Or do *not* swap, maybe nawk is more reliable.
3392 %% TODO v4.4+: Ponder Stephan's mail from 2004/09/02.
3394 %% use \@ET@makeLineNumber.
3395 %% plus almost all `(UL)'
3396 %% plus lots of bad boxes messages
3397 %% change v4.3 TODOs when postponed
3398 %% remove {old} environments.
3400 ------------------------------------------------------------------------------
3402 # awk command lines for v4.00, mixed with former ones:
3404 echo "Don't bother about unknown 'iffalse'." # SHELL1
3405 nawk '/A[W]K/' lineno.sty | nawk -f - lineno.sty >lineno.tex; # SHELL1
3406 latex lineno; latex lineno; latex lineno; latex lineno; # SHELL1
3408 BEGIN{DOC=-1; # AWK DOC A W K
3409 BEGINCODE = "\\begin{code}\\begin{verbatim}"; # AWK
3410 ENDCODE = "\\end{verbatim}\n\\end{code}"; } # AWK
3411 BEGINCODE = "% \\begin{macrocode}"; # DOC A W K
3412 ENDCODE = "% \\end{macrocode}"; } # DOC A W K
3413 /^[ \t]*$/ { ECNT++; next; } # AWK DOC A W K
3414 /\\documentclass/{ sub("article","ltxdoc") } # DOC A W K
3415 /%D$/ { sub("^%* *",""); sub("%D$",""); # DOC A W K
3416 print > "lineno.drv"; next } # DOC A W K
3417 /^%%/ { next; } # AWK DOC A W K
3418 /^%/ { if (!DOC) { print ENDCODE; } # AWK DOC A W K
3419 DOC=1; ECNT=0; # AWK DOC A W K
3420 sub("^% *",""); # AWK
3421 sub("^% *","% "); # DOC A W K
3422 print; next; } # AWK DOC A W K
3423 /%VERSION/ { sub("%VERSION",""); print; next; } # AWK
3424 /%SSTOPP/ { exit } # AWK
3425 DOC<0 { next } # AWK DOC A W K
3426 /^-+-$/ { if (!DOC) print ENDCODE; exit } # AWK DOC A W K
3427 { if (DOC) { ECNT=DOC=0; print BEGINCODE; } # AWK DOC A W K
3428 while (ECNT>0) { print " "; ECNT--; } # AWK DOC A W K
3429 print $0; } # AWK DOC A W K
3431 # New v4.00, UL: know nothing about awk; found present solution
3432 # in hours of trial and error.
3434 % Earlier (should be inhibited by %SSTOPP above and otherwise):
3435 echo "expect errors for unknown commands 'iffalse' and 'fi'";# SHELL0 SHELL#1
3436 awk '/A[W]K/' lineno.sty | awk -f - lineno.sty >lineno.tex; # SHELL0
3437 latex lineno; latex lineno; latex lineno; latex lineno; # SHELL0
3438 nawk '/A[W]K/' lineno4.sty | nawk -f - lineno4.sty >lineno4.tex; # SHELL#1
3439 latex lineno4; latex lineno4; latex lineno4; latex lineno4; # SHELL#1
3441 awk '/DOC A [W] K/' lineno.sty | awk -f - lineno.sty >lineno.doc; # DOC SH
3443 BEGIN{DOC=-1; # A#WK DOC A W K
3444 BEGINCODE = "\\begin{code}\\begin{verbatim}"; # A#WK
3445 ENDCODE = "\\end{verbatim}\n\\end{code}"; } # A#WK
3446 BEGINCODE = "% \\begin{macrocode}"; # DOC A W K
3447 ENDCODE = "% \\end{macrocode}"; } # DOC A W K
3448 /^[ \t]*$/ { ECNT++; next; } # A#WK DOC A W K
3449 /\\documentclass/{ sub("article","ltxdoc") } # DOC A W K
3450 /%D$/ { sub("^%* *",""); sub("%D$",""); # DOC A W K
3451 print > "lineno.drv"; next } # DOC A W K
3452 /^%%/ { next; } # A#WK DOC A W K
3453 /^%/ { if (!DOC) { print ENDCODE; } # A#WK DOC A W K
3454 DOC=1; ECNT=0; # A#WK DOC A W K
3455 sub("^% *",""); # A#WK
3456 sub("^% *","% "); # DOC A W K
3457 print; next; } # A#WK DOC A W K
3458 DOC<0 { next } # A#WK DOC A W K
3459 /^-+-$/ { if (!DOC) print ENDCODE; exit } # A#WK DOC A W K
3460 { if (DOC) { ECNT=DOC=0; print BEGINCODE; } # A#WK DOC A W K
3461 while (ECNT>0) { print " "; ECNT--; } # A#WK DOC A W K
3462 print $0; } # A#WK DOC A W K
3465 ------------------------------------------------------------------------------
3467 If you are looking here because of the two top lines of the file:
3469 A .tex documentation of this macro file can be obtained by
3473 under UNIX.--You may find this hint little helpful. One
3474 reason may be that the awk versions to which you have access
3475 don't work suitably. Another reason may be that you don't have
3476 access to UNIX (in some sense). However, a .tex, .dvi, or .pdf
3477 version of such a documentation should be available from CTAN,
3478 in the same folder as the present file. When we typed this, that
3479 folder was /macros/latex/contrib/lineno. If this has changed in
3480 the meantime, a CTAN search should lead you to a folder
3481 containing such a documentation. Or you may get help from one of
3482 the e-mail addresses above.