Debian Codegraph @

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

raw
1 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
2 \ProvidesPackage{fnlineno}[2011/01/07 v0.55
3 numbers to footnote lines (UL)]
4
5 %% Copyright (C) 2010 Uwe Lück
6 %%
7 %% This file can be redistributed and/or modified under
8 %% the terms of the LaTeX Project Public License; either
9 %% version 1.3c of the License, or any later version.
10 %% The latest version of this license is in
11 %% http://www.latex-project.org/lppl.txt
12 %% We did our best to help you, but there is NO WARRANTY.
13 %%
14 %% Please report bugs, problems, and suggestions via
15 %%
16 %% https://github.com/latex-lineno/lineno
17 %%
18 %% {\it This work has been supported
19 %% % and is owned %% wrong, owner is RUB -- 2011/02/09
20 %% by the Deutsche Forschungsgemeinschaft (DFG),
21 %% organized %% 2010/12/18 TODO!?
22 %% by Prof.~Dr.\ Dr.\ Christian Tapp
23 %% at Ruhr-Universität Bochum, Germany.}
24 %% %% 2010/12/18:
25 %% Christian also has constructed some critical tests.
26 %%
27 %% === Installing and Calling ===
28 %% The file 'fnlineno.sty' is provided ready, installation only requires
29 %% putting it somewhere where \TeX\ finds it
30 %% (which may need updating the filename data
31 %% base).\footnote{\url{http://www.tex.ac.uk/cgi-bin/texfaq2html?label=inst-wlcf}}
32 %%
33 %% As usually, 'fnlineno.sty' is loaded by
34 %% \begin{verbatim}
35 %% \usepackage{fnlineno}
36 %% \end{verbatim}
37 %% below the \verb|\documentclass| line and before \verb|\begin{document}|.
38 %%
39 %% === Limitations ===
40 %% v0.55 %%% v0.5 %% 2011/02/09
41 %% should really work
42 %% the way users expect, %% 2011/02/09
43 %% but please consider:
44 %% % In the \strong{present version (v0.4)}, 'flnineno.sty' is just
45 %% % ``work in progress"---with at least the following issues:
46 %% \begin{enumerate}
47 %% % \item Lines are numbered in an order
48 %% % that you may not like, in the presence of
49 %% % footnotes.
50 %% % Overcoming this failure by automagic
51 %% % will be the major further work on the package!
52 %% % (v0.5!?)
53 %% %
54 %% % \item The package is not expected to work with 'manyfoot'
55 %% % (neither 'ednotes' ... future work!).
56 %%
57 %% \item Nothing is known about compatibility with
58 %% packages (other than 'manyfoot' and 'bigfoot')
59 %% providing footnote features beyond standard \LaTeX.
60 %%
61 %% \item \verb|\lipsum[<opt-arg>]| in main text produces
62 %% a different number of paragraphs ...
63 %%
64 %% %% 2010/12/18:
65 %% % \item \verb|\pagebreak| (without optional argument, or
66 %% % \verb|\pagebreak[4]|) in footnotes prints footnote parts
67 %% % (splits) in wrong order.\footnote{TODO:
68 %% % (i)~extra case (using flag) in &\output
69 %% % with $&\outputpenalty=-10000$;
70 %% % \emph{or}
71 %% % (ii)~redefine &\pagebreak in footnotes ...}
72 %% %% 2010/12/19, "tried" "assumed" 2010/12/21:
73 %% \item v0.41 tried supporting \verb|\pagebreak| in footnotes
74 %% for manual control of splitting footnotes.
75 %% %% 2010/12/20f.:
76 %% However, it wrongly assumed that \verb|\pagebreak[4]|
77 %% forces a footnote split, cf. Section~\ref{sec:sw};
78 %% users better still don't use \verb|\pagebreak|
79 %% in footnotes!
80 %%
81 %% \item Much of the code is ``guessed" without complete
82 %% knowledge of \TeX\ internals and without having
83 %% tested many possible cases.
84 %% %% 2010/12/27:
85 %% \item \emph{Local} switching to ``pagewise" numbering
86 %% won't be possible for a while; we rather assume
87 %% that you \emph{always} want ``pagewise" numbering.
88 %%
89 %% \item Nothing has been tried to offer choices about the
90 %% \emph{style} of numbering footnotes.
91 %% \end{enumerate}
92 %%
93 %% \pagebreak %% 2011/02/09
94 %% == Implementation ==
95 %% === Terms ===
96 %% ``\strong{OTR}" is short for \textit{``output routine"},
97 %% ``\strong{MVL}" is short for \textit{``main vertical list"}.
98 %% %%% TODO "acro"
99 %%
100 %% === Basic Strategy ===
101 %% \LaTeX's \verb|\@footnotetext| writes the footnote text into the
102 %% insertion register. For numbering the footnote lines,
103 %% \emph{we here} do not execute this \verb|\@footnotetext|
104 %% immediately after placing \verb|\@footnotemark|,
105 %% but postpone its \verb|\insert| a little so it
106 %% is executed only after the main text paragraph has been
107 %% broken into lines. Right below the line that contains the
108 %% footnote mark, a special new ``slot" of the \strong{OTR}
109 %% is called that interchanges ``the page so far" with the
110 %% footnote text. When the latter has been typeset,
111 %% another ``slot" of the OTR puts ``the page so far"
112 %% back to the MVL and immediately after that fills the footnote
113 %% text as just typeset on the MVL into the \verb|\insert| register.
114 %%
115 %% Passing footnotes from horizontal mode to vertical mode
116 %% resembles 'lineno''s \verb|\PostponeVadjust|, but a
117 %% different \strong{list} \verb|\FNLN@list|
118 %% must store code
119 %% (\textit{a})~for the footnote \strong{mark} and
120 %% (\textit{b})~for the footnote \strong{text}.
121 %% %%% (TODO: move this paragraph)
122 %%
123 %% === Package Options ===
124 %% A package option |[check-latex]| %% typo article 2010/12/31
125 %% for checking vital \LaTeX\ internals may once be offered
126 %% (TODO 2010/12/12) ...
127 \newif\if@FNLN@check@
128 \DeclareOption{check-latex}{\@FNLN@check@true}
129 \ProcessOptions
130 %%
131 %% === Footnote Commands ===
132 %% ==== Standard Footnotes ====
133 %% The following macro \verb|\FNLN@ltx@fntext| %% more 2010/12/16
134 %% is a copy of \LaTeX's \verb|\@footnotetext|
135 %% that we are varying. It may be used for a check
136 %% if the \verb|\@footnotetext| that 'fnlineno.sty' encounters
137 %% is the one expected (TODO).
138 %% In line numbering mode, this code may never be needed
139 %% all at once, rather we will have to see which material
140 %% must be used at which point of our unusual way of
141 %% processeing footnotes.
142 \if@FNLN@check@
143 \long\def\FNLN@ltx@fntext#1{\insert\footins{%
144 \reset@font\footnotesize
145 \interlinepenalty\interfootnotelinepenalty
146 \splittopskip\footnotesep
147 \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
148 \hsize\columnwidth \@parboxrestore
149 \protected@edef\@currentlabel{%
150 \csname p@footnote\endcsname\@thefnmark
151 }%
152 \color@begingroup
153 \@makefntext{%
154 \rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
155 \color@endgroup}}%
156 \fi
157 %%
158 %% ==== Modifying Footnote Commands ====
159 %% In order to number \verb|\footnote| lines and make
160 %% \verb|\linelabel| available in footnotes, it seems to suffice
161 %% (with standard \LaTeX) to \strong{redefine}
162 %% the internal \verb|\@footnotetext|.
163 %% In line numbering mode, \verb|\@footnotetext| will act as
164 %% \verb|\FNLN@text|,
165 %% % \begin{itemize}
166 %% % \item[(i)]
167 %% (\textit{i})~%
168 %% placing a ``signal" \strong{output penalty}
169 %% below the current line via \verb|\vadjust| and
170 %% % \item[(ii)]
171 %% (\textit{ii})~%
172 %% appending the footnote text to the
173 %% \strong{list} \verb|\FNLN@list| of \strong{footnote texts}.
174 %% % \end{itemize}
175 %%
176 %% \verb|\FNLN@@text| stores the \verb|\@footnotetext| found,
177 %% we might check if it is \verb|\FNLN@ltx@fntext| ... %% TODO
178 \let\FNLN@@text\@footnotetext
179 \def\@footnotetext{%
180 \ifLineNumbers \expandafter \FNLN@text
181 \else \expandafter \FNLN@@text
182 \fi}
183 \def \FNLN@text {% %% 2010/12/31 arg read later
184 \vadjust{\penalty-\FNLN@M@swap@codepen}%
185 %% Standard \LaTeX's \verb|\@footnotetext| expands \verb|\@thefnmark|
186 %% to produce the footnote mark at the page bottom,
187 %% right after it has been determined for the mark
188 %% in the main text. \emph{Here} the footnote text
189 %% will be typeset only when \emph{other} footnote marks
190 %% may have been formed for typesetting the main text
191 %% paragraph before.
192 %% %%% (TODO clearer wording)
193 %% In the \strong{footnote list}
194 %% macro \verb|\FNLN@list|, the (\dqtd{\verb|&\protect|ed})
195 %% \emph{current} expansion <mark> of \verb|\@thefnmark|
196 %% is stored as an item preceding the footnote text
197 %% <text>. One footnote entry in \verb|\FNLN@list|
198 %% thus has the form \lq\verb|<mark>\@lt<text>\@lt|\rq.
199 %% \LaTeX's internal \verb|\g@addto@macro| is used to \emph{append}
200 %% an entry to the list (at the right). The OTR will later
201 %% take the entries from the left of the list.
202 %%
203 %% The argument of the auxiliary/temporary \verb|\@tempa|
204 %% will contain the footnote text and thus must be able to
205 %% carry \verb|\par| tokens. We therefore need a \verb|\long| version of
206 %% \verb|\protected@edef|:
207 \let\@@protect\protect
208 \let\protect\@unexpandable@protect
209 \afterassignment\restore@protect
210 \long \edef \@tempa ##1{%
211 \noexpand\g@addto@macro \noexpand\FNLN@list {%
212 \@thefnmark \noexpand\@lt ##1\noexpand \@lt}}%
213 %% ... issuing
214 %% \lq\verb|\g@addto@macro\FNLN@list{<mark>\elt<text>\@lt}|\rq\ ...
215 \@tempa %% reads arg
216 }
217 %% Here we initialize \verb|\FNLN@list|:
218 \let\FNLN@list\@empty
219 %%
220 %% === Output Routines ===
221 %% ==== 'lineno''s Output Routine ====
222 %% The following is a copy of 'lineno''s OTR
223 %% that we are varying. It may be used for a check
224 %% if the OTR that 'fnlineno.sty' encounters
225 %% is the one expected (TODO).
226 \if@FNLN@check@
227 \def\FNLN@lno@output {%
228 \LineNoTest
229 \if@tempswa
230 \ifnum\outputpenalty=-\@Mllbcodepen
231 \WriteLineNo
232 \else
233 \ifnum\outputpenalty=-\@Mppvacodepen
234 \PassVadjustList
235 \else
236 \LineNoLaTeXOutput
237 \fi
238 \fi
239 \else
240 \MakeLineNo
241 \fi
242 }
243 %% The ``signal penalties" used here are
244 \mathchardef\FNLN@M@llbl@codepen=11111
245 \mathchardef\FNLN@M@ppva@codepen=11112
246 \fi
247 %% Their names should mean \verb|\linelabel| code penalty" and
248 %% \verb|\PostponeVadjust| code penalty."
249 %%
250 %% \verb|\TheLineNoLaTeXOutput|:
251 %% It turns out to be inconvenient here
252 %% that 'lineno' sacrifices access
253 %% to the \emph{primitive} \verb|\output| (\verb|``\@tempa|";
254 %% TODO: auxiliary package before loading 'lineno'!?;
255 %% later change 'lineno.sty' indeed).
256 %% So to change the OTR we use \verb|\LineNoLaTeXOutput| as a hook
257 %% for adding additional cases of \verb|\outputpenalt|ies.
258 %% We take a copy of \verb|\LineNoLaTeXOutput| here.
259 \let\TheLineNoLaTeXOutput\LineNoLaTeXOutput
260 %%
261 %% ==== Tools for Temporary Parameter Changes ====
262 %% \verb|\GStoreReg{<register>}|\quad
263 %% (or\quad \verb|\GStoreReg<register>|\\[\smallskipamount]
264 %% when <register> is a single token---\lq\verb|\count0|\rq\
265 %% being a counterexample ...)\quad
266 %% stores the current content of <register>
267 %% (\emph{globally}) as an internal macro so that it can be
268 %% restored later by\\[\smallskipamount]
269 %% \verb|\RestoreReg{<register>}|\quad
270 %% \mbox{(or\quad }\verb|\RestoreReg<register>|)\\[\smallskipamount]
271 %% or \emph{globally} by\\[\smallskipamount]
272 %% \verb|\GRestoreReg{<register>}|\quad (\verb|\GRestoreReg<register>|)
273 %% \\[\smallskipamount]
274 %% (The OTR runs in a local group!---Recall that assignments
275 %% to ``special dimens"---\TeX book p.\,271---are
276 %% automatically global.)
277 %% <register> is something that can be prefixed by \verb|\the|
278 %% to read its content and to which you can assign a value
279 %% <value> by \lq<register><value>\rq.
280 %% (TODO: could also be some \verb|\catcode|!)
281 %% %% and TODO allow changing name space!
282 \newcommand*{\GStoreReg}[1]{%
283 \expandafter \xdef \csname GS\string#1\endcsname {\the #1}}
284 \newcommand*{\RestoreReg}[1]{#1\csname GS\string#1\endcsname \relax}
285 \newcommand*{\GRestoreReg}{\global\RestoreReg}
286 %% \verb|\GStoreSetReg{<register>}{<value>}| assigns %%% the new value
287 %% <value> to <register> (locally) after executing \verb|\GStoreSet|,
288 %% \verb|\GStoreGSetReg| does the same \emph{globally}
289 %% (and still argument braces aren't needed when a single
290 %% token refers to the register).
291 \newcommand*{\g@storesetreg}[3]{\GStoreReg{#2}#1#2#3\relax}
292 \newcommand*{\GStoreSetReg} {\g@storesetreg\relax}
293 \newcommand*{\GStoreGSetReg}{\g@storesetreg\global}
294 %% (These preliminaries might go into an own new package, TODO!
295 %% + loop on list of <register>s ...) %% 2010/12/19
296 %%
297 %% ==== The basic hook ====
298 %% \label{sec:sw}
299 %% We use two more penalties triggering the ``MVL swaps:"
300 \mathchardef\FNLN@M@swap@codepen =11113
301 \mathchardef\FNLN@M@insert@codepen=11114
302 %% v0.41 deals with \verb|\pagebreak| in footnote texts,
303 %% using a flag \verb|\if@FNLN@sw@| that must be set globally.
304 %% %% 2011/01/07:
305 %% It turned out not to work properly; however, the new
306 %% switch has served a different purpose for ``continuous
307 %% line numbering," cf. section~\ref{sec:cont}.
308 \newif\if@FNLN@sw@ \global\@FNLN@sw@false %% v0.41
309 %% When a \verb|\pagebreak| triggers the OTR while typesetting
310 %% the footnote text, the page content is collected
311 %% in a box \verb|\FNLN@holdft|:
312 \newsavebox\FNLN@holdft %% v0.41
313 %% Using \verb|\LineNoLaTeXOutput| for hooking into the OTR:
314 \renewcommand*{\LineNoLaTeXOutput}{%
315 \ifnum\outputpenalty=-\FNLN@M@swap@codepen
316 \SwapFootnoteMain
317 \else
318 \ifnum\outputpenalty=-\FNLN@M@insert@codepen
319 \InsertFootnote
320 \else
321 \if@FNLN@sw@ %% v0.41
322 % \showthe\outputpenalty %% 2010/12/20
323 \global\setbox \FNLN@holdft \vbox{%
324 \unvbox\FNLN@holdft
325 %% %% moved here, clarified 2010/12/21:
326 %% TODO from v0.41: \verb|\pagebreak[4]| does not seem to force (reliably)
327 %% splitting a footnote; if the footnote is not split here,
328 %% at present the \verb|\baselineskip| is lost,
329 %% see the footnote paragraph starting
330 %% with \qtd{C} in \verb|edfndemo.pdf| as of 2010/12/21.
331 %% We would need some measuring ... \verb|\pagebreak|
332 %% might be redefined ... resembling \LaTeX's \verb|\@specialoutput|!
333 \unvbox\@cclv
334 %% TODO same problem here, see the footnote paragraph starting
335 %% with \qtd{D} in \verb|edfndemo.pdf| as of 2010/12/21.
336 \penalty\outputpenalty}%
337 %% TODO reset page book-keeping!? %% v0.41
338 \else
339 \TheLineNoLaTeXOutput %% "the real \LineNoLaTeXOuput"
340 \fi
341 \fi
342 \fi
343 }
344 %% \strong{An idea:}\quad Instead of so many \verb|\ifnum|, use
345 %% \[\verb|\csname<chars>\the\outputpenalty\endcsname|\]
346 %% ... in 'lineno.sty', when you really have a broad
347 %% range of \verb|\outputpenalties| useful to be
348 %% described by \verb|\ifnum| range checks ...
349 %%
350 %% ==== Typesetting the Footnote Text ====
351 %% \verb|\SwapFootnoteMain| is the slot of the OTR that our
352 %% modified \verb|\@footnotetext| calls with
353 %% $\verb|\outputpenalty|=-\verb|\FNLN@M@swap@codepen|$.
354 %% The ``column so far" is stored in a new box register
355 %% \verb|\FLNL@holdcol|.
356 \newsavebox\FNLN@holdcol
357 \newcommand*{\SwapFootnoteMain}{%
358 \global \setbox\FNLN@holdcol \vbox{\unvbox\@cclv}%
359 %% (... cf. \verb|\@holdpg| in \LaTeX.)
360 %%
361 %% The entire text of a footnote is typeset on top of
362 %% the MVL. \verb|\vsize| is maximized temporarily to avoid
363 %% that the footnote text is broken across pages.
364 \GStoreGSetReg\vsize\maxdimen
365 %% However, the user may want to use \verb|\pagebreak|
366 %% in a footnote in order to control manually where
367 %% a ``long" footnote is split. v0.41 tries to support
368 %% this:
369 \global\@FNLN@sw@true %% v0.41
370 %% ... cf. Section~\ref{sec:sw}.
371 %%
372 %% There shouldn't be any \verb|\topskip|, the space
373 %% on top of a footnote is controlled by \verb|\footnotesep|
374 %% entirely:
375 \GStoreGSetReg\topskip\z@skip
376 %% (\verb|\nointerlineskip| as well as setting \verb|\topskip|
377 %% locally instead fails ... according to \verb|\showlists| ...)
378 %%
379 %% Resetting \verb|\pagegoal|
380 %% (why doesn't it switch to $\verb|\vsize|=\verb|\maxdimen|$ automatically?),
381 %% \verb|\pagetotal|, and the other ``special dimens"
382 %% (\TeX book p.\,271; rather experimental ...
383 %% I think it is important to restore them later ...)
384 \GStoreSetReg\pagegoal \vsize
385 \GStoreSetReg\pagetotal\z@
386 \GStoreSetReg\pagestretch\z@
387 \GStoreSetReg\pagefilstretch\z@
388 \GStoreSetReg\pagefillstretch\z@
389 \GStoreSetReg\pagefilllstretch\z@
390 \GStoreSetReg\pageshrink\z@
391 \GStoreSetReg\pagedepth\z@
392 %% We must choose certain settings from \verb|\@footnotetext|
393 %% such as font:
394 \reset@font\footnotesize
395 \interlinepenalty\interfootnotelinepenalty
396 %% \LaTeX's \verb|split| things here are relevant at
397 %% \verb|\insert\footins| only: (TODO!?)
398 % \splittopskip\footnotesep
399 % \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
400 \hsize\columnwidth \@parboxrestore
401 %% The previous lines were from \LaTeX's \verb|\@footnotetext|.
402 %% Now we need to restore the \verb|\@thefnmark| that belongs
403 %% to the current footnote text. We use a macro that
404 %% tears two items from \verb|\FNLN@list| and executes the
405 %% rest of \LaTeX's \verb|\@footnotetext|:
406 \expandafter \FNLN@typeset \FNLN@list \@@
407 % \showthe\vsize
408 %% ... so a \verb|\vsize| assignment without \verb|\global|
409 %% is noted here, and an analogous \verb|\topskip| assignment
410 %% is not!? TODO ...
411 }
412 %% \verb|\FNLN@typeset| first removes something %% reworded 2010/12/26
413 %% from the list of footnotes, similarly to \LaTeX's \verb|\@xnext|
414 %% and 'lineno''s \verb|\@LN@xnext|, then executes a
415 %% remaining portion of \LaTeX's \verb|\@footnotetext|.
416 %% The footnote text may contain \verb|\par| tokens,
417 %% so the definition must be \verb|\long|:
418 \long\def \FNLN@typeset #1\@lt #2\@lt #3\@@{%
419 \gdef\FNLN@list{#3}%
420 \def\@thefnmark{#1}%
421 %% This was our own, and next \LaTeX\ continues:
422 \protected@edef\@currentlabel{%
423 \csname p@footnote\endcsname\@thefnmark
424 }%
425 \color@begingroup
426 %% We insert starting the 'lineno' settings ...
427 \linenumbers
428 \setfootnotelinenumbers %% 2010/12/25
429 %% ... \LaTeX\ again (v0.41 exports dealing with
430 %% closing \verb|\par| to \verb|finstrut.sty|):
431 \@makefntext{%
432 \rule\z@\footnotesep\ignorespaces
433 %% We replace \verb|#1| by \verb|#2\par| (\verb|\linenumberpar|),
434 %% so we really need \verb|finstrut.sty|:
435 #2\par
436 \@finalstrut\strutbox}%
437 \color@endgroup
438 %% Now we trigger the ``swap back slot" of the OTR:
439 \penalty-\FNLN@M@insert@codepen
440 }
441 \RequirePackage{finstrut}
442 %%
443 %% ==== Insert the Footnote Text ====
444 %% \verb|\InsertFootnote| is the slot of the OTR that executes
445 %% \verb|\insert\footins| with the numbered footnote text.
446 %% The \verb|column| so far stored in \verb|\FNLN@holdcol|
447 %% is put onto the top of the MVL, and then parts of
448 %% \LaTeX's \verb|\@footnotetext| are performed that haven't
449 %% been done earlier, applied to the footnote text
450 %% that the OTR should have found in \verb|\box255|.
451 %% Before however, the previous \verb|\topskip|, \verb|\vsize|, and the
452 %% \verb|\page|... book-keeping parameters are restored:
453 \newcommand*{\InsertFootnote}{%
454 \GRestoreReg\topskip \GRestoreReg\vsize
455 %% (... \emph{global} restoring of \verb|\vsize| proved vital with
456 %% 'edfndemo' 2010/12/17 ...)
457 \RestoreReg \pagegoal \RestoreReg\pagetotal
458 \RestoreReg \pagestretch
459 \RestoreReg \pagefilstretch
460 \RestoreReg \pagefillstretch
461 \RestoreReg \pagefilllstretch
462 \RestoreReg \pageshrink \RestoreReg\pagedepth
463 \unvbox\FNLN@holdcol
464 \insert\footins{%
465 \splittopskip\footnotesep
466 \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
467 %% Support of \verb|\pagebreak| with v0.41:
468 \unvbox\FNLN@holdft %% v0.41
469 \unvbox\@cclv}%
470 \global\@FNLN@sw@false %% v0.41
471 %% With v0.5, global settings for ``pagewise" numbering
472 %% must be restored: %% 2010/12/26
473 \unsetfootnotelinenumbers
474 }
475 %%
476 %% === Continuous Numbering ===
477 %% \label{sec:cont}
478 %% ==== Goal ====
479 %% With v0.5, for the first time we try to get a
480 %% ``pagewise" numbering such that, if a main text line
481 %% has a footnote,
482 %% (\textit{i})~its printed number is just the natural
483 %% successor of the printed number of the previous main
484 %% text line
485 %% (instead of continuing previous numbering with the
486 %% lines of the footnote first),
487 %% and (\textit{ii})~the printed numbers of footnote lines
488 %% just continue the printed numbers of the main text lines.
489 %% This \verb|obvious| desirement is not easy to achieve;
490 %% already pagewise numbering of main text lines,
491 %% without numbering footnote lines, has been somewhat
492 %% ingenious.
493 %%
494 %% ==== How to Number Lines Pagewise ====
495 %% The basic idea of 'lineno''s pagewise numbering is:
496 %% \begin{enumerate}
497 %% \item Each numbered line of the document is identified
498 %% by a unique counter value, an ``absolute" number.
499 %% \item For each page (and column), the range of absolute
500 %% line numbers occurring on them is recorded
501 %% (or actually: the first and the last number).
502 %% \item The ``public," ``human-readable" (``pagewise")
503 %% format of a given absolute line number $l$ is generated by
504 %% (\textit{i})~finding the page (and column) with
505 %% first number $n$ and last number $k$ such that
506 %% $n\leq l\leq k$,
507 %% (\textit{ii}) ``printing" $l-n+1$ in ``columnwise"
508 %% mode, otherwise $l-m+1$ where $m$ is the first
509 %% absolute line number in the left-hand column of the
510 %% same page.
511 %% \end{enumerate}
512 %% \strong{Generating} the ``pagewise" representation for a
513 %% given absolute line number $l$ thus may be summarized as
514 %% \emph{finding the corresponding \emph{\strong{offset}} value}
515 %% to be subtracted ($n$, $n+1$, $m$, or $m+1$ ...).
516 %%
517 %% When \emph{footnote} lines are to be numbered as well,
518 %% a little problem is the order in which main text and
519 %% footnote lines increment the absolute counter.
520 %% 'lineno''s mechanism for this is started immediately
521 %% after a paragraph has been broken into lines.
522 %% Each line of the paragraph then calls a macro
523 %% generating the line number. 'fnlineno' now interrupts
524 %% numbering of main text lines at a line issuing a footnote.
525 %% The footnote text is typeset, including numbering its
526 %% lines at each end of a footnote paragraph. When the
527 %% footnote text has been sent into the \verb|\insert| register,
528 %% numbering of main text lines is resumed.
529 %%
530 %% Up to v0.4 (a development version), we used the \emph{same}
531 %% absolute counter for main text and footnote lines.
532 %% When a page $p$ has more than one main text line and the first
533 %% one has a long footnote continued on the next page~$p+1$,
534 %% there is no ``range" of absolute line numbers
535 %% characterizing page~$p$ any more,
536 %% because the greatest absolute line number of page~$p$
537 %% exceeds the absolute line numbers of the footnote continued
538 %% on page~$p+1$.
539 %%
540 %% 'lineno''s procedure can be revived by numbering
541 %% main text lines and footnote lines independently
542 %% from each other. We use \emph{two} absolute counters,
543 %% one is incremented with main text lines only,
544 %% the other with footnote lines only.
545 %% Numbering of main text lines just will not be affected
546 %% by numbering of the footnote lines.
547 %%
548 %% Almost the same will hold for footnote lines.
549 %% Each page (and column) will have a characteristic
550 %% ``range" of absolute footnote line numbers $\{n,\dots,k\}$.
551 %% The only notable difference will be that for footnote line~$l$
552 %% we print $(l-n+1)+(K-N+1) = (K+l)-(N+n)+2$ instead of
553 %% $l-n+1$---where $\{N,\dots,K\}$ is the range of \emph{main text}
554 %% line numbers of the page (and column).
555 %%
556 %% The previous discussion of \strong{generating} the printed
557 %% line number from its absolute version
558 %% has assumed that corresponding \strong{offset} values
559 %% have been given somehow, or that the ``line number ranges"
560 %% for pages are known from somewhere.
561 %% In fact, these ranges are \strong{computed} at the
562 %% \strong{start} of a \LaTeX\ run \emph{before} typesetting,
563 %% when reading the \verb|.aux| file for the first
564 %% time. They are used in the entire document.
565 %% While typesetting, each numbered line of main text leaves
566 %% a record of its absolute number and page number in the new
567 %% version of the \verb|.aux| file that the run creates,
568 %% a two-parameter macro \verb|\@LN|. With 'fnlineno.sty',
569 %% there will be new \verb|\@FLN| entries of the same type.
570 %% These \verb|.aux| entries are used for building
571 %% the page range data for the next run.
572 %% When the document source has been changed, at least
573 %% \emph{two runs} will usually be required
574 %% to get correct line numbers in page margins,
575 %% and \emph{another} run will be needed so references
576 %% to line numbers by \verb|\ref| and \verb|\linelabel| are correct.
577 %%
578 %% ==== Summary of Changes ====
579 %% Variants of 'lineno.sty''s code for ``pagewise"
580 %% numbering are following. Sometimes we generalize
581 %% \verb|pagewise| stuff from 'lineno' and re-implement pagewise
582 %% numbering of main text lines as a special case,
583 %% the other special case being numbering of footnote lines.
584 %%
585 %% Five things need modifications:
586 %% \begin{description}
587 %% \item[Building page info macros:]
588 %% Processing \verb|\@LN| and \verb|\@FLN| \verb|.aux| entries will
589 %% use shared building macros, the difference is
590 %% obtained by switching \strong{name spaces}.
591 %% (It may be notable that a page may get one
592 %% info macro for main text and another for
593 %% footnote text, if it contains footnote text.)
594 %% \item[Logging:]
595 %% While typesetting, the shared logging macro
596 %% is switched to write either \verb|\@LN| or \verb|\@FLN|
597 %% to the \verb|.aux| file. Also, \verb|\c@linenumber|
598 %% may refer to either the main text or to the
599 %% footnote text counter.
600 %% \item[Generating ``pagewise" format:]
601 %% The choice of \verb|\c@linenumber| also determines
602 %% which counter is incremented, and again
603 %% name spaces for page info macros are switched.
604 %% For footnote lines,
605 %% a tail macro for adding the number of main text lines
606 %% will be activated.
607 %% \item[Referencing:]
608 %% The \verb|.aux| file may have entries from \verb|\linelabel|
609 %% containing large numbers from an ``absolute" counter.
610 %% In generating the ``human-readable" number,
611 %% it must be known whether it is a main text or a
612 %% footnote line number.
613 %% %% 2010/12/28:
614 %% An additional complication is referring to a
615 %% main text line from a footnote and vice versa---thinking
616 %% of global changes in generating the number.
617 %% Or even think of the case referring from unnumbered text
618 %% to numbered text!
619 %% (I have wondered before if the entry couldn't be
620 %% the ready human-readable number, TODO!)
621 %% %% 2010/12/27:
622 %% \item[Lists of ``vertical tasks":]
623 %% 'lineno.sty' (v4) has introduced two lists of
624 %% tasks that were issued in horizontal mode
625 %% but only can be completed after breaking a paragraph
626 %% into lines: one for \verb|\linelabel|s and one for \verb|\vadjust|
627 %% items that must wait until the line number has been
628 %% attached. It is essential that the tasks are processed
629 %% in the same order in vertical mode as they were
630 %% issued in horizontal mode. As we are now interrupting
631 %% processing of main text paragraphs for processing
632 %% footnotes, tasks for footnote text must be lined up
633 %% in separate lists than tasks for main text.
634 %% This is indeed essential for the previous issue
635 %% of getting \verb|\linelabel| work in footnotes as well
636 %% as in main text.
637 %% \end{description}
638 %%
639 %% ==== Info Building ====
640 %% % These macros
641 %% \verb|\@LN|, \verb|\@FLN|, and \verb|\@FNLN|
642 %% are processed at reading the \verb|.aux| file before typesetting only.
643 %% The \strong{interface} to \strong{generating}
644 %% ``pagewise" and footnote line numbers just are \verb|\LN@Pfirst|
645 %% and \verb|\FLN@Pfirst|, eventually pointing to the first page/column
646 %% with numbered main text lines or footnote lines, resp.
647 \def \FLN@Pfirst {\nextLN\relax}
648 %% This initialization of \verb|\FLN@Pfirst| is just the same
649 %% as the one of \verb\verb|\LN@Pfirst| in 'lineno.sty';
650 %% their expansions are changed as soon
651 %% as such a page is found, replacing the \verb|\relax| by the
652 %% corresponding page info macro.
653 %%
654 %% \verb|\LN@Pfirst| and \verb|\FLN@Pfirst| are passed to
655 %% \verb|\testFirstNumberedPage| via the hook \verb|\FNLN@first@numbered|
656 %% that by default is the same as \verb|\LN@first|:
657 \def \FNLN@first@numbered {\LN@Pfirst}
658 %% (oh, it must be \verb|\def| here to recognize the change ...).
659 %% This must be changed by \verb|\setfootnotelinenumbers|
660 %% (\verb|\let| then, as when called the change will have happened).
661 %%
662 %% Moreover, they are passed to \verb|\NumberedPageCache|
663 %% (the page info macro where a search starts,
664 %% ``current" page/column) as its initialization;
665 %% the ``generating" macros then change the
666 %% latter macro following \verb|\nextLN| in the page info macros.
667 %%
668 %% In this sense, no other ``name space switching" is needed
669 %% for communication with other functions.
670 %%
671 %% 'lineno.sty' has changed \verb|\LastNumberedPage| globally ...
672 %% the last page with numbered \emph{footnote} lines
673 %% may well be another one than the last page with
674 %% numbered \emph{main} text lines ...
675 %% But fortunately, also \verb|\LastNumberedPage|
676 %% is needed in reading the \verb|.aux| before typesetting only
677 %% (\verb|\@onlypreamble| is \LaTeX's disabling command):
678 \@onlypreamble\LastNumberedPage
679 %% In 'lineno.sty', we have \verb|\def\LastNumberedPage{first}|.
680 %% We need the same for the footnote variant \verb|\FNLN@last@numbered|
681 %% (to be handled globally!):
682 \global \let \FNLN@last@numbered \LastNumberedPage
683 \@onlypreamble \FNLN@last@numbered
684 %% \verb|\@FNLN{<names>}<last-numbered>{<line>}{<page>}|
685 %% \\[\smallskipamount]
686 %% generalizes 'lineno.sty''s \verb|\@LN{<line>}{<page>}|
687 %% to re-implement it.
688 %% There is an additional parameter argument <names>
689 %% for choosing name spaces
690 %% and a parameter <last-numbered> for choosing the macro
691 %% storing the ``last numbered page."
692 %% (An argument without braces expects a macro name.)
693 \newcommand* \@FNLN [4]{{%
694 \expandafter\@@LN
695 \csname #1#4C\@LN@column \expandafter\endcsname
696 \csname #1O#4\endcsname
697 {#3}{#4}{#1}{#2}}}
698 \@onlypreamble\@FNLN
699 %% As in 'lineno.sty' \verb|\@LN| calls \verb|\@@LN|, a new variant
700 %% of \verb|\@@LN| is called by \verb|\@FLN| here, but it gets one
701 %% additional parameter for passing <names>
702 %% and another for passing <last-numbered> from \verb|\@FLN|.
703 %% So the new syntax is\\[\smallskipamount]
704 %% \verb|\@@LN<info><first-page-line>{<line>}{<page>}{<names>}<last-numbered>|:
705 \renewcommand* \@@LN [6]{%
706 \ifx#1\relax
707 \ifx#2\relax\gdef#2{#3}\fi
708 \expandafter\@@@LN\csname #5#6\endcsname#1%
709 \xdef#1{\lastLN{#3}\firstLN{#3}%
710 \pageLN{#4}{\@LN@column}{#2}\nextLN\relax}%
711 \else
712 \def\lastLN##1{\noexpand\lastLN{#3}}%
713 \xdef#1{#1}%
714 \fi
715 \xdef#6{#4C\@LN@column}}
716 \@onlypreamble\@@LN
717 %% 'lineno.sty''s \verb|\@@@LN| does not need any adjustment.
718 %%
719 %% 'lineno.sty''s \verb|\@LN{<line>}{<page>}| is reimplemented as
720 \def \@LN {\@FNLN{LN@P}\LastNumberedPage}
721 %% ---so \verb|\@LN| really does the same as before, including name spaces.
722 %%
723 %% \verb|\@FLN{<line>}{<page>}| is the other special case of the
724 %% new \verb|\@FNLN|---an \verb|F| precedes the earlier names, and
725 %% \verb|\FNLN@last@numbered| is the storing macro initialized above:
726 \def \@FLN {\@FNLN{FLN@P}\FNLN@last@numbered}
727 %% For logging, we make both unexpandable: %% 2010/12/27
728 % \AtBeginDocument{\let\@LN\relax \let\@FLN\relax}
729 %% ... but this way nothing appears in the file!? TODO ...
730 \@onlypreamble\@LN \@onlypreamble\@FLN
731 %% For reading the \verb|.aux| finally, we do what
732 %% 'lineno' does with \verb|\@LN|:
733 \AtEndDocument{\let\@FLN\@gobbletwo}
734 %%
735 %% ==== Tool for Reusing Global Operations with Macros ====
736 %% %% 2010/12/28
737 %% 'lineno.sty' v4 provides list handling (changing lists globally)
738 %% and global changes of \verb|\NumberedPageCache|.
739 %% We want to use them in ``main text" mode
740 %% as well as in ``footnote" mode.
741 %% To use such an operation on <ln-macro> for <fln-macro>,
742 %% we \verb|\global\let<ln-macro><fln-macro>|, apply the operations,
743 %% and finally \verb|\global\let<fln-macro><ln-macro>|.
744 %% However, we are not only interested in how <fln-macro>
745 %% is changed this way, rather <ln-macro> also is used as input
746 %% for some operations, and we can choose which <fln-macro>
747 %% should be used as input. To switch from working on/with
748 %% <fln-1> to <fln-2> using <ln-macro> with an option
749 %% to use <fln-1> later again, a tool
750 %% \verb|\GStoreUse<ln-macro><fln-1><fln-2>| is provided
751 %% (should render later switchings much better readable):
752 \newcommand* \GStoreUse [3]{\global\let#2#1\global\let#1#3}
753 %% I.e., current content of \#1 is stored in \#2, then
754 %% \#1 attains the content of \#3.
755 %%
756 %% ==== General Settings for Typesetting Stage ====
757 %% % %% 2011/01/01: %% 2011/01/02: wrong!
758 %% % With 'ednotes', it turns out that the heading is not quite
759 %% % correct, 'ednotes'' special \verb|\newlabel| mechanism evaluates
760 %% % \verb|\getpagewiselinelabel| already for building its note
761 %% % info macros at the first reading of the \verb|.aux| file.
762 %%
763 %% %% 2010/12/27:
764 %% Oh my dear, it seems that all the switching
765 %% for the footnote variant of \verb|pagewise| must be global
766 %% (I can't find something useful using \verb|\aftergroup| quickly).
767 %% Therefore, I render 'lineno''s \verb|\setpagewisenumbers|
768 %% acting globally:
769 \renewcommand*\setpagewiselinenumbers{%
770 \global\let \theLineNumber \thePagewiseLineNumber
771 \global\let \c@linenumber \c@pagewiselinenumber
772 \global\let \makeLineNumber \makePagewiseLineNumber
773 }
774 %% I just force this, hehe ...
775 \setpagewiselinenumbers
776 %% As a counterpart to \verb|\c@pagelinenumber|,
777 %% \verb|\c@footnotelinenumber| is reserved for the
778 %% absolute footnote line numbers:
779 \newcount\c@footnotelinenumber
780 %% %% 2011/01/01 severe-bug fix, why didn't show up?:
781 %% \verb|\FNLN@@cache| stores \verb|\NumberedPageCache|
782 %% as from ``main" mode:
783 \let \FNLN@@cache \NumberedPageCache
784 %% \verb|\FNLN@cache| stores \verb|\NumberedPageCache|
785 %% as from ``footnote" mode; its initial content is the
786 %% counterpart or analogue to \verb|\LN@Pfirst|:
787 \def \FNLN@cache {\FLN@Pfirst}
788 %% %% 2010/12/28:
789 %% \verb|\FNLN@foot@cache| and \verb|\FNLN@main@cache|
790 %% switch \verb|\NumberedPageCache|:
791 \def \FNLN@foot@cache {%
792 \GStoreUse \NumberedPageCache \FNLN@@cache \FNLN@cache}
793 \def \FNLN@main@cache {%
794 \GStoreUse \NumberedPageCache \FNLN@cache \FNLN@@cache}
795 %% \verb|\FNLN@labels| will be the counterpart to
796 %% 'lineno.sty''s \verb|\@LN@labellist|:
797 \global\let \FNLN@labels \@empty
798 %% \verb|\FNLN@vadjusts| will be the counterpart to
799 %% 'lineno''s \verb|\@LN@vadjustlist|:
800 \global\let \FNLN@vadjusts \@empty
801 %% %% separation for referencing 2010/12/28:
802 %% Settings for footnote line numbers first resemble
803 %% \verb|\setpagewiselinenumbers|; but more changes
804 %% are needed, and results from main text numbering
805 %% must be stored.
806 %% Some of the settings are needed \emph{locally} for
807 %% generating numbers for labels, collected in
808 %% \verb|\setgetfootnotelinenumbers|; for this purpose
809 %% nothing must be stored explicitly:
810 \newcommand* \setgetfootnotelinenumbers {%
811 %% Change of \verb|\theLineNumber| is omitted as we are \emph{reading},
812 %% not writing a label.
813 \let\c@linenumber\c@footnotelinenumber
814 % \let\makeLineNumber\makeFootnoteLineNumber
815 %% But in fact, \verb|\makeFootnoteLineNumber| and
816 %% \verb|\makePagewiseLineNumber| will be the same.
817 %% The difference is made by the choice of
818 %% \verb|\FNLN@first@numbered| and \verb|\NumberedPageCache|
819 %% for the line range searches.
820 \let \FNLN@first@numbered \FLN@Pfirst
821 \let \FNLN@finish \FNLN@add
822 }
823 %% \verb|\setfootnotelinenumbers| performs all the settings
824 %% for typesetting footnotes in line numbering mode
825 %% \emph{globally},
826 %% including storing results from typesetting main text:
827 \newcommand* \setfootnotelinenumbers {%
828 \globaldefs\@ne
829 %% The previous line also renders \verb|\setgetfootnotelinenumbers| global:
830 \setgetfootnotelinenumbers
831 %% \verb|\theLineNumber| is used for \verb|\linelabel| entries.
832 %% \verb|\thePagewiseLineNumber| is replaced by
833 %% \verb|\theFootnoteLineNumber|:
834 \let\theLineNumber\theFootnoteLineNumber
835 %% Logging to \verb|.aux|:
836 \def \FNLN@log {\string\@FLN}%
837 %% %% 2010/12/28:
838 %% Starting range search: \verb|\NumberedPageCache|
839 \FNLN@foot@cache
840 %% Reusing 'lineno''s task list operations:
841 \GStoreUse \@LN@labellist \FNLN@@labels \FNLN@labels
842 \GStoreUse \@LN@vadjustlist \FNLN@@vadjusts \FNLN@vadjusts
843 \globaldefs\z@
844 }
845 %% For switching back to ``main text mode,"
846 %% again some settings may need a local variant---for
847 %% processing line references from footnotes to main text!
848 %% This is the purpose of \verb|\setgetpagewiselinenumbers|:
849 \newcommand* \setgetpagewiselinenumbers {%
850 \let \FNLN@first@numbered \LN@Pfirst
851 \let \FNLN@finish \@gobbletwo
852 }
853 %% \verb|\unsetfootnotelinenumbers| stores the ``current"
854 %% page with footnote lines and loads the ``most recent"
855 %% page with main text lines---and more ...:
856 \newcommand* \unsetfootnotelinenumbers {%
857 \gdef \FNLN@log {\string\@LN}%
858 \FNLN@main@cache
859 %% Task lists: %% 2010/12/28
860 \GStoreUse \@LN@labellist \FNLN@labels \FNLN@@labels
861 \GStoreUse \@LN@vadjustlist \FNLN@vadjusts \FNLN@@vadjusts
862 \globaldefs\@ne \setgetpagewiselinenumbers \globaldefs\z@ %% v0.53
863 \setpagewiselinenumbers
864 }
865 %% \verb|\makeFootnoteLineNumber| actually only copies
866 %% \verb|\makePagewiseLineNumber|, different results are obtained
867 %% be changing hooks. The command first calls
868 %% logging---\verb|\logtheLineNumber|,
869 %% then generating the ``public" line number---\verb|\getLineNumber|
870 %% (which in turn only is a copy of \verb|\testNumberedPage|
871 %% in 'lineno.sty').
872 \@ifdefinable\makeFootnoteLineNumber
873 {\let \makeFootnoteLineNumber \makePagewiseLineNumber}
874 %%
875 %% ==== Logging ====
876 %% \verb|\logtheLineNumber| is redefined to log both
877 %% main text and footnote line numbers.
878 \def \logtheLineNumber {%
879 \protected@write\@auxout{}{%
880 \FNLN@log{\the\c@linenumber}{\noexpand\the\c@LN@truepage}}}
881 %% \verb|\FNLN@log| is the hook for the difference,
882 %% its default expansion \verb|\@LN| is made for
883 %% \emph{main text} line numbers:
884 \gdef \FNLN@log {\string\@LN}
885 %%
886 %% ==== ``Public" Line Numbers ====
887 %% Fortunately, these commands don't need to know much about
888 %% name spaces. The interfaces to them are
889 %% \verb|\NumberedPageCache|---changing globally---and
890 %% \verb|\FNLN@first@numbered|. Our
891 %% \verb|\FNLN@cache| is initialized
892 %% by analogy to its counterpart \verb|\NumberedPageCache|
893 %% (a minute name space change):
894 \def \FNLN@cache {\FLN@Pfirst}
895 %% \verb|\testFirstNumberedPage{<integer>}| from 'lineno.sty'
896 %% is modified by replacing \verb|\LN@Pfirst| only:
897 \renewcommand* \testFirstNumberedPage [1]{%
898 \ifnum#1>\c@linenumber
899 \def\nextLN##1{%
900 \testNextNumberedPage\FNLN@first@numbered}%
901 \else
902 \let\nextLN\@gobble
903 \def\pageLN{\gotNumberedPage{#1}}%
904 \fi}
905 %% \verb|\testNumberedPage| and \verb|\testNextNumberedPage| from 'lineno'
906 %% don't need any modification. \verb|\testLastNumberedPage|
907 %% is modified in 'edfnotes.sty'. %% 2011/01/07
908 %%
909 %% \verb|\gotNumberedPage| just needs a closing hook
910 %% \verb|\FNLN@finish| to allow for footnote lines.
911 \renewcommand* \gotNumberedPage [4]{%
912 \oddNumberedPagefalse
913 \ifodd \if@twocolumn #3\else #2\fi\relax\oddNumberedPagetrue\fi
914 \advance\c@linenumber\@ne
915 \ifcolumnwiselinenumbers
916 \subtractlinenumberoffset{#1}%
917 \else
918 \subtractlinenumberoffset{#4}%
919 \fi
920 % \show\FNLN@finish
921 \FNLN@finish{#2}{#3}%
922 }
923 %% \verb|\FNLN@finish{<page>}{<column>}| gobbles both
924 %% arguments with \emph{main} text lines,
925 %% but will add the number of main text lines to
926 %% \emph{footnote} line numbers:
927 \global\let \FNLN@finish \@gobbletwo
928 %% Then it will act as \verb|\FNLN@add|. We run the page info macro
929 %% for the same page (column; if defined).
930 \newcommand* \FNLN@add [2]{%
931 \expandafter \let\expandafter \@tempa\csname LN@P#1C#2\endcsname
932 \ifx\@tempa\relax
933 \else
934 \advance\c@linenumber\@ne
935 \ifcolumnwiselinenumbers
936 \let\firstLN\subtractlinenumberoffset
937 %% ... rather assuming \verb|\realpagewiselinenumbers|.
938 \let\pageLN\@gobblethree
939 \else
940 \let\firstLN\@gobble
941 \def\pageLN##1##2##3{\subtractlinenumberoffset{##3}}%
942 \fi
943 \def\lastLN##1{\subtractlinenumberoffset{-##1}}%
944 \let\nextLN\@gobble
945 %% ... TODO all needed?
946 \@tempa
947 \fi
948 }
949 %%
950 %% ==== Referencing ====
951 %% Now that we are using two separate counters for main text lines
952 %% and footnote lines (v0.5), correct references to footnote lines
953 %% using \verb|\linelabel| and \verb|\ref| need further adjustments.
954 %% %
955 %% 'lineno.sty''s \verb|\thePagewiseLineNumber|
956 %% and \verb|\getpagewiselinenumber{<integer>}|
957 %% are generalized and re-implemented
958 %% % by \verb|\theWiseLineNumber| and \verb|\getwiselinenumber|
959 %% by macros that then serve to implement
960 %% referring to footnote line numbers.
961 %%
962 %% \verb|\theWiseLineNumber{<trans>}| leaves a \verb|\protect|ed call
963 %% to a one-parameter macro <trans> in the \verb|.aux| file:
964 \newcommand* \theWiseLineNumber [1]{\protect #1{\the\c@linenumber}}
965 %% \verb|\getwiselinenumber{<choice>}{<integer>}| executes <choice>
966 %% before applying \verb|\testNumberedPage| to <integer>---within
967 %% a local group:
968 \newcommand* \getwiselinenumber [2]{{%
969 %% Some wisdom is needed to take account of the current
970 %% \verb|`numbering state" from which `\ref| was called.
971 %% \begin{description}
972 %% \item[Referring to main text line:]\leavevmode
973 %% \begin{itemize}
974 %% \item Unless called from numbered footnote,
975 %% no extra care is needed.
976 %% \item If called from numbered footnote,
977 %% \verb|\setgetpagewiselinenumbers|
978 %% and temporary switching of \verb|\NumberedPageCache|
979 %% is needed.
980 %% \end{itemize}
981 %% \item[Referring to footnote line:]\leavevmode
982 %% \begin{itemize}
983 %% \item If called from numbered footnote,
984 %% no extra care is needed.
985 %% \item Otherwise, \verb|\setgetfootnotelinenumbers|
986 %% and temporary switching of \verb|\NumberedPageCache|
987 %% is needed.
988 %% \end{itemize}
989 %% \end{description}
990 \ifx#1\relax %% to main text
991 \if@FNLN@sw@ %% from footnote
992 \setgetpagewiselinenumbers
993 \FNLN@main@cache
994 \let \FNLN@restore@cache \FNLN@foot@cache
995 \fi
996 \else %% to footnote
997 \if@FNLN@sw@ \else %% from elsewhere
998 #1%
999 \FNLN@foot@cache
1000 \let \FNLN@restore@cache \FNLN@main@cache
1001 \fi
1002 \fi
1003 \c@linenumber #2\relax\testNumberedPage
1004 \thelinenumber
1005 \FNLN@restore@cache
1006 }}
1007 \let \FNLN@restore@cache \relax
1008 %% \verb|\getpagewiselinenumber| doesn't need any <choice>---we
1009 %% assume that the label was written in the default \verb|pagewise|
1010 %% mode (but it is difficult, though, \verb|\relax| is essential!):
1011 % \renewcommand* \getpagewiselinenumber {\getwiselinenumber\relax} %!!
1012 %% 2010/12/31, a compatibility problem with 'ednotes'' \verb|\newlabel|
1013 %% mechanism shows up. 'ednotes' \verb|`undefines" `\getpagewiselinenumber|
1014 %% and restores it only \verb|\AtBeginDocument|. We must ensure that
1015 %% 'ednotes' will not override our new version of
1016 %% \verb|\getpagewiselinenumber|.
1017 %% (TODO in my view another motivation to write ``ready" numbers
1018 %% without \verb|\getpagewiselinenumbers| directly.)
1019 %%
1020 %% We might assume that 'ednotes' (if at all) is loaded directly
1021 %% and loads 'lineno.sty'
1022 %% (that is the usual and recommended way of using 'ednotes')
1023 %% and that this will happen before 'fnlineno.sty' is loaded.
1024 %% But now that we have spent some time understanding the
1025 %% situation, we can deal with the case as well that 'lineno.sty'
1026 %% is loaded first, then 'fnlineno.sty' is loaded, and then 'ednotes'.
1027 %% (I have assumed earlier that 'fnlineno.sty' is loaded after
1028 %% 'lineno.sty' ...)
1029 \AtBeginDocument{%
1030 \def \getpagewiselinenumber {\getwiselinenumber\relax}% sic!
1031 \let \@EN@getpagewiselno \getpagewiselinenumber}
1032 %% For \verb|\thePagewiseLineNumber|, <trans> is \verb|\getpagewiselinenumber|:
1033 \renewcommand* \thePagewiseLineNumber {%
1034 \theWiseLineNumber\getpagewiselinenumber}
1035 %% \verb|\getfootnotelinenumber{<integer>}| considers <integer>
1036 %% the absolute number of a \emph{footnote} line. The <choice>
1037 %% therefore is \verb|\setgetfootnotelinenumbers|:
1038 \newcommand* \getfootnotelinenumber {%
1039 \getwiselinenumber\setgetfootnotelinenumbers}
1040 %% Finally, \verb|\theFootnoteLineNumber| is how \verb|\linelabel|
1041 %% refers to a \emph{footnote} line. \verb|\theWiseLineNumber|
1042 %% is called with <trans> being \verb|\getfootnotelinenumber|:
1043 \newcommand* \theFootnoteLineNumber {%
1044 \theWiseLineNumber\getfootnotelinenumber}
1045 %%
1046 %% === Leaving the Package File ===
1047 \endinput
1048 %%
1049 %% == Acknowledgements ==
1050 %% %% 2010/12/19
1051 %% On the 'texhax' mailing list, Boris Veytsman recommended
1052 %% using Victor \mbox{Eijk}\-hout's \textit{\TeX\ by Topic} to me,
1053 %% and Andrej Lapshin pointed me to David Salomon's work
1054 %% on output routines
1055 %% (TUGboat 1990 and 1994, also available as a book,
1056 %% as Ulrich Dirr tells me).
1057 %% It helped me a lot to read about output routines
1058 %% in these works, beyond the \TeX book.
1059 %% The abbreviations \lq OTR\rq\ and \lq MVL\rq\ are
1060 %% Salomon's.---And %% added 2010/12/27
1061 %% recall Christian's work and support
1062 %% by the DFG named at the start of the package file.---And
1063 %% ... the ideas of how to implement
1064 %% (\textit i)~attaching line numbers,
1065 %% (\textit{ii})~\verb|\linelabel|, and
1066 %% (\textit{iii})~numbering lines ``pagewise"---so flexibly,
1067 %% compatibly with many other \LaTeX\ packages, still
1068 %% are Stephan's ...
1069 %%
1070 %% == VERSION HISTORY ==
1071 v0.1 2010/12/08 very first, \linelabel works in footnote
1072 SENT TO Christian, problems with "long" footnotes
1073
1074 v0.2 2010/12/08 corr. "manifoot"
1075 2010/12/09 moving doc. from .tex to here,
1076 different doc. sectioning;
1077 \@footnotetext modified (user feature!);
1078 \@doclearpage NOT modified!; \if@FNLN@placing@
1079 2010/12/10 ignore dummy footnote split;
1080 \FNLNpar, \AutoPars, \ExplicitPars,
1081 more on limitations
1082 2010/12/11 more trying, almost anew ...
1083 JUST STORED
1084
1085 v0.3 2010/12/12 new approach, removed much before proceeding
1086 2010/12/13 -- this was putting \box\footins onto MVL,
1087 bad with those penalties
1088 JUST STORED
1089
1090 v0.4 2010/12/14 another new approach:
1091 typeset footnote on MVL immediately --
1092 described strategy
1093 2010/12/15 ... continued, choice of hooking into \output
1094 (...swap...)
1095 2010/12/16 ... continued; rearranged sections ...
1096 \FNLN@@fntext vs. ...ltx...
1097 2010/12/17 success with \pagegoal ...; \GStoreReg etc.;
1098 ...@fntext shortened
1099 2010/12/18 another two limitations: \pagebreak in fn.,
1100 guessed/tested; another note to <register>;
1101 ack. Christian; directed -> organized!?
1102 SENT TO Christian/Stephan
1103
1104 v0.41 2010/12/19 support of \pagebreak with \if@FNLN@sw@ etc.;
1105 TODO on lists of <register>s
1106 2010/12/20 debugging: \if...true; \setbox...ft;
1107 \@finalstrut in vmode exported to finstrut.sty;
1108 notes on how v0.41 still fails with \pagebreak
1109 2010/12/21 additional notes on *two* \pagebreak's
1110
1111 v0.5 2010/12/21 restructuring doc., check@latex@ -> check@,
1112 own account of lineno's pagewise mode
1113 2010/12/22 ... continued ...
1114 2010/12/23 ... continued ...
1115 2010/12/24 ... continued ...
1116 2010/12/25 moved this to pwlineno, replaced ...
1117 more on \FNLN@typeset, + \setfootnotelinenumbers
1118 2010/12/26 new summary of implementation,
1119 rearranged code sections; logging settled
1120 v0.51 2010/12/27 "build" settled, typesetting, logging reformated;
1121 ack.s: "recall"; all settings global,
1122 "public" works
1123 JUST STORED, MARGINAL NUMBERS OK,
1124 \linelabel in footnote broken
1125 [2010/12/28]
1126 v0.52 2010/12/28 own label and vadjust lists for footnotes;
1127 local settings for referencing,
1128 tool and care for global changes (...Cache)
1129 (TODO write ready in .aux? needs another run)
1130 \linelabel's ok, MARGINAL NOTES MAIN BROKEN
1131 v0.53 2010/12/28 debugging; OK; minor doc. modifications;
1132 less "limitations"; \\[\smallskipamount]
1133 TO CHRISTIAN 2010-12-29
1134 v0.54 2010/12/31 typo options; \FNLN@text without arg,
1135 \getpagewiselinenumber with ednotes
1136 2011/01/01 \FNLN@cache, \FNLN@@cache initialized;
1137 doc. "Typesetting Stage" qualification
1138 2011/01/02 that qualification was wrong
1139 2011/01/03 samepage@hook
1140 TO CHRISTIAN SAME DAY
1141 v0.55 2011/01/04 samepage@hook emptied here as well;
1142 2011/01/06 edited version history
1143 2011/01/07 note on \if@FNLN@sw@ with v0.5;
1144 finally without support for samepage@hook!
1145 note on \testLastNumberedPage
1146 PART OF EDFN RELEASE r0.5 (together with edfnotes v0.2)
1147 v0.55a 2011/02/09 corr. owner; "Limitations" updated; \pagebreak