diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-ref.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/strc-ref.mkiv | 804 |
1 files changed, 385 insertions, 419 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-ref.mkiv b/Master/texmf-dist/tex/context/base/strc-ref.mkiv index 8290a1b1380..bec96e05c23 100644 --- a/Master/texmf-dist/tex/context/base/strc-ref.mkiv +++ b/Master/texmf-dist/tex/context/base/strc-ref.mkiv @@ -112,16 +112,28 @@ \newcount\lastreferenceattribute \newcount\lastdestinationattribute -\def\dofinishfullreference#1#2{\normalexpanded{\ctxlatelua{jobreferences.enhance("#1","#2")}}} -\def\dofinishtextreference#1#2{\normalexpanded{\ctxlatelua{jobreferences.enhance("#1","#2",{})}}} +\def\dofinishfullreference#1#2{\normalexpanded{\ctxlatelua{structures.references.enhance("#1","#2")}}} +\def\dofinishtextreference#1#2{\normalexpanded{\ctxlatelua{structures.references.enhance("#1","#2",{})}}} \let\dofinishpagereference\dofinishfullreference \let\dofinishuserreference\dofinishfullreference -\def\dodosetreference#1#2#3#4% kind labels userdata text -> todo: userdata +\def\dofinishsomereference#1{\executeifdefined{dofinish#1reference}\gobbletwoarguments} + +\def\dodosetreference + {\ifreferencing + \expandafter\dododosetreference + \else + \expandafter\gobblefourarguments + \fi} + +\def\dododosetreference#1#2#3#4% kind labels userdata text -> todo: userdata {\ifreferencing + % we could have a more efficient one for page references but for the moment + % we don't care too much \edef\currentreferencekind{#1}% \edef\currentreferencelabels{#2}% + \edef\currentreferenceuserdata{#3}% \edef\currentreferenceexpansion{\@@rfexpansion}% {\referenceparameter\c!expansion} \ifx\currentreferencelabels\empty \else \ifx\currentreferenceexpansion\s!xml @@ -137,36 +149,69 @@ \fi \globallet\currentreferencecoding\s!tex \fi - % beware, the jobreferences.set writes a + % beware, the structures.references.set writes a % \setnextinternalreference - \ctxlua{jobreferences.setandgetattribute("\currentreferencekind", "\referenceprefix","\currentreferencelabels", + \ctxlua{structures.references.setandgetattribute("\currentreferencekind", "\referenceprefix","\currentreferencelabels", { references = { % internal = \nextinternalreference, % no need for an internal as we have an explicit block = "\currentstructureblock", - section = structure.sections.currentid(), + section = structures.sections.currentid(), }, - metadata = { - kind = "#1", - catcodes = \the\catcodetable, - xmlroot = \ifx\currentreferencecoding\s!xml "\xmldocument" \else nil \fi, % only useful when text + metadata = { % we could assume page to have no metadata + kind = "#1", + \ifx\currentreferencekind\s!page\else + catcodes = \the\catcodetable, + xmlroot = \ifx\currentreferencecoding\s!xml "\xmldocument" \else nil \fi, % only useful when text + \fi }, \ifx\currentreferencedata\empty\else entries = { text = \!!bs\currentreferencedata\!!es }, \fi - userdata = structure.helpers.touserdata(\!!bs\detokenize{#3}\!!es) - },"\@@iafocus") + \ifx\currentreferenceuserdata\empty\else + userdata = structures.helpers.touserdata(\!!bs\detokenize{#3}\!!es) + \fi + },"\interactionparameter\c!focus") }% + % todo: optional \xdef\currentdestinationattribute{\number\lastdestinationattribute}% - \begingroup\attribute\destinationattribute\currentdestinationattribute\hbox{}\endgroup % todo + \begingroup\attribute\destinationattribute\currentdestinationattribute\emptyhbox\endgroup % todo \fi \fi} \def\defaultreferencepage#1{[[[#1]]]} \def\defaultreferencetext#1{[[[#1]]]} +%D For internal usage: + +\def\dosetsimplepagereference#1% label + {\iflocation + \ctxlua{structures.references.setandgetattribute("\s!page", "\referenceprefix","#1", + { + references = { + % block = "\currentstructureblock", + % section = structures.sections.currentid(), + }, + metadata = { % we could assume page to have no metadata + kind = "\s!page", + }, + },"\interactionparameter\c!focus") + }% + \xdef\currentdestinationattribute{\number\lastdestinationattribute}% + \else + \xdef\currentdestinationattribute{\number\attributeunsetvalue}% + \fi} + +\def\dogetsimplepagereference#1% + {\iflocation + \ctxlua{structures.references.inject("\referenceprefix","#1",\number\ht\strutbox,\number\dp\strutbox,\extrareferencearguments)}% + \xdef\currentreferenceattribute{\number\lastreferenceattribute}% + \else + \xdef\currentreferenceattribute{\number\attributeunsetvalue}% + \fi} + %D These macros depend on three other ones, %D \type {\makesectionformat}, that generated \type %D {\sectionformat}, \type {\pagenumber}. The not yet used @@ -213,7 +258,7 @@ %D \stoptabulate \def\usereferences[#1]% not yet - {\writestatus\m!systems{references from other files are handled automatically}} + {\writestatus\m!system{references from other files are handled automatically}} %D As mentioned we will also use the cross reference mechanism %D for navigational purposes. The main reason for this is that @@ -371,13 +416,13 @@ {\dodoubleempty\dodefinereference} \def\dodefinereference[#1][#2]% - {\ctxlua{jobreferences.define("\referenceprefix","#1",\!!bs\detokenize{#2}\!!es)}} + {\ctxlua{structures.references.define("\referenceprefix","#1",\!!bs\detokenize{#2}\!!es)}} \def\resetreference[#1]% - {\ctxlua{jobreferences.reset("\referenceprefix","#1")}} + {\ctxlua{structures.references.reset("\referenceprefix","#1")}} \def\setpagereference#1#2% name, specification - {\ctxlua{jobreferences.define("","#1",\!!bs\v!page(\luaescapestring{#2})\!!es)}} + {\ctxlua{structures.references.define("","#1",\!!bs\v!page(\luaescapestring{#2})\!!es)}} %D Chained references are defined as: %D @@ -407,10 +452,13 @@ \newconditional\gotonewwindow \setfalse\gotonewwindow \def\expandtexincurrentreference % will happen in lua some time - {\ifcase\referencehastexstate\else\ctxlua{jobreferences.expandcurrent()}\fi} + {\ifcase\referencehastexstate\else\ctxlua{structures.references.expandcurrent()}\fi} + +\def\expandreferenceoperation#1#2{\ctxcommand{setreferenceoperation(#1,\!!bs#2\!!es)}} +\def\expandreferencearguments#1#2{\ctxcommand{setreferencearguments(#1,\!!bs#2\!!es)}} \def\doifreferencefoundelse#1#2#3% - {\ctxlua{jobreferences.doifelse("\referenceprefix","#1",\luaconditional\highlighthyperlinks,\luaconditional\gotonewwindow)}% + {\ctxlua{structures.references.doifelse("\referenceprefix","#1",\luaconditional\highlighthyperlinks,\luaconditional\gotonewwindow)}% {\expandtexincurrentreference#2}% {#3}} @@ -422,7 +470,7 @@ %D be called. \def\analyzecurrentreference - {\ctxlua{jobreferences.analyse()}} + {\ctxlua{structures.references.analyze()}} %D The inner case is simple. Only two cases have to be taken %D care of: @@ -446,14 +494,14 @@ %D An unknown reference is reported on the screen, in the log %D file and, when enabled, in the left margin of the text. -\def\reportreferenceerror#1#2% only once (keep track in lua) - {\ifinpagebody \else - \doifconcepttracing{\doifsomething{#2}{\inleft{\infofont\doboundtext{#2}{\dimexpr\leftmarginwidth-2em\relax}{..}->}}}% - \fi - \showmessage\m!references{#1}{[\referenceprefix][#2]}} +% \def\unknownreference#1% +% {\iftrialtypesetting \else +% \ifinpagebody \else +% \doifconcepttracing{\doifsomething{#1}{\inleft{\infofont\doboundtext{#1}{\dimexpr\leftmarginwidth-2em\relax}{..}->}}}% +% \fi +% \fi} -\def\unknownreference{\reportreferenceerror1} -\def\illegalreference{\reportreferenceerror4} +\let\unknownreference\gobbleoneargument %D When a reference is not found, we typeset a placeholder %D (two glyphs are often enough to represent the reference @@ -521,26 +569,31 @@ \newcount\locationorder \newbox \locationbox -\def\nextinternalreference {\the\locationcount} +\def\nextinternalreference {\the\locationcount} \def\nextinternalorderreference{\the\locationorder} \def\setnextinternalreference {\global\advance\locationcount\plusone} \def\setnextinternalreferences#1#2% plural - {\ctxlua{jobreferences.setnextinternal("#1","#2")}} + {\ctxlua{structures.references.setnextinternal("#1","#2")}} \def\getinternalorderreference#1#2% - {\ctxlua{jobreferences.currentorder("#1","#2")}} + {\ctxlua{structures.references.currentorder("#1","#2")}} \def\thisissomeinternal#1#2% tag reference (only for old time sake) - {\begingroup\attribute\destinationattribute\ctxlua{jobreferences.mark("#1:#2")}\hbox{}\endgroup} + {\begingroup + \ctxlua{structures.references.setinternalreference("","#1:#2")}% + \hbox attr \destinationattribute\lastdestinationattribute{}% + \endgroup} + +\newconditional\preferpagereferences \def\gotosomeinternal#1#2#3#4% - {\ifinternalnamedreferences - \directgoto{#4}[#1:#2]% - \else + {\ifconditional\preferpagereferences \directgoto{#4}[page(#3)]% + \else + \directgoto{#4}[#1:#2]% \fi} \def\gotonextinternal#1#2% @@ -587,41 +640,60 @@ %D document). By setting the \type{interaction} variable, one %D can influences the way interactive references are set. -\chardef\autocrossfilereferences=0 +\newconstant\autocrossfilereferences % not yet supported in mkiv +\newconstant\referencefilecaseswap % not yet supported in mkiv + +\newtoks \everysetupreferencing \unexpanded\def\setupreferencing {\dosingleargument\dosetupreferencing} \def\dosetupreferencing[#1]% - {\getparameters - [\??rf] - [\c!prefix=\s!unknown,#1]% + {\getparameters[\??rf][\c!prefix=\s!unknown,#1]% + \the\everysetupreferencing} + +\appendtoks \processaction [\@@rfstate] [ \v!stop=>\referencingfalse, \v!start=>\referencingtrue]% +\to \everysetupreferencing + +% \newconstant \referencecontentmode +% +% \appendtoks +% \processaction +% [\@@rfinteraction] +% [ \v!all=>\referencecontentmode\zerocount, +% \v!label=>\referencecontentmode\plusone, +% \v!text=>\referencecontentmode\plustwo, +% \v!symbol=>\referencecontentmode\plusthree]% +% \to \everysetupreferencing + +\appendtoks + \autocrossfilereferences\zerocount \processaction - [\@@rfinteraction] - [ \v!all=>\let\dowantedreference\docompletereference, - \v!label=>\let\dowantedreference\dolabelonlyreference, - \v!text=>\let\dowantedreference\dotextonlyreference, - \v!symbol=>\let\dowantedreference\dosymbolreference]% - \chardef\autocrossfilereferences\zerocount - \processaction - [\@@rfautofile] - [ \v!yes=>\chardef\autocrossfilereferences\plusone, - \v!page=>\chardef\autocrossfilereferences\plustwo]% - \chardef\referencefilecase\zerocount - \processaction[\@@rfconvertfile] - [ \v!yes=>\chardef\referencefilecase\plusone, - \v!big=>\chardef\referencefilecase\plusone, - \v!small=>\chardef\referencefilecase\plustwo]% + [\@@rfautofile] % not yet in mkiv + [ \v!yes=>\autocrossfilereferences\plusone, + \v!page=>\autocrossfilereferences\plustwo]% +\to \everysetupreferencing + +\appendtoks + \referencefilecaseswap\zerocount + \processaction[\@@rfconvertfile] % not yet in mkiv + [ \v!yes=>\referencefilecaseswap\plusone, + \v!big=>\referencefilecaseswap\plusone, + \v!small=>\referencefilecaseswap\plustwo]% +\to \everysetupreferencing + +\appendtoks \setupreferenceprefix[\@@rfprefix]% \doifelse\@@rfglobal\v!yes - {\settrue \autoglobalfilereferences} - {\setfalse\autoglobalfilereferences}} + {\settrue \autoglobalfilereferences}% + {\setfalse\autoglobalfilereferences}% +\to \everysetupreferencing -% \appendtoks\ctxlua{jobreferences.export("whatever")}\to\everystoptext +% \appendtoks\ctxlua{structures.references.export("whatever")}\to\everystoptext % \starttext % \chapter[test]{test} % test \in{IN}[more] and \in{IN}[test] or \at{AT}[more] and \at{AT}[test]\par @@ -630,7 +702,7 @@ % \stoptext \def\exportreferences - {\doif\@@rfexport\v!yes{\ctxlua{jobreferences.export()}}} + {\doif\@@rfexport\v!yes{\ctxlua{structures.references.export()}}} \appendtoks \exportreferences @@ -700,7 +772,7 @@ {\ifsecondargument \doifreferencefoundelse{#2} {\executeifdefined{reftype#1}\reftypep} - {\unknownreference{#2}\dummyreference}% + {\dummyreference}% \else \dummyreference \fi} @@ -761,14 +833,14 @@ % \definecommand from {\dospecialfrom} % \definecommand over {\dospecialabout} % needed here, else math problems -\def\currentreferencenumber {\ctxlua{jobreferences.filter("number")}} -\def\currentreferencepage {\ctxlua{jobreferences.filter("page")}} -\def\currentreferencetitle {\ctxlua{jobreferences.filter("title")}} -\def\currentreferencetext {\ctxlua{jobreferences.filter("text")}} -\def\currentreferencedefault {\ctxlua{jobreferences.filter("default")}} -\def\currentreferencerealpage{\ctxlua{jobreferences.realpage()}} +\def\currentreferencenumber {\ctxlua{structures.references.filter("number")}} +\def\currentreferencepage {\ctxlua{structures.references.filter("page")}} +\def\currentreferencetitle {\ctxlua{structures.references.filter("title")}} +\def\currentreferencetext {\ctxlua{structures.references.filter("text")}} +\def\currentreferencedefault {\ctxlua{structures.references.filter("default")}} +\def\currentreferencerealpage{\ctxlua{structures.references.realpage()}} -\def\getreferenceentry#1{\ctxlua{jobreferences.filter("#1")}} % user entry +\def\getreferenceentry#1{\ctxlua{structures.references.filter("#1")}} % user entry \unexpanded\def\dospecialabout[#1]% {\dontleavehmode @@ -799,12 +871,12 @@ % Yet untested: \unexpanded\def\somewhere#1#2#3[#4]% #3 gobbles space around #2 % todo - {\doifreferencefoundelse{#4}% kind of inefficient as \goto also analyses + {\doifreferencefoundelse{#4}% kind of inefficient as \goto also analyzes {\goto{\analyzecurrentreference\ifcase\referencepagestate\relax#1/#2\or#2\or#1\or#2\fi}[#4]} {[#1/#2]}} \unexpanded\def\atpage[#1]% todo - {\doifreferencefoundelse{#1}% kind of inefficient as \goto also analyses + {\doifreferencefoundelse{#1}% kind of inefficient as \goto also analyzes {\goto{\analyzecurrentreference\ifcase\referencepagestate \labeltexts\v!page\dummyreference \or @@ -822,7 +894,7 @@ \unexpanded\def\referencesymbol {\hbox{\strut\high - {\setupsymbolset[\@@iasymbolset]% + {\setupsymbolset[\interactionparameter\c!symbolset]% \symbol [\ifcase\referencepagestate \v!somewhere @@ -834,49 +906,99 @@ \v!next% \fi]}}} -% \def\dosymbolreference#1#2[#3]% -% {\removeunwantedspaces -% \goto{\setupsymbolset[\@@iasymbolset]\high{\symbol -% [\ifcase\referencepagestate -% \v!somewhere -% \or % same -% \v!nowhere -% \or % before -% \v!previous -% \or % after -% \v!next% -% \fi]}}[#3]} +%D The other alternatives just conform their names: only the +%D label, only the text, or the label and the text. -\def\dosymbolreference#1#2[#3]% - {\removeunwantedspaces - \goto{\referencesymbol}[#3]} +% \dounknownreference -> \dummyreference -\def\symbolreference[#1]% - {\removeunwantedspaces - \goto{\referencesymbol}[#1]} +\def\symbolreference[#1]% for old times sake + {\goto{\referencesymbol}[#1]} +% \referencecontentmode 0=all 1=label 2=text 3=symbol -%D The other alternatives just conform their names: only the -%D label, only the text, or the label and the text. +\newtoks\leftreferencetoks +\newtoks\rightreferencetoks +\newtoks\defaultleftreferencetoks +\newtoks\defaultrightreferencetoks + +\def\leftofreferencecontent {\nobreakspace} % we cannot do \definereferenceformat[at] .. so we need this +\let\rightofreferencecontent \empty +\let\leftofreference \empty +\let\rightofreference \empty + +\setvalue{\??rf\c!interaction\v!all}% + {\leftofreference + \the\leftreferencetoks + \doifsometokselse\leftreferencetoks \leftofreferencecontent \donothing + \currentreferencecontent + \doifsometokselse\rightreferencetoks\rightofreferencecontent\donothing + \the\rightreferencetoks + \rightofreference} + +\setvalue{\??rf\c!interaction\v!label}% + {\leftofreference + \the\leftreferencetoks + \the\rightreferencetoks + \rightofreference} + +\setvalue{\??rf\c!interaction\v!text}% + {\leftofreference + \currentreferencecontent + \rightofreference} + +\setvalue{\??rf\c!interaction\v!symbol}% + {\referencesymbol} + +\def\referencesequence + {\csname \??rf\c!interaction + \ifcsname\??rf\c!interaction\@@rfinteraction\endcsname + \@@rfinteraction + \else + \v!all + \fi + \endcsname} -\def\dounknownreference#1#2[#3]% - {\unknownreference{#3}\dotextprefix{#2}\dummyreference}% +\newtoks\everyresetinatreference -\def\docompletereference#1#2[#3]% - {\goto{\dotextprefix{#2}#1}[#3]} +\appendtoks + \glet\leftofreference \relax + \glet\rightofreference\relax +\to \everyresetinatreference + +\def\dostartgotoreference + {\dontleavehmode + \begingroup} -% \def\dolabelonlyreference#1#2[#3]% -% {\doifsomespaceelse{#2}% space? -% {\doifsomething{#2}{\goto{#2}[#3]}} -% {\goto{\dotextprefix{#2}}[#3]}} +\def\dostopgotoreference + {\the\everyresetinatreference + \endgroup} -\def\dolabelonlyreference#1#2[#3]% - {\goto{\dotextprefix{#2}}[#3]} +\def\dopickupgotoreference + {\dodoublegroupempty\dodopickupgotoreference} -\def\dotextonlyreference#1#2[#3]% - {\dotextprefix{#2}\goto{#1}[#3]} +\def\dodopickupgotoreference#1#2#3[#4]% #3 gobbles spaces (really needed) + {\leftreferencetoks + \iffirstargument + {#1}% + \else + \defaultleftreferencetoks + \let\leftofreferencecontent\empty + \fi + \rightreferencetoks + \ifsecondargument + {#2}% + \else + \defaultrightreferencetoks + \let\rightofreferencecontent\empty + \fi + \doifreferencefoundelse{#4} % we need to resolve the text + {\goto{\referencesequence}[#4]} + {\let\currentreferencecontent\dummyreference + \goto{\referencesequence}[#4]}% + \dostopgotoreference} -\let\dowantedreference\docompletereference +\unexpanded\def\dospecialin{\dostartgotoreference\let\currentreferencecontent\currentreferencedefault\dopickupgotoreference} +\unexpanded\def\dospecialat{\dostartgotoreference\let\currentreferencecontent\currentreferencepage \dopickupgotoreference} %D \macros %D {definereferenceformat} @@ -885,8 +1007,6 @@ %D Hoekwater. They can be used for predefining reference %D texts, and thereby stimulate efficiency. %D -%D [more documentation will be added] -%D %D \starttyping %D \definereferenceformat[informula] [left=(,right=),text=formula] %D \definereferenceformat[informulas] [left=(,right=),text=formulas] @@ -902,61 +1022,83 @@ %D %D Instead of a text, one can specify a label, which should %D be defined with \type {\setuplabeltext}. +%D +%D +%D Watch out: the second argument is somewhat special and mostly +%D meant for a suffix to a number: +%D +%D \startbuffer +%D \definereferenceformat [intesta] [left=(,right=),text=Whatever~] +%D \definereferenceformat [intestb] [left=(,right=),label=figure] +%D +%D \placeformula[x]\startformula a \stopformula +%D +%D \starttabulate[|||||] +%D \NC \in [x] \NC \in {left}[x] \NC \in {}{right}[x] \NC \in {left}{right}[x] \NC \NR +%D \NC \intesta[x] \NC \intesta{left}[x] \NC \intesta{}{right}[x] \NC \intesta{left}{right}[x] \NC \NR +%D \NC \intestb[x] \NC \intestb{left}[x] \NC \intestb{}{right}[x] \NC \intestb{left}{right}[x] \NC \NR +%D \stoptabulate +%D \stopbuffer +%D +%D \typebuffer \getbuffer + +% todo: inherit -% todo: inherit; probably not yet mkiv okay +\let\currentreferenceformat\empty + +\def\referenceformatparameter#1% some day we will add inheritance + {\ifcsname\??rf\currentreferenceformat#1\endcsname\csname\??rf\currentreferenceformat#1\expandafter\endcsname\fi} \unexpanded\def\definereferenceformat {\dodoubleargument\dodefinereferenceformat} +% left right text label + \def\dodefinereferenceformat[#1][#2]% {\iffirstargument - \getparameters[\??rf#1] - [\c!left=, % of the number - \c!right=, % of the number - \c!text=, % before the number - \c!label=, % can be {left}{right} - \c!command=\in, - #2]% - \setuvalue{#1}% - {\dontleavehmode\doexecutereferenceformat{#1}}% + \getparameters[\??rf#1][\c!left=,\c!right=,\c!text=,\c!label=,\c!autocase=v!no,#2]% + \setuvalue{#1}{\doexecutereferenceformat{#1}}% \fi} -\def\noexecutelabelreferenceformat#1% - {\doifvaluesomething{\??rf#1\c!text}{\gdef\textofreference{\csname\??rf#1\c!text\endcsname}}% - \csname\??rf#1\c!command\endcsname} - -\def\doexecutelabelreferenceformat#1% - {\csname\??rf#1\c!command\endcsname - {\leftlabeltext {\csname\??rf#1\c!label\endcsname}}% - {\rightlabeltext{\csname\??rf#1\c!label\endcsname}}} - -\def\doexecutereferenceformat#1% - {\gdef\leftofreference {\csname\??rf#1\c!left \endcsname}% - \gdef\rightofreference{\csname\??rf#1\c!right\endcsname}% - \global\let\textofreference\empty % otherwise ~ added - \doifelsevaluenothing{\??rf#1\c!label}\noexecutelabelreferenceformat\doexecutelabelreferenceformat{#1}} +\def\doexecutereferenceformat#1% quite slow due to all assignments but we will speed it up + {\dostartgotoreference % once it's stable + \edef\currentreferenceformat{#1}% + \gdef\leftofreference {\referenceformatparameter\c!left }% + \gdef\rightofreference{\referenceformatparameter\c!right}% + % we can make a helper for this .. we will use the new parameter handler anyway + % but at least aditya can play with it now + \doifsomething{\referenceformatparameter\c!style} + {\dosetfontattribute{\??rf\currentreferenceformat}\c!style + \resetinteractionparameter\c!style}% + \doifsomething{\referenceformatparameter\c!color} + {\dosetcolorattribute{\??rf\currentreferenceformat}\c!color + \resetinteractionparameter\c!contrastcolor + \resetinteractionparameter\c!color}% + % + \edef\currentreferenceformatlabel{\referenceformatparameter\c!label}% + \ifx\currentreferenceformatlabel\autoreferencelabeltextflag + \edef\currentreferenceformatlabel{\autoreferencelabeltext}% + \fi + \doif{\referenceformatparameter\c!autocase}\v!yes + {\setcharactercleaning[1]}% + \ifx\currentreferenceformatlabel\empty + \defaultleftreferencetoks {\referenceformatparameter\c!text}% + \defaultrightreferencetoks\emptytoks + \else + \defaultleftreferencetoks {\leftlabeltext \currentreferenceformatlabel}% + \defaultrightreferencetoks{\rightlabeltext\currentreferenceformatlabel}% + \fi + \doifelse{\referenceformatparameter\c!type}\v!page + {\let\currentreferencecontent\currentreferencepage} + {\let\currentreferencecontent\currentreferencedefault}% + \let\leftofreferencecontent \empty + \let\rightofreferencecontent\empty + \dopickupgotoreference} -\let\leftofreference \relax -\let\rightofreference\relax -\let\textofreference \relax +\def\autoreferencelabeltextflag{*} % a proper key like 'auto' or 'name' can clash with a label key -% fails on metafun {\leftofreference#1\ignorespaces#3\removeunwantedspaces\rightofreference}{#2}[#4]% -% -% \def\dodododoinatreference#1#2#3[#4]% no \removeunwantedspaces (fails on metafun) -% {\ifx\next\bgroup -% \dododododoinatreference{\leftofreference#1\ignorespaces#3\rightofreference}{#2}[#4]% -% \else -% \dododododoinatreference{\leftofreference#1\rightofreference}{#2#3}[#4]% -% \fi} -% -% \def\dododododoinatreference#1#2[#3]% -% {\dontleavehmode % replaces \leaveoutervmode -% \begingroup -% \postponenotes -% \doifreferencefoundelse{#3} -% {\doifelsenothing{#1}\dosymbolreference\dowantedreference{#1}{#2}[#3]}% -% {\dounknownreference{#1}{#2}[#3]}% -% \endgroup} +\unexpanded\def\autoreferencelabeltext + {\ctxlua{structures.references.getcurrentmetadata("name")}} % \starttext % \definereferenceformat[inxx] [left=(,right=),text=txt] @@ -970,62 +1112,6 @@ % [\inxx{a}{b}[one]] % \stoptext -\unexpanded\def\dospecialin{\let\currentreferencecontent\currentreferencedefault\doinatreference} -\unexpanded\def\dospecialat{\let\currentreferencecontent\currentreferencepage \doinatreference} - -\newtoks\leftreferencetoks -\newtoks\rightreferencetoks - -\def\doinatreference - {\futurelet\next\doinatreferenceone} - -\def\doinatreferenceone - {\ifx\next\bgroup - \afterassignment\doinatreferenceonetwo - \expandafter\leftreferencetoks - \else - \leftreferencetoks\emptytoks - \expandafter\dodoinatreferencenone - \fi} - -\def\doinatreferenceonetwo - {\futurelet\next\doinatreferencetwo} - -\def\doinatreferencetwo - {\ifx\next\bgroup - \afterassignment\dodoinatreferenceboth - \expandafter\rightreferencetoks - \else - \rightreferencetoks\emptytoks - \expandafter\dodoinatreferenceleft - \fi} - -\def\dodoinatreferencenone - {\dodoinatreferenceindeed - {\leftofreference\currentreferencecontent\rightofreference} - {}} - -\def\dodoinatreferenceleft - {\dodoinatreferenceindeed - {\leftofreference\currentreferencecontent\rightofreference} - {\the\leftreferencetoks}} - -\def\dodoinatreferenceboth - {\dodoinatreferenceindeed - {\leftofreference\currentreferencecontent\the\rightreferencetoks\rightofreference} - {\the\leftreferencetoks}} - -\def\dodoinatreferenceindeed#1#2#3[#4]% #3 gobbles space - {\dontleavehmode % replaces \leaveoutervmode - \begingroup - \postponenotes - \doifreferencefoundelse{#4} - {\doifelsenothing{#1}\dosymbolreference\dowantedreference{#1}{#2}[#4]}% - {\dounknownreference{#1}{#2}[#4]}% - \endgroup} - -\let\dosymbolreference\dowantedreference - %D In interactive documents going to a specific location is not %D bound to cross references. The \type{\goto} commands can be %D used to let users access another part of the document. In @@ -1058,74 +1144,107 @@ % The unbox trick is needed in order to permit \par inside a reference. Otherwise % the reference attribute migrates to the outer boxes. +\newcount\lastsavedreferenceattribute + \newbox\referencebox +\def\revivesavedreferenceattribute % sometimes handy as no test etc needed + {\attribute\referenceattribute\lastsavedreferenceattribute} + \def\dodirectgoto#1[#2]% no test for valid references {\dontleavehmode \begingroup \attribute\referenceattribute\attributeunsetvalue + \global\lastsavedreferenceattribute\attributeunsetvalue \iflocation - \ctxlua{jobreferences.inject("\referenceprefix","#2",\number\ht\strutbox,\number\dp\strutbox,\extrareferencearguments)}% + \ctxlua{structures.references.inject("\referenceprefix","#2",\number\ht\strutbox,\number\dp\strutbox,\extrareferencearguments)}% \setlocationattributes\??ia \setstrut % can be option + \global\lastsavedreferenceattribute\lastreferenceattribute \attribute\referenceattribute\lastreferenceattribute + \dostarttagged\t!link\empty % not here + #1% + \dostoptagged + \else + #1% \fi - #1% \endgroup} \def\dodirectgotohtdp#1[#2]% no test for valid references {\dontleavehmode \begingroup + \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{jobreferences.inject("\referenceprefix","#2",\number\dimexpr\@@iaheight\relax,\number\dimexpr\@@iadepth\relax,\extrareferencearguments)}% + \ctxlua{structures.references.inject("\referenceprefix","#2",\number\dimexpr\interactionparameter\c!height\relax,\number\dimexpr\interactionparameter\c!depth\relax,\extrareferencearguments)}% \setlocationattributes\??ia \attribute\referenceattribute\lastreferenceattribute + \global\lastsavedreferenceattribute\lastreferenceattribute + \dostarttagged\t!link\empty + #1% + \dostoptagged + \else + #1% \fi - #1% \endgroup} \def\dogoto#1#2[#3]% #2 gobbles spaces after #1 so that \goto{xx} [yy] works ok {\dontleavehmode \begingroup %\setbox\referencebox\hbox\bgroup % experiment, might change again to non \par support + \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{jobreferences.doifelse("\referenceprefix","#3",\extrareferencearguments)}% + \ctxlua{structures.references.doifelse("\referenceprefix","#3",\extrareferencearguments)}% {\expandtexincurrentreference - \ctxlua{jobreferences.injectcurrentset(\number\ht\strutbox,\number\dp\strutbox)}% + \ctxlua{structures.references.injectcurrentset(\number\ht\strutbox,\number\dp\strutbox)}% \setlocationattributes\??ia \setstrut % can be option - \attribute\referenceattribute\lastreferenceattribute}% - {\unknownreference{#3}}% + \global\lastsavedreferenceattribute\lastreferenceattribute + \attribute\referenceattribute\lastreferenceattribute + \dostarttagged\t!link\empty + #1% + \dostoptagged}% + {#1}% + \else + #1% \fi - #1% %\egroup\unhbox\referencebox} \endgroup} \def\dogotohtdp#1#2[#3]% #2 gobbles spaces after #1 so that \goto{xx} [yy] works ok {\dontleavehmode \begingroup + \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{jobreferences.doifelse("\referenceprefix","#3",\extrareferencearguments)}% + \ctxlua{structures.references.doifelse("\referenceprefix","#3",\extrareferencearguments)}% {\expandtexincurrentreference - \ctxlua{jobreferences.injectcurrentset(\number\dimexpr\@@iaheight\relax,\number\dimexpr\@@iadepth\relax)}% + \ctxlua{structures.references.injectcurrentset(\number\dimexpr\interactionparameter\c!height\relax,\number\dimexpr\interactionparameter\c!depth\relax)}% \setlocationattributes\??ia - \attribute\referenceattribute\lastreferenceattribute}% - {\unknownreference{#3}}% + \global\lastsavedreferenceattribute\lastreferenceattribute + \attribute\referenceattribute\lastreferenceattribute + \dostarttagged\t!link\empty + #1% + \dostoptagged}% + {#1}% + \else + #1% \fi - #1% \endgroup} \unexpanded\def\directgotobox#1[#2]% no test for valid references {\dontleavehmode \begingroup + \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{jobreferences.inject("\referenceprefix","#2",nil,nil,\extrareferencearguments)}% + \ctxlua{structures.references.inject("\referenceprefix","#2",nil,nil,\extrareferencearguments)}% \setlocationattributes\??ia + \global\lastsavedreferenceattribute\lastreferenceattribute + \dostarttagged\t!link\empty \hbox attr \referenceattribute \lastreferenceattribute {#1}% + \dostoptagged \else #1% \fi @@ -1134,11 +1253,15 @@ \unexpanded\def\directgotospecbox#1#2[#3]% no test for valid references {\dontleavehmode \begingroup + \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{jobreferences.inject("\referenceprefix","#3",nil,nil,\extrareferencearguments)}% + \ctxlua{structures.references.inject("\referenceprefix","#3",nil,nil,\extrareferencearguments)}% \setlocationcolorspec{#1}% no consequence for strut + \global\lastsavedreferenceattribute\lastreferenceattribute + \dostarttagged\t!link\empty \hbox attr \referenceattribute \lastreferenceattribute {#2}% + \dostoptagged \else #2% \fi @@ -1147,10 +1270,14 @@ \unexpanded\def\directgotodumbbox#1[#2]% no test for valid references {\dontleavehmode \begingroup + \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{jobreferences.inject("\referenceprefix","#2",nil,nil,\extrareferencearguments)}% + \ctxlua{structures.references.inject("\referenceprefix","#2",nil,nil,\extrareferencearguments)}% + \global\lastsavedreferenceattribute\lastreferenceattribute + \dostarttagged\t!link\empty \hbox attr \referenceattribute \lastreferenceattribute {#1}% + \dostoptagged \else #1% \fi @@ -1159,19 +1286,36 @@ \unexpanded\def\gotobox#1[#2]% no test for valid references {\dontleavehmode \begingroup + \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{jobreferences.doifelse("\referenceprefix","#2",\extrareferencearguments)}% + \ctxlua{structures.references.doifelse("\referenceprefix","#2",\extrareferencearguments)}% {\expandtexincurrentreference - \ctxlua{jobreferences.injectcurrentset(nil,nil)}% + \ctxlua{structures.references.injectcurrentset(nil,nil)}% \setlocationattributes\??ia - \hbox attr \referenceattribute \lastreferenceattribute {#1}}% - {\unknownreference{#2}}% + \global\lastsavedreferenceattribute\lastreferenceattribute + \dostarttagged\t!link\empty + \hbox attr \referenceattribute \lastreferenceattribute {#1}% + \dostoptagged}% + {#1}% \else #1% \fi \endgroup} - + +\unexpanded\def\gotowdhtbox#1#2[#3]% fast variant for overlays + {\dontleavehmode + \begingroup + \setbox\scratchbox\emptyhbox\wd\scratchbox#1\ht\scratchbox#2% + \global\lastsavedreferenceattribute\attributeunsetvalue + \attribute\referenceattribute\attributeunsetvalue + \ctxlua{structures.references.doifelse("\referenceprefix","#3",\extrareferencearguments)}% + {\ctxlua{structures.references.injectcurrentset(nil,nil)}% + \global\lastsavedreferenceattribute\lastreferenceattribute + \hbox attr \referenceattribute \lastreferenceattribute {\box\scratchbox}} + {\box\scratchbox}% + \endgroup} + %D An reference to another document can be specified as a file %D or as an \URL. Both are handled by the same mechanism and %D can be issued by saying something like: @@ -1228,13 +1372,13 @@ \let\useexternaldocument\usefile \def\douseurl[#1][#2][#3][#4]% - {\ctxlua{jobreferences.urls.define("#1",\!!bs\detokenize{#2}\!!es,\!!bs\detokenize{#3}\!!es,\!!bs\detokenize{#4}\!!es)}} + {\ctxlua{structures.references.urls.define("#1",\!!bs\detokenize{#2}\!!es,\!!bs\detokenize{#3}\!!es,\!!bs\detokenize{#4}\!!es)}} \def\dousefile[#1][#2][#3]% - {\ctxlua{jobreferences.files.define("#1",\!!bs\detokenize{#2}\!!es,\!!bs\detokenize{#3}\!!es)}} + {\ctxlua{structures.references.files.define("#1",\!!bs\detokenize{#2}\!!es,\!!bs\detokenize{#3}\!!es)}} -\def\doifurldefinedelse #1{\ctxlua{commands.doifurldefinedelse ("#1")}} -\def\doiffiledefinedelse#1{\ctxlua{commands.doiffiledefinedelse("#1")}} +\def\doifurldefinedelse #1{\ctxcommand{doifurldefinedelse ("#1")}} +\def\doiffiledefinedelse#1{\ctxcommand{doiffiledefinedelse("#1")}} %D \macros %D {url,setupurl} @@ -1261,7 +1405,7 @@ \begingroup \dosetfontattribute\??ur\c!style \dosetcolorattribute\??ur\c!color - \hyphenatedurl{\ctxlua{jobreferences.urls.get("#1","\@@uralternative","\@@urspace")}}% + \hyphenatedurl{\ctxlua{structures.references.urls.get("#1","\@@uralternative","\@@urspace")}}% \endgroup} % # fails @@ -1311,7 +1455,7 @@ \def\dodospecialfrom[#1]% {\dontleavehmode - \goto{\ctxlua{jobreferences.from("#1")}}[fileorurl(#1)]} + \goto{\ctxlua{structures.references.from("#1")}}[fileorurl(#1)]} \def\dofromurldescription#1% {#1} @@ -1356,14 +1500,14 @@ {\dotripleargument\dodefineprogram} \def\dodefineprogram[#1][#2][#3]% - {\ctxlua{jobreferences.programs.define("#1","#2","#3")}} + {\ctxlua{structures.references.programs.define("#1","#2","#3")}} \def\program[#1]% incompatible, more consistent, hardy used anyway {\dontleavehmode \begingroup \dosetfontattribute\??pr\c!style \dosetcolorattribute\??pr\c!color - \ctxlua{jobreferences.programs.get("#1","\@@pralternative","\@@prspace")}% + \ctxlua{structures.references.programs.get("#1","\@@pralternative","\@@prspace")}% \endgroup} %D As we can see, we directly use the special reference @@ -1449,8 +1593,6 @@ %D key \type{file}, which is interpreted as the file to jump %D to, that is, when one clicks on the title. -\newif\ifautocrossdocument - \def\coupledocument {\doquadrupleempty\docoupledocument} @@ -1459,185 +1601,6 @@ % this will be done differently (when it's needed) \fi} -%D Buttons are just what their names says: things that can be -%D clicked (pushed) on. They are similar to \type{\goto}, -%D except that the text argument is not interpreted. -%D Furthermore one can apply anything to them that can be done -%D with \type{\framed}. -%D -%D \startbuffer -%D \button[width=3cm,height=1.5cm]{Exit}[ExitViewer] -%D \stopbuffer -%D -%D \typebuffer -%D -%D gives -%D -%D \getbuffer -%D -%D This command is formally specified as: -%D -%D \showsetup{button} -%D -%D The characteristics can be set with: -%D -%D \showsetup{setupbuttons} - -\unexpanded\def\setupbuttons - {\dodoubleargument\getparameters[\??bt]} - -\definecomplexorsimpleempty\button - -\def\complexbutton - {\docomplexbutton\??bt} - -\presetlocalframed[\??bt] - -\long\def\docomplexbutton#1[#2]#3#4% get rid of possible space before [#4] - {\dodocomplexbutton#1[#2]{#3}#4} % #4 == [ - -\def\buttonframed{\dodoubleempty\localframed[\??bt]} % goodie - -\long\def\dodocomplexbutton#1[#2]#3[#4]% #3 can contain [] -> {#3} later - {\begingroup - \doifvalue{#1\c!state}\v!stop\locationfalse - \iflocation - \ConvertConstantAfter\doifelse{#3}\v!none\hphantom\hbox - {\doifelsenothing{#4} - {\setlocationboxnop#1[#2]{#3}[#4]} - {\doifreferencefoundelse{#4} % INEFFICIENT - {\setlocationboxyes#1[#2]{#3}[#4]} - {\unknownreference{#4}% - \setlocationboxnop#1[#2]{#3}[#4]}}}% - \fi - \endgroup} - -\setupbuttons - [\c!state=\v!start] - -%D Interaction buttons, in fact a row of tiny buttons, are -%D typically only used for navigational purposed. The next -%D macro builds such a row based on a specification list. -%D -%D \startbuffer -%D \interactionbuttons -%D [width=\hsize][page,PreviousJump,ExitViewer] -%D \stopbuffer -%D -%D \typebuffer -%D -%D gives -%D -%D \getbuffer -%D -%D Apart from individual entries, one can use \type{page} and -%D \type {subpage} as shortcuts to their four associated buttons. -%D The symbols are derived from the symbols linked to the -%D entries. - -% does not work well with for instance SomeRef{whatever} - -\def\interactionbuttons - {\dodoubleempty\dointeractionbuttons} - -\def\dointeractionbuttons[#1][#2]% er is een verdeel macro \horizontalfractions - {\iflocation - % BUG: fails when frame=off; best is to rewrite this macro - \bgroup - \doif\@@ibstate\v!stop\locationfalse - \iflocation - \ifsecondargument - \setupinteractionbar[#1]% - \checkinteractionbar{1.5em}\v!broad\!!zeropoint % brrrrr - \setbox2\hbox{\localframed[\??ib][\c!background=]{\symbol[\@@iasymbolset][\v!previouspage]}}% - \!!heighta\ht2 % needed because we default to nothing - \setupinteractionbar[\c!strut=\v!no]% - \setinteractionparameter\c!width\!!zeropoint - \!!counta\zerocount % new, was 1 - \processallactionsinset - [#2] - [ \v!page=>\advance\!!counta 4, - \v!subpage=>\advance\!!counta 4, - \s!unknown=>\advance\!!counta 1]% - \ifdim\@@ibwidth=\zeropoint - \!!widtha2em - \advance\!!widtha \@@ibdistance % new - \!!widthb\!!counta\!!widtha - \advance\!!widthb -\@@ibdistance % new - \else - \!!widtha\@@ibwidth - \!!widthb\@@ibdistance % new - \multiply\!!widthb \!!counta % new - \advance\!!widthb -\@@ibdistance % new - \advance\!!widtha -\!!widthb % new - \divide\!!widtha \!!counta - \!!widthb\@@ibwidth - \fi - \def\xgoto##1% clash ? - {\setnostrut - \edef\localreference{##1}% - \normalexpanded{\noexpand\dodocomplexbutton\??ib[\c!height=\the\!!heighta,\c!width=\the\!!widtha]}% - {\dontleavehmode\symbol[\@@iasymbolset][\localreference]}% - [\localreference]% - \hss}% - \hbox to \!!widthb - {\processallactionsinset - [#2] - [ \v!page=>\xgoto\v!firstpage - \xgoto\v!nextpage - \xgoto\v!previouspage - \xgoto\v!lastpage, - \v!subpage=>\xgoto\v!firstsubpage - \xgoto\v!nextsubpage - \xgoto\v!previoussubpage - \xgoto\v!lastsubpage, - \s!unknown=>\xgoto\commalistelement]% - \unskip}% - \else - \interactionbuttons[][#1]% - \fi - \fi - \egroup - \fi} - -%D \macros -%D {overlaybutton} -%D -%D For converience we provide: -%D -%D \starttyping -%D \overlaybutton[reference] -%D \stoptyping -%D -%D This command can be used to define overlays an/or can be -%D used in the whatevertext areas, like: -%D -%D \starttyping -%D \defineoverlay[PrevPage][\overlaybutton{PrevPage}] -%D \setupbackgrounds[page][background=PrevPage] -%D \setuptexttexts[\overlaybutton{NextPage}] -%D \stoptyping -%D -%D For practical reasons, this macro accepts square brackets -%D as well as braces. - -\definecomplexorsimple\overlaybutton - -\def\simpleoverlaybutton#1% - {\complexoverlaybutton[#1]} - -\def\complexoverlaybutton[#1]% - {\iflocation - \gotobox{\overlayfakebox}[#1]% - \fi} - -\def\overlayfakebox - {\hbox - {\setbox\scratchbox\null - \wd\scratchbox\overlaywidth - \ht\scratchbox\overlayheight - \box\scratchbox}} - %D \macros %D {dotextprefix} %D @@ -1730,7 +1693,6 @@ \definereference [\v!HideField ] [action(hide)] \definereference [\v!ShowField ] [action(show)] \definereference [\v!GotoPage ] [action(gotopage)] -\definereference [\v!GotoPage ] [action(gotopage)] \definereference [\v!Query ] [action(query)] \definereference [\v!QueryAgain ] [action(queryagain)] \definereference [\v!FitWidth ] [action(fitwidth)] @@ -1738,6 +1700,10 @@ \definereference [\v!ShowThumbs ] [action(thumbnails)] \definereference [\v!ShowBookmarks ] [action(bookmarks)] +\definereference [\v!HideLayer ] [action(hidelayer)] +\definereference [\v!VideLayer ] [action(videlayer)] +\definereference [\v!ToggleLayer ] [action(togglelayer)] + \definereference [\v!firstpage] [page(firstpage)] \definereference [\v!previouspage] [page(previouspage)] \definereference [\v!nextpage] [page(nextpage)] @@ -1817,16 +1783,16 @@ % \def\getreferencestructureprefixspec#1% we can save one call by moving this to the lua end % {\getreferencestructureprefix -% {\ctxlua{jobreferences.get_current_metadata("kind")}} -% {\ctxlua{jobreferences.get_current_metadata("name")}} +% {\ctxlua{structures.references.getcurrentmetadata("kind")}} +% {\ctxlua{structures.references.getcurrentmetadata("name")}} % {#1}} % \def\currentreferencedefault -% {\ctxlua{jobreferences.filter("default",\getreferencestructureprefixspec\v!default)}} +% {\ctxlua{structures.references.filter("default",\getreferencestructureprefixspec\v!default)}} % % this is shortcut for: \def\currentreferencedefault - {\ctxlua{jobreferences.filter("default",\ctxlua{jobreferences.get_current_prefixspec("\v!default")})}} + {\ctxlua{structures.references.filter("default",\ctxlua{structures.references.getcurrentprefixspec("\v!default")})}} \protect \endinput |