forked from quantixed/CoB-LaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineno.sty
3484 lines (3241 loc) · 148 KB
/
lineno.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\iffalse; awk '/S[H]ELL1/' lineno.sty|sh;exit;
... see bottom for .tex documentation ...
Macro file lineno.sty for LaTeX: attach line numbers, refer to them.
\fi
\def\fileversion{v4.41} \def\filedate{2005/11/02} %VERSION
%%% Copyright 1995--2003 Stephan I. B"ottcher <boettcher@physik.uni-kiel.de>;
%%% Copyright 2002--2005 Uwe L"uck, http://www.contact-ednotes.sty.de.vu
%%% for version 4 and code from former Ednotes bundle
%%% --author-maintained.
%%%
%%% This file can be redistributed and/or modified under
%%% the terms of the LaTeX Project Public License; either
%%% version 1.3a of the License, or any later version.
%%% The latest version of this license is in
%%% http://www.latex-project.org/lppl.txt
%%% We did our best to help you, but there is NO WARRANTY.
%
%%% $Id: lineno.sty,v 3.14.2.2 2004/09/13 19:30:39 stephan Exp $ %% was v4.00.
% \title{\texttt{\itshape
%% %% (UL 2004/10/09:) Italic TT is evil
%% %% ... or nice front page layout!?
%%
% lineno.sty \ \fileversion\ \filedate
% \unskip}\\\ \\
% A \LaTeX\ package to attach
% \\ line numbers to paragraphs
% \unskip}\author{%
% Stephan I. B\"ottcher
% \\ Uwe L\"uck
% \unskip}\date{%
% boettcher@physik.uni-kiel.de
% \\ http://contact-ednotes.sty.de.vu
%% \\ stephan@nevis.columbia.edu
%% \\ Stephan.Boettcher@cern.ch
% \\}
%
% \documentclass[a4paper,12pt]{article}%D
% \usepackage{lineno}%D
%% %% (New v4.00)
% \catcode`\_\active\let_~
%% %% Beware math!? (/New v4.00)
% \def~{\verb~}
% \let\lessthan<
% \catcode`\<\active
% \def<#1>{$\langle${\itshape#1}\/$\rangle$}
% \catcode`\|\active
%% (New v4.1: \tt star; in box anyway.)
% \def|#1{\ttfamily\string#1}
%% \def|#1{{\ttfamily\string#1}}
%% (/New v4.1)
% \newenvironment{code}
% {\par\runninglinenumbers
% \modulolinenumbers[1]%
% \linenumbersep.3em
% \footnotesize
% \def\linenumberfont
% {\normalfont\tiny\itshape}}
% {}
%% %% (New v4.00)
% {\makeatletter \gdef\scs#1{\texttt
% {\protect\@backslashchar#1}}}
% \def\old{\par\footnotesize}
%% %% (/New v4.00)
%% %% (New v4.1)
% {\catcode`\/\active
% \gdef\path{\begingroup\catcode`\/\active
% \let/\slash\dopath}
% \gdef\dopath#1{\slash\unpenalty#1\endgroup}}
%% %% (/New v4.1)
%
% \begin{document}%D
%% \DocInput{lineno}%D
% \pagewiselinenumbers
% \maketitle
% \pagestyle{headings}
% \tableofcontents
% \sloppy
%
%% %% New v4.00: `...section{%' + \unskip
% \section{%
% Introductions
%% %% New v4.00: `s'
% \unskip}
%
% (New v4.00) Parts of former first section
% have been rendered separate subsections for package
% version_v4.00. (/New v4.00)
%
% \subsection{%
% Introduction to versions $\textrm{v}\lessthan4$
% \unskip}
%
% This package provides line numbers on paragraphs.
% After \TeX\ has broken a paragraph into lines there will
% be line numbers attached to them, with the possibility to
% make references through the \LaTeX\ ~\ref~, ~\pageref~
% cross reference mechanism. This includes four issues:
% \begin{itemize}
% \item attach a line number on each line,
% \item create references to a line number,
% \item control line numbering mode,
% \item count the lines and print the numbers.
% \end{itemize}
% The first two points are implemented through patches to
% the output routine. The third by redefining ~\par~, ~\@par~
% and ~\@@par~. The counting is easy, as long as you want
% the line numbers run through the text. If they shall
% start over at the top of each page, the aux-file as well
% as \TeX s memory have to carry a load for each counted line.
%
% I wrote this package for my wife Petra, who needs it for
% transcriptions of interviews. This allows her to
% precisely refer to passages in the text. It works well
% together with ~\marginpar~s, but not too well with displaymath.
% ~\footnote~s are a problem, especially when they
% are split, but we may get there.
% (New v4.00 UL) Version v4.00 overcomes the problem, I believe.
% (/UL /New v4.00)
%
% lineno.sty works
% surprisingly well with other packages, for
% example, ~wrapfig.sty~. So please try if it
% works with whatever you need, and if it does,
% please tell me, and if it does not, tell me as
% well, so I can try to fix it.
%
% \subsection{%
% Introduction to versions v4.00ff. (UL)
% \unskip}
%
% ~lineno.sty~ has been maintained by Stephan until version_v3.14.
% From version_v4.00 onwards, maintenance is shifting towards
% Uwe L\"uck (UL), who is the author of v4\dots code and of v4\dots
% changes in documentation. This came about as follows.
%
% Since late 2002, Christian Tapp and Uwe L\"uck have employed
% ~lineno.sty~ for their ~ednotes.sty~, a package supporting
% critical editions---cf.
% \[\mbox{\tt
% http://ednotes.sty.de.vu
% \unskip}\]
% ---while you find ~ednotes.sty~ and surrounding files in
% CTAN folder \path{macros/latex/contrib/ednotes}.
%
% Soon, some weaknesses of ~lineno.sty~ showed up, mainly since
% Christian's critical editions (using ~ednotes.sty~) needed lots
% of ~\linelabel~s and footnotes. (These weaknesses are due to
% weaknesses of \LaTeX's ~\marginpar~ mechanism that Stephan
% used for ~\linelabel~.) So we changed some ~lineno.sty~
% definitions in some extra files, which moreover offered new
% features. We sent these files to Stephan, hoping he would take
% the changes into ~lineno.sty~. However, he was too short of time.
%
% Writing a TUGboat article on Ednotes in 2004, we hoped to
% reduce the number of files in the Ednotes bundle and so asked
% Stephan again. Now he generously offered maintenance to me, so
% I could execute the changes on my own.
%
% The improvements are as follows:
% \begin{itemize}\item
% [(i)] Footnotes placement approaches intentions better
% (footnotes formerly liked to pile up at late pages).
% \item
% [(ii)] The number of ~\linelabel~s in one paragraph is no longer
% limited to 18.
% \item
% [(iii)] ~\pagebreak~, ~\nopagebreak~, ~\vspace~, and the star
% and optional versions of ~\\~ work as one would expect
% (section_\ref{s:MVadj}). %% Added for v4.1
% \item
% [(iv)] A command is offered which chooses the first line number
% to be printed in the margin
% (subsection_\ref{ss:Mod}). %% Added for v4.1
% \item
% [(v)] (New v4.1) \LaTeX\ tabular environments (optionally)
% get line numbers as well, and you can refer to them in the
% usual automatic way. (It may be considered a shortcoming that,
% precisely, \emph{rows} are numbered, not lines.---See
% subsection_\ref{ss:Tab}.)
% \item
% [(vi)] We are moving towards referring to math items
% (subsection_\ref{ss:MathRef} and the hooks in
% subsection_\ref{ss:LL}).
% (/New v4.1)
% \end{itemize}
% (Thanks to Stephan for making this possible!)
%
%% Unpublish:
%% You may trace the earlier developments of these changes by
%% requesting our files ~linenox0.sty~, ~linenox1.sty~, and
%% ~lnopatch.sty~. Most of our changes have been in ~linenox0.sty~.
%% Our ~linenox1.sty~ has extended ~linenox0.sty~ for one single
%% purpose in a not very stable way.
%%% (See ~\linenumberpar~ below).
%% ~lnopatch.sty~ has done the first line number thing referred
%% to in case_(iv) up to now.
%% (New v4.1)
%% Case_(v) earlier was provided by our ~edtab02.sty~---now
%% called ~edtable.sty~.
%% (/New v4.1)
%
% Ednotes moreover profits from Stephan's offer with regard
% to the documentation of our code which yielded these
% improvements formerly. This documentation now becomes
% printable, being part of the ~lineno.sty~ documentation.
%
% Of course, Stephan's previous ~lineno.sty~ versions were a great
% and ingenious work and exhibit greatest \TeX pertise. I never
% could have done this. I learnt a lot in studying the code when
% Christian pointed out strange output results and error
% messages, and there are still large portions of ~lineno.sty~
% which I don't understand (consider only pagewise numbering of
% lines). Fortunately, Stephan has offered future help if
% needed.---My code for attaching line numbers to \emph{tabular
% environments} (as mentioned above, now still in
% ~edtable.sty~) %% %% TODO
% developed from macros which Stephan and Christian experimented
% with in December 2002. Stephan built the basics.
% (However, I then became too proud to follow his advice only to
% use and modify ~longtable.sty~.)
%
% There are some issues concerning use of counters on which I
% don't agree with Stephan and where I would like to change the
% code if ~lineno.sty~ is ``mine'' as Stephan offered. However,
% Stephan is afraid of compatibility problems from which, in
% particular, his wife could suffer in the near future. So he
% demanded that I change as little as possible for my first
% version. Instead of executing changes that I plan I just offer
% my opinions at the single occasions. I hope to get in touch
% this way with users who consider subtle features vital which I
% consider strange.
%
% On the other hand, the sections on improvements of the
% implementation have been blown up very much and may be tiring
% and litte understandable for mere \emph{users}. These users
% may profit from the present presentation just by jumping to
% sections_\ref{s:Opts} and_\ref{s:UserCmds}. There is a user's
% guide ulineno.tex which may be even more helpful, but it has
% not been updated for a while. %% TODO
%
% \subsection{%
% Availability
% \unskip}
%
% In case you have found the present file otherwise than from
% CTAN: A recent version and documentation of this package
% should be available from CTAN folder
% \path{macros/latex/contrib/lineno}.
% Or mail to one of the addresses at top of file.
%
% \subsection{%
% Introductory code
% \unskip}
%
% This style option is written for \LaTeXe, November 1994 or later,
% since we need the ~\protected@write~ macro.
%
% (New v4.00) And we use ~\newcommand*~ for
% controlling length of user macro arguments, which has been
% available since December 1994.
%%
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
%% [1994/11/04]
\ProvidesPackage{lineno}
[\filedate\space line numbers on paragraphs \fileversion]
% (/New v4.00)
%%
%% History of versions:
%% v1.00 1995/03/31 SIB: first release for Petra's interview transcriptions
%% v1.01 1995/10/28 SIB: added ~pagewise~ mode
%% v1.02 1995/11/15 SIB: added ~modulo~ option
%% v1.03 1995/12/05 SIB: pagewise: try to reduce the hash-size requirements
%% v2.00 1995/12/06 SIB: .. it works, new user interface
%% v2.01 1996/09/17 SIB: put into CVS
%% v2.02 1997/03/17 SIB: add: \@reinserts, for footnotes
%% v2.04 1998/03/09 SIB: add: linenomath environment
%% v2.05 1998/04/26 SIB: add: prevgraf test
%% v2.06 1999/03/02 SIB: LPPL added
%% v3.00 1999/06/11 SiB: include the extension in the main file
%% v3.01 1999/08/28 SiB: \@reinserts -> \holdinginserts
%% v3.02 2000/03/10 SiB: \@LN@output
%% v3.03 2000/07/01 SiB: \@LN@ExtraLabelItems, hyperref
%% v3.04 2000/12/17 SiB: longtable compatibility.
%% v3.05 2001/01/02 SiB: [fleqn] detection.
%% v3.05a 2001/01/04 SiB: [fleqn] detection reverted for eqnarray.
%% v3.06 2001/01/17 SiB: [twocolumn] mode support.
%% v3.07 2001/07/30 SiB: [hyperref] option obsoleted.
%% v3.08 2001/08/02 SiB: linenomath wrapping for \[ \]
%% v3.08a 2001/08/04 SiB: linenomath wrapping for \[ \] fixed
%% v3.08b 2002/01/27 SiB: enquotation typo fix
%% v3.09 2003/01/14 SIB: hyperref detection fix
%% v3.10 2003/04/15 FMi: \MakeLineNo fix for deep boxes
%% v3.10a 2003/11/12 Uwe Lück: \lineref typo fix
%% v4.00 2004/09/02 UL: included linenox0, linenox1, lnopatch code with
%% documentation, usually indicated by `New v4.00';
%% discussions of old code, indicated by `UL';
%% LPPL v.1 -> LPPL v1.3, `program' -> `file';
%% first lines with \filedate and \fileversion,
%% according nawk lines; `November 1994 or later',
%% some earlier documentation typos (including a few
%% bad minus signs), { -> {% and } -> \unskip} at
%% line ends (so, e.g., alignment in TOC works); \scs.
%% 2004/09/03 UL: removed everything which indicated that the
%% present file were named `lineno4.sty'.
%% v4.1 2004/09/19 UL: Inserted Stephan's identification line, removed
%% some TODOs and remarks from v4.00.
%% 2004/10/04 UL: Added acknowledgement for Daniel Doherty;
%% `(New v4.00)' with [|\firstlinenumber]; changed
%% TODOs; Refining -> Redefining (\vadjust).
%% 2004/10/05 UL: ednmath0 -> mathrefs; \catcode`\~ -> \active;
%% \path; refined section on options `mathrefs';
%% changes in introduction.
%% 2004/10/06 UL: Changed/removed TODOs, e.g., for edtable.sty.
%% 2004/10/11 UL: Reminders: linenox0/1/lnopatch.sty obsolete;
%% \tt star in list of commands.
%% 2004/10/12 UL: Corrected blank lines in lineno.tex.
%% 2004/10/19 UL: Fixed minor typos; remark on \if@LN@edtable.
%% v4.1a 2004/11/07 UL: LPPL v1.3a.
%% v4.1b 2004/11/13 UL: Comment on \outputpenalty values.
%% v4.1c 2005/01/10 UL: Contact via http.
%% v4.11 2005/02/20 UL: Error message with \linelabel when not numbering.
%% 2005/03/07 UL: Removed \linelabel from ss:Tab heading, consider
%% marginal line numbers as well, revised ss:Tab.
%% Added a few lines on missing explanations to
%% s:UserCmds. Corrected some code alignments.
%% 2005/03/08 UL: Require recent edtable.sty.
%%
%% v4.2 2005/03/21 UL: "Physical page" counter works with \include.
%% 2005/04/17 UL: Raised options section above extensions section
%% (v4.00 disabled `displaymath' option);
%% third arg for \@ifundefined{mathindent};
%% "bunch of options";
%% 2005/04/24 UL: compatibility with tamefloats; vplref.sty.
%% 2005/04/25 UL: \number -> \the; wondered -> $$; subsec. appbas;
%% CrtlLN sec -> subsec.; \newcommand* wherever ...;
%% doc. on `other output routines' and `addpageno'
%% (this changed from `varioref').
%% 2005/04/27 UL: =1\relax -> =\@ne, 0\relax ..., \hb@xt@,
%% \ifx\@@par\@@@par -> \ifLineNumbers, typos,
%% \pagestyle{headings}, LaTeX -> \LaTeX.
%% v4.21 2005/04/28 UL: linenomath section: removed wrong \else's,
%% \holding...: \thr@@, \@LN@outer@holdins, \global.
%% v4.22 2005/05/01 UL: \unvbox\@outputbox; \@LN@col without #1,
%% 2005/05/08 UL: global/local \internall..., \resetl... global,
%% shortened discussions of this and of \newcounter.
%% 2005/05/09 UL: corr.: doc. typo, version history, bad lines;
%% percent; \chardef for modulo,
%% \value{firstlinenumber}.
%% v4.3 2005/05/10 UL: \@backslashchar -> \char`\\ in \scs.
%% 2005/05/11 UL: \linenumbers sets ...outer@holdins; tidied up
%% documentation regarding earlier versions.
%% 2005/05/12 UL: `linenomath' without spurious number above;
%% `displaymath' default; edmac homepage ->
%% ednotes.sty.de.vu, \endlinenomath without
%% numbers: no change of \holdinginserts;
%% \linelabel doesn't go to .aux or mark,
%% hyperref detected; undone 2005/05/10 (bad mark).
%% 2005/05/13 UL: Reworked hyperref detection (new subsec.).
%% 2005/05/15 UL: More typo fixes, corrected terrible confusions in
%% the discussion (v4.22/v4.3) of \new/\stepcounter;
%% new subsec. in `Line number ...'; another
%% implementation of `hyperref' detection.
%% 2005/05/16 UL: Final minor changes.
%% v4.31b /06/14 UL: Extended explanation of \firstlinenumbers
%% and package options; \@LN@ifgreat@critical;
%% \modulolinenumbers*. Sent to Ednotes.news only.
%% v4.31 2005/06/15 UL: \modulolinenumbers* with \firstlinenumber{1};
%% " -> ``/''; more doc. on \firstlinenumber .
%% 2005/06/20 UL: Typo fix.
%% 2005/10/01 UL: Warning about \mod...* with pagewise mode.
%% v4.31a /10/02 UL: Minor changes of appearance of doc., e.g.,
%% \[ for $$.
%% v4.32b /10/15 UL: Support for \addvspace; removed comments that
%% had been invisible already for some time;
%% made clear with which environments the
%% linenomath environment is not needed.
%% v4.32ab /10/15 UL: Observe \if@nobreak with support for \addvspace.
%% v4.32 2005/10/17 UL: Just made it official and sent it to CTAN.
%% v4.33b /10/23 UL: \if@nobreak\nobreak\fi -> \nobreak .
%% v4.33ab /10/24 UL: \LineNoLaTeXOutput without \@tempswafalse;
%% undid v4.22: \[unv]box\@outputbox (space is OK,
%% \unvbox pushes short columns down); \@LN@kern@z@ .
%% v4.4b 2005/10/24 UL: Another tidying-up of the discussion of
%% \stepcounter{linenumber}; \@LN@screenoff@pen
%% replaces \@LN@kern@z@, \@LN@depthbox .
%% v4.4 2005/10/27 UL: Just made official for CTAN.
%% v4.4a 2005/10/29 UL: Undid change of discussion of
%% \stepcounter{linenumber} (confusion again).
%% v4.41 2005/11/02 UL: Raised \CheckCommand*.
%%
%% Acknowledgements:
%% v3.06: Donald Arseneau, pointed to mparhack.sty.
%% v3.07+: Frank Mittelbach, points out inconsistencies in the
%% user interface.
%% v3.10: Frank Mittelbach \MakeLineNo fix for deep boxes
%% v4.00: Daniel Doherty points out clash of \pagewise... with resetting
%% page number.
%% v4.21: Much testing work by Erik Luijten.
%% v4.3: `displaymath' default by Erik Luijten's suggestion.
%% v4.31: \modulolinenumbers* is an idea of Hillel Chayim Yisraeli's.
%% v4.32: Support for \addvspace due to Saravanan M.'s observation.
%% v4.33: Different support for \addvspace due to bug reports by
%% Saravanan M.'s and David Josef Dev.
%% v4.4: David Josef Dev points out that \kern\z@ after a paragraph
%% tends to place its final baseline wrongly.
%
%
% \section{%
% Put the line numbers to the lines
% \unskip}
%
% (New v4.00) This section contained the most
% basic package code previously. For various purposes of
% version_4\dots, much of these basics have been to be modified.
% Much of my (UL's) reasoning on these modifications has been to
% be reported. Sorry, the present section has been blown up
% awfully thus and contains ramifications that may be difficult
% to trace. We add some ~\subsection~ commands in order to cope
% with the new situation. (/New v4.00)
%
% \subsection{%
% Basic code of \texttt{lineno.sty} \scs{output}
% \unskip}\label{ss:output}
%
% The line numbers have to be attached by the output
% routine. We simply set the ~\interlinepenalty~ to $-100000$.
% The output routine will be called after each line in the
% paragraph, except the last, where we trigger by ~\par~.
% The ~\linenopenalty~ is small enough to compensate a bunch of
% penalties (e.g., with ~\samepage~).
%
% (New v3.04) Longtable uses
% ~\penalty~$-30000$. The lineno penalty range was
% shrunk to $-188000 \dots -32000$. (/New v3.04)
% (New v4.00) New values are listed below (11111f.). (/New v4.00)
\newcount\linenopenalty\linenopenalty=-100000
%% TODO v4.4+:
% (UL) Hm. It is never needed below
% that this is a counter. ~\def\linenopenalty{-100000\relax}~
% would do. (I guess this consumes more memory, but it
% is more important to save counters than to save memory.)
% I was frightened by ~-\linenopenalty~ below, but indeed
% \TeX\ interprets the string ~--100000~ as 100000.
% Has any user or extension package writer ever called
% ~\linenopenalty=xxx~, or could I really change this?---The
% counter is somewhat faster than the macro. Together with the
% compatibility question this seems to support keeping the
% counter. (???)
%% Note that Stephan chose ~\mathchardef~ below,
%% so his choice above seems to have been deliberate.
%% <- no point, \mathchardef token is fast.
% (/UL)
\mathchardef\linenopenaltypar=32000
% So let's make a hook to ~\output~, the direct way. The \LaTeX\
% macro ~\@reinserts~ puts the footnotes back on the page.
%
% (New v3.01) ~\@reinserts~ badly
% screws up split footnotes. The bottom part is
% still on the recent contributions list, and the
% top part will be put back there after the bottom
% part. Thus, since lineno.sty does not play well
% with ~\inserts~ anyway, we can safely experiment
% with ~\holdinginserts~, without making things
% much worse.
%
% Or that's what I thought, but: Just activating
% ~\holdinginserts~ while doing the ~\par~ will
% not do the trick: The ~\output~ routine may be
% called for a real page break before all line
% numbers are done, and how can we get control
% over ~\holdinginserts~ at that point?
%
% Let's try this: When the ~\output~ routine is
% run with ~\holdinginserts=3~ for a real page
% break, then we reset ~\holdinginserts~ and
% restart ~\output~.
%
% Then, again, how do we keep the remaining
% ~\inserts~ while doing further line numbers?
%
% If we find ~\holdinginserts~=$-3$ we activate it again
% after doing ~\output~. (/New v3.01)
%
% (New v3.02) To work with
% multicol.sty, the original output routine is now
% called indirectly, instead of being replaced.
% When multicol.sty changes ~\output~, it is a
% toks register, not the real thing. (/New v3.02)
%
% (New v4.00) Two further complications are added.
%%
%% TODO v4.3+: Or three, ~\@nobreakfalse~ after ~\MakeLineNo~
%% for getting rid of ~\@LN@nopagebreak~.
% \begin{itemize}\item
% [(i)] Problems with footnotes formerly resulted from
% \LaTeX's ~\@reinserts~ in ~\@specialoutput~ which Stephan's
% ~\linelabel~ called via the ~\marginpar~ mechanism.
% \item
% [(ii)] \LaTeX\ commands using ~\vadjust~ formerly didn't work
% as one would have hoped. The problem is as follows:
% Printing the line number results from
% a box that the output routine inserts at the place of the
% ~\interlinepenalty~. ~\vadjust~ items appear \emph{above} the
% ~\interlinepenalty~ (\TeX book p._105). So ~\pagebreak~, e.g.,
% formerly sent the line number to the next page, while the
% penalty from ~\nopagebreak~ could not tie the following line,
% since it was screened off by the line number box.---Our trick
% is putting the ~\vadjust~ items into a list macro from which
% the output routine transfers them into the vertical list,
% below the line number box.
% \end{itemize}
% In this case_(ii), like in case_(i), footnotes would suffer
% if ~\holdinginserts~ were non-positive. Indeed, in both
% cases_(i) and_(ii) we tackle the footnote problem by extending
% that part of Stephan's output routine that is active when
% ~\holdinginserts~ is positive. This extension writes the line
% number ~\newlabel~ to the .aux file (which was formerly done
% under $~\holdinginserts~=-3$) and handles the ~\vadjust~
% items.---To trigger ~\output~ and its ~\linelabel~ or, resp.,
% ~\vadjust~ part, the list of signal penalties started
% immediately before is increased here (first for ~\linelabel~,
% second for postponed ~\vadjust~ items):
\mathchardef\@Mllbcodepen=11111
\mathchardef\@Mppvacodepen=11112
% (/New v4.00) (New v4.2) David Kastrup urges to use a private
% name instead of ~\the\output~ (LaTeX-L-list). Otherwise an
% ~\output~ routine loaded later and using ~\newtoks\output~
% again may get lost entirely. So we change use of ~\@LN@output~,
% using it for the former purpose. Reference to what appeared
% with the name of ~\output~ here lasts for a few lines and then
% is given away.
\let\@tempa\output
\newtoks\output
\let\@LN@output\output
\output=\expandafter{\the\@tempa}
% Now we add two cases to Stephan's output routine. (New v4.00)
\@tempa={%
% (/New 4.2)
\LineNoTest
\if@tempswa
%%
%% (UL) Learnt that even in def.s blank line means ~\par~.
%% to leave visual space in present file with having a
%% blank line neither in present nor in .tex file,
%% use double comment mark (`%%'). (/UL)
%%
% (New v4.00)
% We insert recognition of waiting ~\linelabel~ items---
%%
\ifnum\outputpenalty=-\@Mllbcodepen
\WriteLineNo
%%
% ---and of waiting ~\vadjust~ items:
%%
\else
\ifnum\outputpenalty=-\@Mppvacodepen
\PassVadjustList
\else
%%
%% Now we give control back to Stephan.
% (/New v4.00) (New v4.2) Outsource ``Standard'' output
% ---which occurs so rarely---to subsection_\ref{ss:LLO}:
%%
\LineNoLaTeXOutput
% (/New v4.2) (New v4.00)
% Two new ~\fi~s for the ~\linelabel~ and ~\vadjust~ tests---
%%
\fi
\fi
%%
% ---and the remaining is
%%%next three lines are
% Stephan's code again:
% (/New v4.00)
%%
\else
\MakeLineNo
\fi
}
% (New v4.00) Our new macros
% ~\WriteLineNo~ and ~\PassVadjustList~ will be dealt with in
% sections_\ref{s:LNref} and_\ref{ss:PVadj}. (/New v4.00)
%
% \subsection{%
% \scs{LineNoTest}
% \unskip}
%
% The float mechanism inserts ~\interlinepenalty~s during
% ~\output~. So carefully reset it before going on. Else
% we get doubled line numbers on every float placed in
% horizontal mode, e.g, from ~\linelabel~.
%
% Sorry, neither a ~\linelabel~ nor a ~\marginpar~ should
% insert a penalty, else the following linenumber
% could go to the next page. Nor should any other
% float. So let us suppress the ~\interlinepenalty~
% altogether with the ~\@nobreak~ switch.
%
% Since (ltspace.dtx, v1.2p)[1996/07/26], the ~\@nobreaktrue~ does
% it's job globally. We need to do it locally here.
\def\LineNoTest{%
\let\@@par\@@@par
\ifnum\interlinepenalty<-\linenopenaltypar
\advance\interlinepenalty-\linenopenalty
\@LN@nobreaktrue
\fi
\@tempswatrue
\ifnum\outputpenalty>-\linenopenaltypar\else
\ifnum\outputpenalty>-188000\relax
\@tempswafalse
\fi
\fi
}
\def\@LN@nobreaktrue{\let\if@nobreak\iftrue} % renamed v4.33
% (UL) I thought here were
% another case of the save stack problem explained in \TeX book,
% p._301, namely through both local and global changing
% ~\if@nobreak~. However, ~\@LN@nobreak~ is called during
% ~\@LN@output~ only, while ~\@nobreaktrue~ is called by \LaTeX's
% ~\@startsection~ only. The latter never happens during
% ~\@LN@output~. So there is no local value of ~\if@nobreak~ on
% save stack when ~\@nobreaktrue~ acts, since ~\the\@LN@output~
% (where ~\@LN@output~ is a new name for the original ~\output~)
% is executed within a group (\TeX book p._21).
%%
%% 2004/09/19 Removed nonsense here according to Stephan 2004/09/04.
%%
% (/UL)
%
% \subsection{%
% Other output routines (v4.2)
% \unskip}\label{ss:LLO}
%
% I had thought of dealing with bad interference of footnotes
% (and ~\enlargethispage~) with (real) ~\marginpar~s and floats
% \emph{here}. Yet this is done in
% \[
% ~http://~\mbox{[CTAN]}
% ~/macros/latex/contrib/tamefloats/tameflts.sty~
% \]
% now, and I prefer striving for compatibility with the latter.
% (See there for expanding on the problem.)
% This requires returning the special absolute value of
% ~\holdinginserts~ that ~lineno.sty~ finds at the end of a newly
% typeset paragraph---now done in subsection_\ref{ss:calls}
% (~\linenumberpar~).
% The former ~\LineNoHoldInsertsTest~ has been filled into here.
%% ---`3' is replaced by ~\thr@@~ for a while. ~\thr@@~ is
%% useful practice since plain \TeX, but Stephan may have been
%% wise in suspecting that \LaTeX\ once could forsake ~\thr@@~.
%% The same holds for ~\@M=10000~.
% Note: when the following code is invoked, we have
% ~\if@tempswa~_ =_~\iftrue~.
% WARNING: I am still not sure whether the present code is good
% for cooperating with other packages that use ~\holdinginserts~.
\def\LineNoLaTeXOutput{%
\ifnum \holdinginserts=\thr@@ % v4.33 without \@tempswafalse
\global\holdinginserts-\thr@@
\unvbox\@cclv
\ifnum \outputpenalty=\@M \else \penalty\outputpenalty \fi
\else
\if@twocolumn \let\@makecol\@LN@makecol \fi
\the\@LN@output % finally following David Kastrup's advice.
\ifnum \holdinginserts=-\thr@@
\global\holdinginserts\thr@@ \fi
\fi
}
% \textit{More on dealing with output routines from other
% packages:}
% Since ~lineno.sty~'s output routine is called at least once
% for each output line, I think it should be in \TeX's
% original ~\output~, while output routines dealing with
% building pages and with floats etc.\ should be filled into
% registers addressed by ~\output~ after ~\newtoks\output~.
% Therefore \begin{enumerate}
% \item
% ~tameflts.sty~ should be loaded \emph{after} ~lineno.sty~;
% \item
% if a class changes ~\output~ (APS journal class revtex4,
% e.g.), ~lineno.sty~ should be loaded by ~\RequirePackage~
% [here presumably following some options in
% brackets]~{lineno}~ \emph{preceding} ~\documentclass~.
% \item
% If you actually maintain such a class, please consider
% loading ~lineno.sty~ on some draft option. The bunch of
% lineno's package options may be a problem, but perhaps the
% purpose of your class is offering only very few of lineno's
% options anyway, maybe just one.
% \end{enumerate}
% The latter may also be needed with classes that don't follow
% David Kastrup's rule on changing ~\output~.
%
% \subsection{%
% \scs{MakeLineNo}: Actually attach line number
% \unskip}\label{ss:MLN}
%
% We have to return all the page to the current page, and
% add a box with the line number, without adding
% breakpoints, glue or space. The depth of our line number
% should be equal to the previous depth of the page, in
% case the page breaks here, and the box has to be moved up
% by that depth.
%
% The ~\interlinepenalty~ comes after the ~\vadjust~ from a
% ~\linelabel~, so we increment the line number \emph{after}
% printing it. The macro ~\makeLineNumber~ produces the
% text of the line number, see section \ref{appearance}.
%
% (UL) I needed a while to understand
% the sentence on incrementing. Correctly: writing the
% ~\newlabel~ to the .aux file is triggered by the signal
% penalty that ~\end@float~ inserts via ~\vadjust~.
% However, this could be changed by our new ~\PostponeVadjust~.
% After ~\c@linenumber~ has been introduced as a \LaTeX\
% counter, it might be preferable that it behaved like standard
% \LaTeX\ counters which are incremented shortly before printing.
% But this may be of little practical relevance in this case,
% as ~\c@linenumber~ is driven in a very non-standard
% way.---However still, this behaviour of ~\c@linenumber~
% generates a problem with our ~edtable.sty~.
%% \unskip---Before,
%% I thought that Stephan had reported his reasoning incorrectly
%% and rather did this because of his ~\resetlinenumber~ which
%% initializes ~\c@linenumber~ to 1 instead of 0---the latter is
%% usual with \LaTeX\ counters. Cf._additional comment at
%% ~\resetlinenumber~.
% (/UL).
%
% Finally we put in the natural ~\interlinepenalty~, except
% after the last line.
%
% (New v3.10) Frank Mittelbach points out that box255 may be
% less deep than the last box inside, so he proposes to
% measure the page depth with ~\boxmaxdepth=\maxdimen~.
% (/New v3.10)
%
% (UL, New v4.00) We also resume the matter of
% ~\vadjust~ items that was started in section_\ref{ss:output}.
%
% \TeX\ puts only nonzero interline
% penalties into the vertical list (\TeX book p._105), while
% ~lineno.sty~ formerly replaced the signal interline penalty by
% something closing with an explicit penalty of the value that
% the interline penalty would have without ~lineno.sty~.
% This is usually 0. Now, explicit vertical penalties can be
% very nasty with respect to ~\nopagebreak~, e.g., a low (even
% positive) ~\widowpenalty~ may force a widow where you
% explicitly tried to forbid it by ~\nopagebreak~
% (see explanation soon below).
% The ~\nopagebreak~ we create here would never work if all
% those zero penalties were present.---On
% the other hand, we cannot just omit Stephan's zero penalties,
% because \TeX\ puts a penalty of 10000 after what ~lineno.sty~
% inserts (\TeX book p._125). This penalty must be overridden
% to allow page breaks between ordinary lines. To revive
% ~\nopagebreak~, we therefore replace those zero (or low)
% penalties by penalties that the user demanded by
% ~\nopagebreak~.---This mechanism is not perfect and does not
% exactly restore the original \LaTeX\ working of ~\pagebreak~
% and ~\nopagebreak~. Viz., if there are several vertical
% penalties after a line which were produced by closely sitting
% ~\[no]pagebreak~s, without ~lineno.sty~ the lowest penalty would
% be effective (cf._\TeX book exercise_14.10). Our mechanism, by
% contrast, chooses the \emph{last} user-set penalty of the line
% as the effective one. It would not be very difficult to come
% more close to the original mechanism, but until someone urges
% us we will cling to the present simple way. You may consider an
% advantage of the difference between our mechanism and the
% original one that the user here can actually override low
% penalties by ~\nopagebreak~, which may be what a lay \LaTeX\
% user would expect.
%% ---Zero glue would do instead of zero
%% penalty! This could make things easier. Maybe next time.
%% <- v4.4: No, problem with column depth.
% (/UL, /New v4.00)
\def\MakeLineNo{%
\@LN@maybe@normalLineNumber % v4.31
\boxmaxdepth\maxdimen\setbox\z@\vbox{\unvbox\@cclv}%
\@tempdima\dp\z@ \unvbox\z@
\sbox\@tempboxa{\hb@xt@\z@{\makeLineNumber}}%
%%
% (New v4.00) Previously,
% \begin{old}\begin{verbatim}
% % \stepcounter{linenumber}%
% \end{verbatim}
% \end{old}
%% %% TODO: Still first `\begin{old}'?
% followed. (Of course, there was no
% comment mark; I put it there to make
% reading the actual code easy.)
%
% (New v4.22: improved) Why not just
% \[~\global\advance\c@linenumber\@ne~?\]
% ~\stepcounter~ additionally resets ``subordinate''
% counters, but which could these (usefully) be?
% Again, may be column counters with ~edtable.sty~!?
%
% But then, our ~edtable.sty~ and its ~longtable~ option
% should use it as well. So use a shorthand supporting
% uniformity. You can even use it as a hook for choosing
% ~\global\advance\c@linenumber\@ne~ instead of our choice.
% (/New v4.22)
%%
\stepLineNumber
%%
% (New v4.4) Now
%%
\ht\@tempboxa\z@ \@LN@depthbox
%%
% appends the box containing the line number without changing
% ~\prevdepth~---see end of section.
% Now is the time for inserting the $\dots$ (/New v4.4)
%% The line number has now been placed (it may be invisible
%% depending on the modulo feature), so
%% we can insert the
% ~\vadjust~ items. We cannot do this much later, because
% their right place is above the artificial interline
% penalty which Stephan's code will soon insert
% (cf._\TeX book p._105). The next command is just ~\relax~
% if no ~\vadjust~ items have been accumulated for the
% current line. Otherwise it is a list macro inserting
% the ~\vadjust~ items and finally resetting itself.
% (This is made in section_\ref{ss:PVadj} below.)
% If the final item is a penalty, it is stored so it can
% compete with other things about page breaking.
%%
\@LN@do@vadjusts
\count@\lastpenalty
%%
% At this place,
% \begin{old}\begin{verbatim}
% % \ifnum\outputpenalty=-\linenopenaltypar\else
% \end{verbatim}
% \end{old}
% originally followed. We need something \emph{before} the
% ~\else~:
%%
\ifnum\outputpenalty=-\linenopenaltypar
\ifnum\count@=\z@ \else
%%
% So final ~\pagebreak[0]~ or ~\nopagebreak[0]~ has no
% effect---but this will make a difference after headings only,
% where nobody should place such a thing anyway.
%%
\xdef\@LN@parpgbrk{%
\penalty\the\count@
\global\let\noexpand\@LN@parpgbrk
\noexpand\@LN@screenoff@pen}% v4.4
%%
% That penalty will replace former ~\kern\z@~ in
% ~\linenumberpar~, see subsection_\ref{ss:calls}.---A
% few days earlier, I tried to send just a penalty value.
% However, the ~\kern\z@~ in ~\linenumberpar~ is crucial,
% as I then found out. See below.---The final penalty is
% repeated, but this does no harm. (It would not be very
% difficult to avoid the repeating, but it may even be
% less efficient.) It may be repeated due to the previous
% ~\xdef~, but it may be repeated as well below in the
% present macro where artificial interline penalty is to
% be overridden.
%%
\fi
\else
%%
% (/New v4.00)
%% Corrected code alignment with v4.11.
\@tempcnta\outputpenalty
\advance\@tempcnta -\linenopenalty
%%
% (New v4.00)
% \begin{old}\begin{verbatim}
% % \penalty\@tempcnta
% \end{verbatim}
% \end{old}
% followed previously. To give ~\nopagebreak~ a chance,
% we do
%% Corrected code alignment with v4.11.
\penalty \ifnum\count@<\@tempcnta \@tempcnta \else \count@ \fi
%%
% instead.---In ~linenox0.sty~, the ~\else~ thing once was omitted.
% Sergei Mariev's complaint (thanks!) showed that it is vital
% (see comment before ~\MakeLineNo~).
% The remaining ~\fi~ from previous package version closes the
% ~\ifnum\outputpenalty~\dots
% (/New v4.00)
%%
\fi
}
% (New v4.00)
\newcommand\stepLineNumber{\stepcounter{linenumber}}
% For reason, see use above. (/New v4.00)
%% %% TODO v4.4+: ~\newcommand~ more often!?
%
% (New v4.4) The depth preserving trick is drawn here from
% ~\MakeLineNo~ because it will be used again in
% section_\ref{ss:calls}.
\def\@LN@depthbox{%
\dp\@tempboxa=\@tempdima
\nointerlineskip \kern-\@tempdima \box\@tempboxa}
% (/New v4.4)
%
% \section{%
% Control line numbering
% \unskip}
% \subsection{%
% Inserting \scs{output} calls %% own subsec. v4.4.
% \unskip}\label{ss:calls}
% The line numbering is controlled via ~\par~. \LaTeX\
% saved the \TeX-primitive ~\par~ in ~\@@par~. We push it
% one level further out, and redefine ~\@@par~ to insert
% the ~\interlinepenalty~ needed to trigger the
% line numbering. And we need to allow pagebreaks after a
% paragraph.
%
% New (2.05beta): the prevgraf test. A paragraph that ends with a
% displayed equation, a ~\noindent\par~ or ~wrapfig.sty~ produce empty
% paragraphs. These should not get a spurious line number via
% ~\linenopenaltypar~.
\let\@@@par\@@par
\newcount\linenoprevgraf
% (UL) And needs ~\linenoprevgraf~
% to be a counter? Perhaps there may be a paragraph having
% thousands of lines, so ~\mathchardef~ doesn't suffice (really??).
%%
%% %% TODO: limitations of lines per paragraph elsewhere?
%% %% Signal penalties, e.g.!? ~\deadcycles~!?
%%
% A macro ending on ~\relax~ might suffice, but would be
% somewhat slow. I think I will use ~\mathchardef~ next time.
% Or has any user used ~\linenoprevgraf~? (/UL)
%% v4.33: changed code alignment for better understanding.
\def\linenumberpar{%
\ifvmode \@@@par \else
\ifinner \@@@par \else
\xdef\@LN@outer@holdins{\the\holdinginserts}% v4.2
\advance \interlinepenalty \linenopenalty
\linenoprevgraf \prevgraf
\global \holdinginserts \thr@@
\@@@par
\ifnum\prevgraf>\linenoprevgraf
\penalty-\linenopenaltypar
\fi
%%
% (New v4.00)
% \begin{old}\begin{verbatim}
% % \kern\z@
% \end{verbatim}
% \end{old}
% was here previously. What for?
% According to \TeX book p._125, Stephan's
% interline penalty is changed into 10000. At the end of a
% paragraph, the ~\parskip~ would follow that penalty of 10000,
% so there could be a page break neither at the
% ~\parskip~ nor at the ~\baselineskip~ (\TeX book p._110)---so
% there could never be a page break between two paragraphs.
% So something must screen off the 10000 penalty.
% Indeed, the ~\kern~ is a place to break.
% (Stephan once knew this: see `allow pagebreaks' above.)
%
% Formerly, I tried to replace ~\kern\z@~ by
% \begin{old}\begin{verbatim}
% % \penalty\@LN@parpgpen\relax
% \end{verbatim}
% \end{old}
% ---but this allows a page break after heading. So:
%%
\@LN@parpgbrk
%%
%% After heading, ~\kern\z@~ resulting from previous line
%% (see below) is followed by ~\write~ or ~\penalty10000~,
%% so causes no page break.
%