summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/page-lin.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/page-lin.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/page-lin.mkiv286
1 files changed, 173 insertions, 113 deletions
diff --git a/Master/texmf-dist/tex/context/base/page-lin.mkiv b/Master/texmf-dist/tex/context/base/page-lin.mkiv
index c82d4d5206e..51f02763985 100644
--- a/Master/texmf-dist/tex/context/base/page-lin.mkiv
+++ b/Master/texmf-dist/tex/context/base/page-lin.mkiv
@@ -17,15 +17,17 @@
\unprotect
+% todo: save settings
+
% low level interface
\registerctxluafile{page-lin}{1.001}
-\definesystemattribute[line-number]
-\definesystemattribute[line-reference]
+\definesystemattribute[line-number] \chardef\linenumberattribute \dogetattributeid{line-number}
+\definesystemattribute[line-reference] \chardef\linereferenceattribute \dogetattributeid{line-reference}
-\appendtoksonce\doresetattribute{line-number}\to\everyforgetall
-\appendtoksonce\dosetattribute{display-math}{1}\to\everybeforedisplayformula
+\appendtoksonce \attribute\linenumberattribute \attributeunsetvalue \to \everyforgetall
+\appendtoksonce \attribute\displaymathattribute\plusone \to \everybeforedisplayformula
\newcount\linenumber
\newbox \linenumberscratchbox
@@ -34,34 +36,17 @@
\newconditional\tracelinenumbering
-\def\mkaddtextlinenumbers#1#2#3% box col max
- {\bgroup
- \def\skipnumber{\hbox{}}%
- \ifcase#3\relax
- \let\makenumber\mkskiplinenumber
- \or
- \let\makenumber\mkleftlinenumber
- \else\ifcase#2\relax
- \let\makenumber\mkskiplinenumber
- \or
- \let\makenumber\mkleftlinenumber
- \else
- \let\makenumber\mkrightlinenumber
- \fi\fi
- \mkprocesstextlinenumbers{#1}%
- \egroup}
-
\def\mkprocesstextlinenumbers#1%
{\setbox\linenumberscratchbox\vbox{\forgetall\offinterlineskip\ctxlua{nodes.lines.boxed.stage_one(\number#1)}}%
\ctxlua{nodes.lines.boxed.stage_two(\number#1,\number\linenumberscratchbox)}}% can move to lua code
-% id nr shift width leftskip
+% id nr shift width leftskip dir
-\def\mkskiplinenumber #1#2#3#4#5{}
-\def\mkleftlinenumber #1#2#3#4#5{\hbox{\llap{#2\quad\hskip#3\scaledpoint}}}
-\def\mkrightlinenumber#1#2#3#4#5{\hbox{\rlap{\hskip#4\scaledpoint\hskip#3\scaledpoint\quad#2}}}
+% \def\mkskiplinenumber #1#2#3#4#6#5{}
+% \def\mkleftlinenumber #1#2#3#4#5#6{\hbox{\llap{#2\quad\hskip#3\scaledpoint}}}
+% \def\mkrightlinenumber#1#2#3#4#5#6{\hbox{\rlap{\hskip#4\scaledpoint\hskip#3\scaledpoint\quad#2}}}
-\def\makenumber#1#2{\hbox{\llap{#1\quad\hskip#2\scaledpoint}}\endgraf}%
+\let\makenumber\gobblesixarguments
\newconditional\boxcontentneedsprocessing
@@ -69,38 +54,54 @@
\def\mkdoprocessboxcontents #1{\mkaddtextlinenumbers{#1}\plusone \plusone}
\def\mkdoprocesscolumncontents#1{\mkaddtextlinenumbers{#1}\currentcolumn\nofcolumns}
-\def\mkcurrentstart{0}
-\def\mkcurrentstep {1}
+\def\mklinenumberparameters
+ {continue = "\linenumberparameter\c!continue",
+ start = \linenumberparameter\c!start,
+ step = \linenumberparameter\c!step,
+ method = "\linenumberparameter\c!method",
+ tag = "\currentlinenumbering"}
-\def\mkdefinetextlinenumbering#1%
- {\begingroup
- \scratchcounter\ctxlua{tex.sprint(nodes.lines.boxed.register({start=\mkcurrentstart,step=\mkcurrentstep,tag="#1"}))}%
- \setxvalue{ln:c:#1}{\number\scratchcounter}%
- \endgroup}
+\def\mklinenumberupdateparameters
+ {continue = "\linenumberparameter\c!continue"}
+
+\def\mkdefinetextlinenumbering
+ {\setxvalue{ln:c:\currentlinenumbering}{\number\ctxlua{tex.sprint(nodes.lines.boxed.register({\mklinenumberparameters}))}}}
-\def\mkstarttextlinenumbering#1#2%
+\def\mkupdatetextlinenumbering
+ {\ctxlua{nodes.lines.boxed.setup(\getvalue{ln:c:\currentlinenumbering},{\mklinenumberupdateparameters})}}
+
+\def\mkstarttextlinenumbering#1#2% always when assignment
{\globallet\mkprocesspagecontents \mkdoprocesspagecontents
\globallet\mkprocesscolumncontents\mkdoprocesscolumncontents
\global\settrue\boxcontentneedsprocessing % see core-rul.mkiv
+ \edef\currentlinenumbering{#1}%
\ifcase#2\relax
- % continue
+ \mkupdatetextlinenumbering % continue
\or
- \mkdefinetextlinenumbering{#1}% restart
+ \mkdefinetextlinenumbering % only when assignment
\fi
- \dosetattribute{line-number}{\getvalue{ln:c:#1}}}
+ \attribute\linenumberattribute\getvalue{ln:c:\currentlinenumbering}\relax}
-\def\mksetuptextlinenumbering#1%
- {\ctxlua{nodes.lines.boxed.setup(\getvalue{ln:c:#1},{start=\mkcurrentstart,step=\mkcurrentstep,tag="#1"})}}
+\def\mksetuptextlinenumbering
+ {\ifcsname ln:c:\currentlinenumbering\endcsname
+ \ctxlua{nodes.lines.boxed.setup(\getvalue{ln:c:\currentlinenumbering},{\mklinenumberparameters})}%
+ \fi}
\def\mkstoptextlinenumbering
- {\doresetattribute{line-number}}
+ {\attribute\linenumberattribute\attributeunsetvalue}
+
+% we could make this a bit more efficient by putting the end reference
+% in the same table as the start one but why make things complex ...
+
+\let\dofinishlinereference\dofinishfullreference
\def\mksomelinereference#1#2#3%
{\dontleavehmode\begingroup
\global\advance\linerefcounter\plusone
- \dosetattribute{line-reference}\linerefcounter
- % this will change and is troublesome anyway
- #3\textreference[#2]{\noexpand\ctxlua{tex.sprint(nodes.lines.number(\the\linerefcounter))}}%
+ \attribute\linereferenceattribute\linerefcounter
+ #3%
+ % for the moment we use a simple system i.e. no prefixes etc .. todo: store as number
+ \expanded{\dodosetreference{line}{#2}{conversion=\linenumberparameter\c!conversion}{\the\linerefcounter}}% kind labels userdata text
\endgroup}
\def\mkstartlinereference#1{\mksomelinereference{#1}{lr:b:#1}{}\ignorespaces}
@@ -117,7 +118,7 @@
\let\currentlinenumbering\empty
\chardef\linenumbermode = 1 % 0=continue, 1=restart
-\chardef\linenumberlocation = 1 % 0=middle, 1=left, 2=right, 3=inner, 4=outer, 5=text
+\chardef\linenumberlocation = 1 % 0=middle, 1=left, 2=right, 3=inner, 4=outer, 5=text, 6=begin, 7=end
\chardef\linenumberalignment = 5 % 0=middle, 1=left, 2=right, 5=auto
\newevery \beforeeverylinenumbering \relax
@@ -127,14 +128,14 @@
\newdimen\linenumberwidth
\newdimen\linenumberdistance
-\def\definelinenumbering
+\unexpanded\def\definelinenumbering
{\dosingleempty\dodefinelinenumbering}
\def\dodefinelinenumbering[#1]%
- {\def\currentlinenumbering{#1}%
- \mkdefinetextlinenumbering\currentlinenumbering}
+ {\edef\currentlinenumbering{#1}%
+ \mkdefinetextlinenumbering}
-\def\setuplinenumbering
+\unexpanded\def\setuplinenumbering
{\dodoubleempty\dosetuplinenumbering}
\def\dosetuplinenumbering[#1][#2]%
@@ -145,7 +146,7 @@
\let\currentlinenumbering\empty
\getparameters[\??rn][#1]%
\fi
- \mksetuptextlinenumbering\currentlinenumbering}
+ \mksetuptextlinenumbering}
\def\linenumberparameter#1%
{\csname\??rn\ifcsname\??rn\currentlinenumbering#1\endcsname\currentlinenumbering\fi#1\endcsname}
@@ -153,13 +154,12 @@
\def\linenumberattributes
{\doattributes{\??rn\ifcsname\??rn\currentlinenumbering\c!style\endcsname\currentlinenumbering\fi}}
-\definelinenumbering
-
\setuplinenumbering
[\c!conversion=\v!numbers,
\c!start=1,
\c!step=1,
- \c!continue=v!no,
+ \c!method=\v!first,
+ \c!continue=\v!no,
\c!location=\v!left,
\c!style=,
\c!color=,
@@ -170,15 +170,14 @@
\c!distance=\zeropoint,
\c!align=\v!auto]
-\def\startlinenumbering
+\definelinenumbering
+
+\unexpanded\def\startlinenumbering
{\dodoubleempty\dostartlinenumbering}
% no intermediate changes in values, define a class, otherwise each range
% would need a number
-\def\mkcurrentstart{\linenumberparameter\c!start}
-\def\mkcurrentstep {\linenumberparameter\c!step }
-
% todo: text
\expandafter\chardef\csname\??rn:l:\v!middle \endcsname \zerocount
@@ -191,6 +190,8 @@
\expandafter\chardef\csname\??rn:l:\v!inner \endcsname \plusthree
\expandafter\chardef\csname\??rn:l:\v!outer \endcsname \plusfour
\expandafter\chardef\csname\??rn:l:\v!text \endcsname \plusfive
+\expandafter\chardef\csname\??rn:l:\v!begin \endcsname \plussix
+\expandafter\chardef\csname\??rn:l:\v!end \endcsname \plusseven
\expandafter\chardef\csname\??rn:a:\v!middle \endcsname \zerocount
\expandafter\chardef\csname\??rn:a:\v!right \endcsname \plusone
@@ -204,32 +205,37 @@
\chardef\linenumbermode\plusone
\ifsecondargument
\def\currentlinenumbering{#1}%
- \doifnumberelse{#2}% downward compatible
- {\setvalue{\??rn#1\c!start}{#2}}%
- {\doif{#2}\v!continue{\chardef\linenumbermode\zerocount}}%
+ \doifassignmentelse{#2}
+ {\getparameters[\??rn\currentlinenumbering][#2]}
+ {\doifnumberelse{#2}% downward compatible
+ {\setvalue{\??rn#1\c!start}{#2}}%
+ {\doif{#2}\v!continue
+ {\getparameters[\??rn\currentlinenumbering][\c!continue=\v!yes]%
+ \chardef\linenumbermode\zerocount}}}%
\else\iffirstargument
\doifnumberelse{#1}% downward compatible
{\let\currentlinenumbering\empty
\setvalue{\??rn\c!start}{#1}}%
{\doifelse{#1}\v!continue
{\let\currentlinenumbering\empty
+ \getparameters[\??rn\currentlinenumbering][\c!continue=\v!yes]%
\chardef\linenumbermode\zerocount}
{\def\currentlinenumbering{#1}}}%
\fi\fi
- \doifelse{\linenumberparameter\c!continue}\v!yes
+ \doif{\linenumberparameter\c!continue}\v!yes
{\chardef\linenumbermode\zerocount}%
\numberinglinestrue
\the\beforeeverylinenumbering
\mkstarttextlinenumbering\currentlinenumbering\linenumbermode}
-\def\stoplinenumbering
+\unexpanded\def\stoplinenumbering
{\mkstoptextlinenumbering
\the\aftereverylinenumbering
\endgroup}
% number placement
-\let\mkskiplinenumber \gobblefivearguments
+\let\mkskiplinenumber \gobblesixarguments
\def\mkdoinnerlinenumber{\doifoddpageelse\mkdoleftlinenumber\mkdorightlinenumber}
\def\mkdoouterlinenumber{\doifoddpageelse\mkdorightlinenumber\mkdoleftlinenumber}
@@ -245,6 +251,12 @@
\expandafter\mkdoinnerlinenumber
\or
\expandafter\mkdoouterlinenumber
+ \or
+ \expandafter\mkdotextlinenumber
+ \or
+ \expandafter\mkdobeginlinenumber
+ \or
+ \expandafter\mkdoendlinenumber
\fi}
\def\mkrightlinenumber
@@ -258,32 +270,72 @@
\expandafter\mkdoouterlinenumber
\or
\expandafter\mkdoinnerlinenumber
+ \or
+ \expandafter\mkdotextlinenumber
+ \or
+ \expandafter\mkdoendlinenumber
+ \or
+ \expandafter\mkdobeginlinenumber
\fi}
\def\mkaddtextlinenumbers#1#2#3% box col max
{\bgroup
+ \chardef\linenumberbox #1\relax
+ \chardef\linenumbercolumn #2\relax
+ \chardef\linenumberlastcolumn#3\relax
+ \fullrestoreglobalbodyfont
\def\skipnumber{\hbox{}}%
- \ifcase#3\relax
- \let\makenumber\mkskiplinenumber
+ \let\makenumber\maketextlinenumber
+ \mkprocesstextlinenumbers\linenumberbox
+ \egroup}
+
+\def\maketextlinenumber#1%
+ {\edef\currentlinenumbering{#1}%
+ \chardef\linenumberlocation \executeifdefined{\??rn:l:\linenumberparameter\c!location}\plusone % left
+ \chardef\linenumberalignment\executeifdefined{\??rn:a:\linenumberparameter\c!align }\plusfive % auto
+ \ifcase\linenumberlastcolumn\relax
+ \let\domakenumber\mkskiplinenumber
\or
- \let\makenumber\mkleftlinenumber
- \else\ifcase#2\relax
- \let\makenumber\mkskiplinenumber
+ % one column
+ \ifcase\linenumberlocation
+ \let\domakenumber\mkskiplinenumber
+ % hm
+ \or
+ \let\domakenumber\mkleftlinenumber
+ \or
+ \let\domakenumber\mkrightlinenumber
+ \or % inner
+ \let\domakenumber\mkdoinnerlinenumber
+ \or % outer
+ \let\domakenumber\mkdoouterlinenumber
+ \or % text
+ \let\domakenumber\mkdotextlinenumber
+ \or
+ \let\domakenumber\mkdobeginlinenumber
+ \or
+ \let\domakenumber\mkdoendlinenumber
+ \fi
+ \else\ifcase\linenumbercolumn\relax
+ \let\domakenumber\mkskiplinenumber
\or
- \let\makenumber\mkdoleftlinenumber
+ \let\domakenumber\mkleftlinenumber
\ifcase\linenumberlocation\or
\chardef\linenumberlocation\plusone
\or
\chardef\linenumberlocation\plustwo
- \or
+ \else
\chardef\linenumberlocation\plusone
\or
\chardef\linenumberlocation\plusone
\or
\chardef\linenumberlocation\plusone
+ \or
+ \chardef\linenumberlocation\plusone % todo
+ \or
+ \chardef\linenumberlocation\plusone % todo
\fi
\else
- \let\makenumber\mkdorightlinenumber
+ \let\domakenumber\mkrightlinenumber
\ifcase\linenumberlocation\or
\chardef\linenumberlocation\plustwo
\or
@@ -292,21 +344,52 @@
\chardef\linenumberlocation\plustwo
\or
\chardef\linenumberlocation\plustwo
+ \or
+ \chardef\linenumberlocation\plustwo % todo
+ \or
+ \chardef\linenumberlocation\plustwo % todo
\fi
\fi\fi
- \mkprocesstextlinenumbers{#1}%
- \egroup}
+ \domakenumber{#1}}
-\def\mkdoleftlinenumber #1#2#3#4#5%
- {\hbox{\llap{\dosomelinenumber{#1}{2}{#2}{#5}\hskip#3\scaledpoint}}}
-\def\mkdorightlinenumber#1#2#3#4#5%
- {\hbox{\rlap{\hskip#4\scaledpoint\hskip#3\scaledpoint\dosomelinenumber{#1}{1}{#2}{#5}}}}
+\def\mkdotextlinenumber #1#2#3#4#5#6% beware, one needs so compensate for this in the width !
+ {\hbox{\dosomelinenumber{#1}{2}{#2}{#5}\hskip#3\scaledpoint}}
+
+\def\mkdotextlinenumber #1#2#3#4#5#6% beware, one needs so compensate for this in the width !
+ {\hbox{\dosomelinenumber{#1}{2}{#2}{#5}\hskip#3\scaledpoint}}
+
+\def\mkdoleftlinenumber #1#2#3#4#5#6%
+ {\naturalhbox to \zeropoint
+ {\ifcase\istltdir#6\else \hskip-#4\scaledpoint \fi
+ \llap{\dosomelinenumber{#1}{2}{#2}{#5}\kern#3\scaledpoint}}}
+
+\def\mkdorightlinenumber#1#2#3#4#5#6%
+ {\naturalhbox to \zeropoint
+ {\ifcase\istltdir#6\else \hskip-#4\scaledpoint \fi
+ \rlap{\hskip#4\scaledpoint\hskip#3\scaledpoint\dosomelinenumber{#1}{1}{#2}{#5}}}}
+
+\def\mkdobeginlinenumber #1#2#3#4#5#6%
+ {\ifcase\istltdir#6\relax
+ \chardef\linenumberlocation\plusone
+ \expandafter\mkdoleftlinenumber
+ \else
+ \chardef\linenumberlocation\plustwo
+ \expandafter\mkdorightlinenumber
+ \fi{#1}{#2}{#3}{#4}{#5}{#6}}
+
+\def\mkdoendlinenumber#1#2#3#4#5#6%
+ {\ifcase\istltdir#6\relax
+ \chardef\linenumberlocation\plustwo
+ \expandafter\mkdorightlinenumber
+ \else
+ \chardef\linenumberlocation\plusone
+ \expandafter\mkdoleftlinenumber
+ \fi{#1}{#2}{#3}{#4}{#5}{#6}}
\def\dosomelinenumber#1#2#3#4% tag 1=left|2=right linenumber leftskip
{\begingroup
\def\currentlinenumbering{#1}%
- \chardef\linenumberlocation \executeifdefined{\??rn:l:\linenumberparameter\c!location}\plusone % left
- \chardef\linenumberalignment\executeifdefined{\??rn:a:\linenumberparameter\c!align }\plusfive % auto
+ \def\linenumber{#3}% unsafe
\doifelse{\linenumberparameter\c!width}\v!margin
{\linenumberwidth\leftmarginwidth}
{\linenumberwidth\linenumberparameter\c!width}%
@@ -365,8 +448,8 @@
% referencing
\def\someline [#1]{\mkstartlinereference{#1}\mkstoplinereference{#1}}
-\def\startline[#1]{\mkstartlinereference{#1}}
-\def\stopline [#1]{\mkstoplinereference {#1}}
+\unexpanded\def\startline[#1]{\mkstartlinereference{#1}}
+\unexpanded\def\stopline [#1]{\mkstoplinereference {#1}}
\def\mkshowstartlinereference#1%
{\ifconditional\tracelinenumbering
@@ -386,11 +469,14 @@
% eventually we will do this in lua
+\def\currentreferencelinenumber{\ctxlua{jobreferences.filter("linenumber")}}
+
\def\doifelsesamelinereference#1#2#3%
{\doifreferencefoundelse{lr:b:#1}
- {\let\fline\currenttextreference
+ {\edef\fline{\currentreferencelinenumber}%
\doifreferencefoundelse{lr:e:#1}
- {\let\tline\currenttextreference
+ {\edef\tline{\currentreferencelinenumber}%
+ %[\fline,\tline]
\ifx\fline\tline#2\else#3\fi}
{\unknownreference{#1}#2}}
{\unknownreference{#1}#2}}
@@ -404,35 +490,9 @@
{\in{#1}[lr:b:#2]}
{\in{#1}[lr:b:#2]--\in[lr:e:#2]}}}
-\protect \endinput
-
-\iffalse % \iftrue
-
- \appendtoks\ctxlua{nodes.lines.flowed.prepare()}\to\everyshipout
- \appendtoks\ctxlua{nodes.lines.flowed.cleanup()}\to\everybye
-
- \def\mkstarttextlinenumbering#1#2%
- {\ctxlua{nodes.lines.flowed.prepare("#1")}%
- \dosetattribute{line-number}{#2}}
+\def\inlinerange[#1]%
+ {\doifelsesamelinereference{#1}
+ {\in[lr:b:#1]}
+ {\in[lr:b:#1]--\in[lr:e:#1]}}
- \def\mkstoptextlinenumbering
- {\doresetattribute{line-number}}
-
- \def\mkmaketextlinenumber#1#2%
- {\hbox \bgroup
- \ifcase#2\relax
- %
- \or
- \llap{#1\quad\hskip#2\scaledpoint}%
- \else
- \rlap{\hskip\textwidth\quad#1\hskip#2\scaledpoint}%
- \fi
- \egroup}
-
- \ctxlua{
- nodes.lines.scratchbox = \number\linenumberscratchbox ;
- % callback.register('vpack_filter', nodes.lines.flowed.apply)
- callback.register('post_linebreak_filter', nodes.lines.flowed.apply)
- }
-
-\fi
+\protect \endinput