summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/strc-reg.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-reg.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/strc-reg.mkiv282
1 files changed, 222 insertions, 60 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-reg.mkiv b/Master/texmf-dist/tex/context/base/strc-reg.mkiv
index 2ec448d97fe..fcc37549c44 100644
--- a/Master/texmf-dist/tex/context/base/strc-reg.mkiv
+++ b/Master/texmf-dist/tex/context/base/strc-reg.mkiv
@@ -57,14 +57,14 @@
\def\detokenizedregisterparameter#1{\detokenize\expandafter\expandafter\expandafter{\csname\??id#1\endcsname}} % always root
-\def\registerparameter #1{\csname\doregisterparameter{\??id\currentregister}#1\endcsname}
+\def\registerparameter #1{\csname\doregisterparameter{\??id\currentregister}{#1}\endcsname}
\def\registerparameterhash#1{\doregisterparameterhash {\??id\currentregister}#1}
-\def\doregisterparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\doregisterparentparameter \csname#1\s!parent\endcsname#2\fi}
-\def\doregisterparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\doregisterparentparameterhash\csname#1\s!parent\endcsname#2\fi}
+\def\doregisterparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\doregisterparentparameter \csname#1\s!parent\endcsname{#2}\fi}
+\def\doregisterparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\doregisterparentparameterhash\csname#1\s!parent\endcsname{#2}\fi}
-\def\doregisterparentparameter #1#2{\ifx#1\relax\s!empty\else\doregisterparameter #1#2\fi}
-\def\doregisterparentparameterhash#1#2{\ifx#1\relax \else\doregisterparameterhash#1#2\fi}
+\def\doregisterparentparameter #1#2{\ifx#1\relax\s!empty\else\doregisterparameter #1{#2}\fi}
+\def\doregisterparentparameterhash#1#2{\ifx#1\relax \else\doregisterparameterhash#1{#2}\fi}
\def\dosetregisterattributes#1#2% style color
{\edef\fontattributehash {\registerparameterhash#1}%
@@ -76,7 +76,7 @@
\newtoks\everysetupregister
-\def\setupregisters
+\unexpanded\def\setupregisters
{\dotripleempty\dosetupregisters}
\def\dosetupregisters[#1][#2][#3]%
@@ -116,6 +116,7 @@
\c!unknownreference=\v!empty,
\c!prefix=\v!both,
%\c!expansion=,
+%\c!xmlsetup=,
\c!pageprefixconnector=\endash,
\c!pagesegments=2:2,
\c!file=\jobname,
@@ -124,16 +125,16 @@
%D Definition:
-\def\defineregister
+\unexpanded\def\defineregister
{\dodoubleargument\dodefineregister}
\def\dodefineregister[#1][#2]% #2?
{\setupregister[#1][\s!parent=\??id]%
\ctxlua{jobregisters.define('#1')}%
\presetheadtext[#1=\Word{#1}]%
- \unexpanded\setvalue{#1}{\dodoubleempty\doregister[#1]}%
- \unexpanded\setvalue{\e!see#1}{\dodoubleempty\doseeregister[#1]}%
-% \unexpanded\setvalue{\e!coupled#1}{\dolinkedregister{#1}}%
+ \setuvalue{#1}{\dodoubleempty\doregister[#1]}%
+ \setuvalue{\e!see#1}{\dodoubleempty\doseeregister[#1]}%
+% \setuvalue{\e!coupled#1}{\dolinkedregister{#1}}%
\setvalue{\e!place#1}{\placeregister[#1]}%
\setvalue{\e!complete#1}{\completeregister[#1]}%
\setvalue{\e!setup#1\e!endsetup}[##1]{\getparameters[\??id#1][##1]}}
@@ -144,32 +145,85 @@
% tzt variant met n entries, parameters en userdata (altnum)
-\def\doregisterstructurepageregister#1#2#3% register data userdata
+\getparameters
+ [\??id]
+ [\c!label=,
+ \c!entries=,
+ \c!entries:1=,\c!entries:2=,\c!entries:3=,
+ \c!keys:1=,\c!keys:2=,\c!keys:3=,
+ \c!alternative=]
+
+\def\doregisterstructurepageregister
+ {\iftrialtypesetting
+ \expandafter\gobblethreearguments
+ \else
+ \expandafter\dodoregisterstructurepageregister
+ \fi}
+
+\def\dodoregisterstructurepageregister#1#2#3% register data userdata
{\begingroup
\edef\currentregister{#1}%
- \getparameters[\??id][\c!entries=,\c!label=,\c!keys=,\c!alternative=,#2]%
+ %getparameters[\??id][\c!entries=,\c!label=,\c!keys=,\c!alternative=,#2]%
+ \getparameters[\??id][#2]%
\edef\currentregisterlabel {\registerparameter\c!label}%
\edef\currentregisterexpansion{\registerparameter\c!expansion}%
\edef\currentregisterownnumber{\registerparameter\c!ownnumber}%
\xdef\currentregisterkeys {\registerparameter\c!keys}%
- \ifx\currentregisterexpansion\s!xml
- \xmlstartraw
- \xdef\currentregisterentries{\registerparameter\c!entries}%
- \xmlstopraw
- \globallet\currentregistercoding\s!xml
+ \xdef\currentregisterentries {\registerparameter\c!entries}%
+ \xdef\currentregisterxmlsetup {\registerparameter\c!xmlsetup}%
+ \ifx\currentregisterentries\empty
+ \ifx\currentregisterexpansion\s!xml
+ \xmlstartraw
+ \xdef\currentregisterentriesa{\registerparameter{\c!entries:1}}%
+ \xdef\currentregisterentriesb{\registerparameter{\c!entries:2}}%
+ \xdef\currentregisterentriesc{\registerparameter{\c!entries:3}}%
+ \xmlstopraw
+ \globallet\currentregistercoding\s!xml
+ \else
+ \ifx\currentregisterexpansion\v!yes
+ \xdef\currentregisterentriesa{\registerparameter{\c!entries:1}}%
+ \xdef\currentregisterentriesb{\registerparameter{\c!entries:2}}%
+ \xdef\currentregisterentriesc{\registerparameter{\c!entries:3}}%
+ \else
+ \xdef\currentregisterentriesa{\detokenizedregisterparameter{\c!entries:1}}%
+ \xdef\currentregisterentriesb{\detokenizedregisterparameter{\c!entries:2}}%
+ \xdef\currentregisterentriesc{\detokenizedregisterparameter{\c!entries:3}}%
+ \fi
+ \globallet\currentregistercoding\s!tex
+ \fi
\else
- \ifx\currentregisterexpansion\v!yes
- \xdef\currentregisterentries{\registerparameter\c!entries}%
+ \ifx\currentregisterexpansion\s!xml
+ \xmlstartraw
+ \xdef\currentregisterentries{\registerparameter\c!entries}%
+ \xmlstopraw
+ \globallet\currentregistercoding\s!xml
\else
- \xdef\currentregisterentries{\detokenizedregisterparameter\c!entries}%
+ \ifx\currentregisterexpansion\v!yes
+ \xdef\currentregisterentries{\registerparameter\c!entries}%
+ \else
+ \xdef\currentregisterentries{\detokenizedregisterparameter\c!entries}%
+ \fi
+ \globallet\currentregistercoding\s!tex
+ \fi
+ \fi
+ \ifx\currentregisterkeys\empty
+ \ifx\currentregistercoding\s!xml
+ \xmlstartraw
+ \xdef\currentregisterkeysa{\registerparameter{\c!keys:1}}%
+ \xdef\currentregisterkeysb{\registerparameter{\c!keys:2}}%
+ \xdef\currentregisterkeysc{\registerparameter{\c!keys:3}}%
+ \xmlstopraw
+ \else
+ \xdef\currentregisterkeysa{\registerparameter{\c!keys:1}}%
+ \xdef\currentregisterkeysb{\registerparameter{\c!keys:2}}%
+ \xdef\currentregisterkeysc{\registerparameter{\c!keys:3}}%
\fi
- \globallet\currentregistercoding\s!tex
\fi
\setnextinternalreference
% we could consider storing register entries in a list which we
% could then sort
\xdef\currentregisternumber{\ctxlua{
- jobregisters.store {
+ jobregisters.store { % 'own' should not be in metadata
metadata = {
kind = "entry",
name = "\currentregister",
@@ -179,18 +233,31 @@
\ifx\currentregisterownnumber\v!yes
own = "\registerparameter\c!alternative", % can be used instead of pagenumber
\fi
+ xmlroot = \ifx\currentreferencecoding\s!xml "\xmldocument" \else nil \fi, % only useful when text
+\ifx\currentregisterxmlsetup\empty \else
+ xmlsetup = "\currentregisterxmlsetup",
+\fi
},
references = {
internal = \nextinternalreference,
- section = structure.sections.currentid(), % hm, why then not also lastsection the same way
- label = "\currentregisterlabel",
+ section = structure.sections.currentid(), % hm, why then not also lastsection the same way
+ label = "\currentregisterlabel",
},
- \ifx\currentregisterentries\empty \else
+% \ifx\currentregisterentries\empty \else
entries = {
% we need a special one for xml, this is just a single one
- \!!bs\currentregisterentries\!!es, \!!bs\currentregisterkeys\!!es
+ \ifx\currentregisterentries\empty
+ { \!!bs\currentregisterentriesa\!!es, \!!bs\currentregisterentriesb\!!es, \!!bs\currentregisterentriesc\!!es },
+ \else
+ \!!bs\currentregisterentries\!!es,
+ \fi
+ \ifx\currentregisterkeys\empty
+ { \!!bs\currentregisterkeysa\!!es, \!!bs\currentregisterkeysb\!!es, \!!bs\currentregisterkeysc\!!es },
+ \else
+ \!!bs\currentregisterkeys\!!es,
+ \fi
},
- \fi
+% \fi
userdata = structure.helpers.touserdata(\!!bs\detokenize{#3}\!!es)
}
} }%
@@ -201,7 +268,7 @@
\xdef\currentregistersynchronize{\ctxlatelua{jobregisters.enhance("\currentregister",\currentregisternumber)}}%
\fi
\currentregistersynchronize % here?
- \attribute\destinationattribute\lastdestinationattribute \strut % todo
+ \attribute\destinationattribute\lastdestinationattribute \forcecolorhack % no \strut as it will be removed during cleanup
\endgroup}
\def\doregister[#1][#2]%
@@ -211,8 +278,8 @@
\def\donoregister #1#2#3{\doflushatpar{\doregisterstructurepageregister{#1}{\c!keys={#2},\c!entries={#3}}{}}}
\def\dodoregister#1#2#3#4{\doflushatpar{\doregisterstructurepageregister{#1}{\c!keys={#2},\c!alternative=#3,\c!entries={#4}}{}}}
-\def\startregister{\doquadrupleempty\dostartregister}
-\def\stopregister {\dodoubleargument\dostopregister}
+\unexpanded\def\startregister{\doquadrupleempty\dostartregister}
+\unexpanded\def\stopregister {\dodoubleargument\dostopregister}
% a synonym, so that we can nest with overlap without syntax check problems
@@ -234,6 +301,8 @@
\def\setregisterentry {\dotripleempty\dosetregisterentry}
\def\finishregisterentry{\dotripleempty\dofinishregisterentry}
+% not yet document, not sure if this will stay:
+
\def\dosetregisterentry [#1][#2][#3]{\doflushatpar{\doregisterstructurepageregister{#1}{#2}{#3}}}
\def\dofinishregisterentry[#1][#2][#3]{\dofinishregisterstructurepageregister{#1}{#2}{#3}}
@@ -287,6 +356,41 @@
\fi
\endgroup}
+% The following variants are meant for (for instance xml). There is some
+% overlap with previously defined macros.
+%
+% \starttext
+% \setstructurepageregister[index][entries=alpha]a
+% \setstructurepageregister[index][entries=gamma]g
+% \setstructurepageregister[index][entries=beta]b
+% \setstructurepageregister[index][entries:1=alpha,keys:1=z]a
+% \setstructurepageregister[index][entries:1=gamma,keys:1=x]g
+% \setstructurepageregister[index][entries:1=beta, keys:1=y]b
+% \index{alpha}a
+% \index{gamma}g
+% \index{beta}b
+% \placeregister[index][n=1]
+% \stoptext
+
+\def\setstructurepageregister{\dotripleempty\dosetstructurepageregister}
+
+\def\dosetstructurepageregister[#1][#2][#3]% [register][settings][userdata]
+ {\doflushatpar{\doregisterstructurepageregister{#1}{#2}{#3}}}
+
+\unexpanded\def\startstructurepageregister{\doquadrupleempty\dostartstructurepageregister}
+\unexpanded\def\stopstructurepageregister {\dodoubleargument\dostopstructurepageregister}
+
+\let\openstructurepageregisterrange \startstructurepageregister
+\let\closestructurepageregisterrange\stopstructurepageregister
+
+\def\dostartstructurepageregister[#1][#2][#3][#4]% [register][tag][settings][userdata]
+ {\doflushatpar{\doregisterstructurepageregister{#1}{\c!label=#2,#3}{#4}}}
+
+\def\dostopstructurepageregister[#1][#2]%
+ {\normalexpanded{\ctxlatelua{jobregisters.extend("#1","#2")}}}
+
+% So far.
+
\def\doseeregister[#1][#2]#3#4%
{\doflushatpar{\doprocessseeregister{#1}{#2}{#3}{#4}}}
@@ -312,7 +416,7 @@
\fi
\setnextinternalreference
% we could consider storing register entries in list
- \ctxlua{ jobregisters.store {
+ \edef\temp{\ctxlua{ jobregisters.store {
metadata = {
kind = "see",
name = "\currentregister",
@@ -331,7 +435,7 @@
text = "\currentregisterseeword"
},
}
- }%
+ }}%
\endgroup}
%D Rendering:
@@ -342,7 +446,14 @@
{\dodoubleempty\dodetermineregistercharacteristics}
\def\dodetermineregistercharacteristics[#1][#2]%
- {\edef\utilityregisterlength{\ctxlua{jobregisters.analyse('\currentregister')}}%
+ {\begingroup
+ \edef\currentregister{#1}%
+ \setupregister[\currentregister][#2]%
+ \normalexpanded{\endgroup\noexpand\xdef\noexpand\utilityregisterlength{\ctxlua{jobregisters.analyse('\currentregister',{
+ language = "\registerparameter\s!language",
+ compress = "\registerparameter\c!compress",
+ criterium = "\registerparameter\c!criterium",
+ })}}}% brrr
\ifcase\utilityregisterlength\relax
\resetsystemmode\v!register
\else
@@ -355,7 +466,7 @@
\dontcomplain
\to \everyplaceregister
-\def\placeregister
+\unexpanded\def\placeregister
{\dodoubleempty\doplaceregister}
\def\doplaceregister[#1][#2]%
@@ -380,6 +491,7 @@
% prefix = "\registerparameter\c!pageprefix",
separatorset = "\registerparameter\c!pageprefixseparatorset",
conversionset = "\registerparameter\c!pageprefixconversionset",
+ starter = \!!bs\registerparameter\c!pageprefixstarter\!!es,
stopper = \!!bs\registerparameter\c!pageprefixstopper\!!es,
set = "\registerparameter\c!pageprefixset",
segments = "\registerparameter\c!pageprefixsegments",
@@ -389,6 +501,7 @@
prefix = "\registerparameter\c!pageprefix",
separatorset = "\registerparameter\c!pageseparatorset",
conversionset = "\registerparameter\c!pageconversionset",
+ starter = \!!bs\registerparameter\c!pagestarter\!!es,
stopper = \!!bs\registerparameter\c!pagestopper\!!es,
segments = "\registerparameter\c!pagesegments",
}
@@ -417,7 +530,7 @@
\begingroup
\edef\currentregister{#1}%
% the expansion is needed because we don't want \v!'s in the tuo file (french)
- \normalexpanded{\noexpand\systemsuppliedchapter[\currentregister]{\noexpand\headtext{\currentregister}}}%
+ \normalexpanded{\systemsuppliedchapter[\currentregister]{\noexpand\headtext{\currentregister}}}%
\placeregister[\currentregister][#2]%
\page[\v!yes]%
\endgroup
@@ -426,9 +539,9 @@
% test case for collapsing (experimental, for Steffen Wolfrum)
%
% \starttext
-% \placeregister[index][collapse=no] \blank[2*big]
-% \placeregister[index][collapse=yes] \blank[2*big]
-% \placeregister[index][collapse=akk] \page
+% \placeregister[index][compress=no] \blank[2*big]
+% \placeregister[index][compress=yes] \blank[2*big]
+% \placeregister[index][compress=all] \page
% \dorecurse{10}{test 1:!\index{test} test \page}
% \dorecurse{5} {test 2:\recurselevel \page}
% \dorecurse{10}{test 3:!\index{test} test \page}
@@ -459,13 +572,14 @@
\setvalue{\??id:\c!indicator:a}#1%
{\registerparameter\c!before
- \vskip\lineheight\goodbreak\vskip-\lineheight
+ % bugged, why does leftskip gets set: \vskip\lineheight\goodbreak\vskip-\lineheight
\begingroup\dosetregisterattributes\c!style\c!color
\registerparameter\c!command{\strut#1}%
\endgroup
\registerparameter\c!after
\par\nobreak}
+
% b = <goodbreak> <before> <character> <after> <nobreak>
\setvalue{\??id:\c!indicator:b}#1%
@@ -482,49 +596,53 @@
%D The following macros are the interface to the rendering. These are
%D generated by \LUA. This might change.
-\def\startregisteroutput
+%D Beware, we get funny side effects when a dangling \index precedes an
+%D placeindex as then flushing takes place inside the index. Took me hours
+%D to notice that.
+
+\unexpanded\def\startregisteroutput
{\endgraf
\begingroup
\forgetparindent
\forgetparskip}
-\def\stopregisteroutput
+\unexpanded\def\stopregisteroutput
{\endgraf
\endgroup}
-\def\startregisterentries#1% depth
+\unexpanded\def\startregisterentries#1% depth
{\endgraf
\begingroup
\dosetregisterattributes\c!textstyle\c!textcolor
\advance\leftskip\numexpr#1-1\relax\dimexpr\registerparameter\c!distance\relax
\hangindent\registerparameter\c!distance\hangafter\plusone}
-\def\stopregisterentries
+\unexpanded\def\stopregisterentries
{\endgraf
\endgroup}
-\def\startregistersection#1% title
+\unexpanded\def\startregistersection#1% title
{\registercharacter{#1}\endgraf}
-\def\stopregistersection
+\unexpanded\def\stopregistersection
{\endgraf}
\newconditional\registerpagedone
-\def\startregisterpages
+\unexpanded\def\startregisterpages
{\begingroup
\setfalse\registerpagedone
\dosetregisterattributes\c!pagestyle\c!pagecolor}
-\def\stopregisterpages
+\unexpanded\def\stopregisterpages
{\endgroup}
-\def\startregisterseewords
+\unexpanded\def\startregisterseewords
{\begingroup
\setfalse\registerpagedone
\dosetregisterattributes\c!pagestyle\c!pagecolor}
-\def\stopregisterseewords
+\unexpanded\def\stopregisterseewords
{\endgroup}
\def\registerpageseparator% todo: , configurable
@@ -535,14 +653,29 @@
\settrue\registerpagedone
\fi}
+\def\registeronepagerangeseparator{|\endash|}
+
+\def\withregisterpagecommand#1#2#3%
+ {\def\currentregisterpageindex{#1}%
+ \iflocation
+ \goto{\registerparameter\c!pagecommand{#3}}[internal(#1)]%
+ \else
+ \registerparameter\c!pagecommand{#3}%
+ \fi}
+
\def\registeronepage#1#2#3% content
- {\registerpageseparator\registerparameter\c!pagecommand{\goto{#3}[internal(#1)]}}
+ {\registerpageseparator
+ \withregisterpagecommand{#1}{#2}{#3}}
\def\registerpagerange#1#2#3#4#5#6% content, content todo: -- configurable
- {\registerpageseparator\registerparameter\c!pagecommand{\goto{#3}[internal(#1)]}|--|\registerparameter\c!pagecommand{\goto{#6}[internal(#4)]}}
+ {\registerpageseparator
+ \withregisterpagecommand{#1}{#2}{#3}%
+ \registeronepagerangeseparator
+ \withregisterpagecommand{#4}{#5}{#6}}
\def\registeroneword#1#2#3% content
- {\registerpageseparator\registerseeword{#3}}
+ {\registerpageseparator
+ \registerseeword{#3}}
\def\defaultregisterentry #1{\registerparameter\c!textcommand{\limitedregisterentry{\registerparameter\c!deeptextcommand{#1}}}}
\def\defaultregisterseeword#1{\labeltexts\v!see{#1}}
@@ -559,13 +692,41 @@
% todo: \installregisterpagehandler
+% \def\MyRegisterPageCommand#1%
+% {#1\currentregisterpageuserdata{whatever}}
+%
+% \starttext
+% \setregisterentry[index][entries=aaa][whatever=f.] test \index{bbb} test
+% \placeregister[index][n=1,pagecommand=\MyRegisterPageCommand]
+% \stoptext
+
+\def\registerpageuserdata #1#2{\ctxlua{jobregisters.userdata(#1,"#2")}}
+\def\currentregisterpageuserdata {\registerpageuserdata\currentregisterpageindex} % {#1}
+
+% not yet ok : new internal handler names
+
\def\registerpagebuttonsymbol{\vrule\!!width1em\!!height1ex\!!depth\zeropoint\relax}
-\setvalue{\??id:\c!symbol :\c!n}{\def\registerpageseparatorsymbol{, }\let\registerpagenumberhandler\firstofoneargument}
-\setvalue{\??id:\c!symbol :\c!a}{\def\registerpageseparatorsymbol{, }\let\registerpagenumberhandler\firstofoneargument} % now done via conversion
-\setvalue{\??id:\c!symbol:\v!none}{\let\registerpageseparatorsymbol\empty\let\registerpagenumberhandler\gobbleoneargument}
-\setvalue{\??id:\c!symbol :1}{\let\registerpageseparatorsymbol\space\def\registerpagenumberhandler{\symbol[1]\gobbleoneargument}}
-\setvalue{\??id:\c!symbol :2}{\let\registerpageseparatorsymbol\space\def\registerpagenumberhandler{\registerpagebuttonsymbol\gobbleoneargument}}
+\setvalue{\??id:\c!symbol:\c!n}%
+ {\def\registerpageseparatorsymbol{, }}
+
+\setvalue{\??id:\c!symbol:\c!a}%
+ {\def\registerpageseparatorsymbol{, }} % now done via conversion
+
+\setvalue{\??id:\c!symbol:\v!none}%
+ {\let\registerpageseparatorsymbol\empty
+ \let\registeronepage \gobblethreearguments
+ \let\registerpagerange \gobblesixarguments}
+
+\setvalue{\??id:\c!symbol:1}%
+ {\let\registerpageseparatorsymbol\space
+ \def\registeronepage {\symbol[1]\gobblethreearguments}%
+ \def\registerpagerange {\symbol[1]\gobblesixarguments}}
+
+\setvalue{\??id:\c!symbol:2}%
+ {\let\registerpageseparatorsymbol\space
+ \def\registeronepage {\registerpagebuttonsymbol\gobblethreearguments}%
+ \def\registerpagerange {\registerpagebuttonsymbol\gobblesixarguments}}
\def\setregisterpagerendering
{\edef\currentregisterpagesymbol{\registerparameter\c!symbol}%
@@ -575,7 +736,8 @@
\csname\??id:\c!symbol:\currentregisterpagesymbol\endcsname
\else
\let\registerpageseparatorsymbol\space
- \def\registerpagenumberhandle{\registerparameter\c!symbol\gobbleoneargument}%
+ \def\registeronepage {\registerparameter\c!symbol\gobblethreearguments}%
+ \def\registerpagerange {\registerparameter\c!symbol\gobblesixarguments}%
\fi\fi}
\appendtoks
@@ -684,8 +846,8 @@
% \fi}
% {\dosetpageregister{#1}}}
-\def\dosetregister#1%
- {\dosetpageregister{#1}}
+% \def\dosetregister#1%
+% {\dosetpageregister{#1}}
% \newcounter\internallistreference