Annotation of ttbar/p20_taujets_note/lineno.tex, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>