diff options
author | Marius <mariausol@gmail.com> | 2012-06-20 17:40:13 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-06-20 17:40:13 +0300 |
commit | 7f94b11435ebc551709e20c1112eae2492ef1583 (patch) | |
tree | 846bd704ba49c0ea6b7004b1995205d1531cdf91 /tex/context/base/strc-ref.mkvi | |
parent | ecddeed5ffa6bcf030adc91f3ca7f85cea867b3f (diff) | |
download | context-7f94b11435ebc551709e20c1112eae2492ef1583.tar.gz |
beta 2012.06.20 16:19
Diffstat (limited to 'tex/context/base/strc-ref.mkvi')
-rw-r--r-- | tex/context/base/strc-ref.mkvi | 248 |
1 files changed, 128 insertions, 120 deletions
diff --git a/tex/context/base/strc-ref.mkvi b/tex/context/base/strc-ref.mkvi index ee45d76fa..91b807696 100644 --- a/tex/context/base/strc-ref.mkvi +++ b/tex/context/base/strc-ref.mkvi @@ -61,20 +61,42 @@ % \definespecial\dosetexecuteJScode % ... -%D This module deals with referencing. In \CONTEXT\ referencing -%D is one of the core features, although at a first glance -%D probably nobody will notice. This is good, because -%D referencing should be as hidden as possible. +%D This module deals with referencing. In \CONTEXT\ referencing is one of +%D the core features, although at a first glance probably nobody will +%D notice. This is good, because referencing should be as hidden as possible. %D -%D In paper documents, referencing comes down to cross -%D referencing, but in their interactive counterparts, is also -%D involves navigation. Many features implemented here are -%D therefore closely related to navigation. +%D Before we start implementing functionality we provide a way to set +%D up this mechanism. %D -%D Many \CONTEXT\ commands can optionally be fed with a -%D reference. Such a reference, when called upon, returns the -%D number of a figure, table, chapter etc, a piece of text, or -%D a pagenumber. +%D \showsetup{setupreferencing} +%D +%D In interactive documents verbose references don't always +%D make sense (what is a page number in an unnumbered +%D document). By setting the \type{interaction} variable, one +%D can influences the way interactive references are set. + +\installcorenamespace{referencing} + +\installdirectcommandhandler \??referencing {referencing} % \??referencing + +\newif\ifreferencing \referencingtrue + +\appendtoks + \edef\p_state{\referencingparameter\c!state}% + \ifx\p_state\v!start + \referencingtrue + \else + \referencingfalse + \fi +\to \everysetupreferencing + +%D In paper documents, referencing comes down to cross referencing, but in +%D their interactive counterparts, is also involves navigation. Many features +%D implemented here are therefore closely related to navigation. +%D +%D Many \CONTEXT\ commands can optionally be fed with a reference. Such a +%D reference, when called upon, returns the number of a figure, table, chapter +%D etc, a piece of text, or a pagenumber. %D %D There are three ways of defining a reference: %D @@ -108,8 +130,8 @@ \newcount\lastreferenceattribute \newcount\lastdestinationattribute -\def\dofinishfullreference#prefix#label{\normalexpanded{\ctxlatelua{structures.references.enhance("#prefix","#label")}}} -\def\dofinishtextreference#prefix#label{\normalexpanded{\ctxlatelua{structures.references.enhance("#prefix","#label",{})}}} +\def\dofinishfullreference#prefix#label{\normalexpanded{\ctxlatecommand{enhancereference("#prefix","#label")}}} +\def\dofinishtextreference#prefix#label{\normalexpanded{\ctxlatecommand{enhancereference("#prefix","#label",{})}}} \let\dofinishpagereference\dofinishfullreference \let\dofinishuserreference\dofinishfullreference @@ -143,7 +165,7 @@ \edef\currentreferencekind {#kind}% \edef\currentreferencelabels {#labels}% \edef\currentreferenceuserdata {#userdata}% - \edef\currentreferenceexpansion{\@@rfexpansion}% {\referenceparameter\c!expansion} + \edef\currentreferenceexpansion{\referencingparameter\c!expansion}% {\referenceparameter\c!expansion} \ifx\currentreferencelabels\empty \lastdestinationattribute\attributeunsetvalue \else @@ -163,7 +185,7 @@ % beware, the structures.references.set writes a % \setnextinternalreference \strc_references_start_destination_nodes - \ctxlua{structures.references.setandgetattribute("\currentreferencekind", "\referenceprefix","\currentreferencelabels", + \ctxcommand{setreferenceattribute("\currentreferencekind", "\referenceprefix","\currentreferencelabels", { references = { % internal = \nextinternalreference, % no need for an internal as we have an explicit @@ -210,7 +232,7 @@ \lastdestinationattribute\attributeunsetvalue \else \strc_references_start_destination_nodes - \ctxlua{structures.references.setandgetattribute("\s!page", "\referenceprefix","\currentreferencelabels", + \ctxcommand{setreferenceattribute("\s!page", "\referenceprefix","\currentreferencelabels", { references = { block = "\currentsectionblock", @@ -248,7 +270,7 @@ \def\strc_references_set_simple_page_reference#label% {\iflocation \strc_references_start_destination_nodes - \ctxlua{structures.references.setandgetattribute("\s!page", "\referenceprefix","#label", + \ctxcommand{setreferenceattribute("\s!page", "\referenceprefix","#label", { references = { % block = "\currentsectionblock", @@ -268,7 +290,7 @@ \def\strc_references_get_simple_page_reference#label% {\iflocation - \ctxlua{structures.references.inject("\referenceprefix","#label",\number\ht\strutbox,\number\dp\strutbox,\extrareferencearguments)}% + \ctxcommand{injectreference("\referenceprefix","#label",\number\ht\strutbox,\number\dp\strutbox,\extrareferencearguments)}% \xdef\currentreferenceattribute{\number\lastreferenceattribute}% \else \xdef\currentreferenceattribute{\number\attributeunsetvalue}% @@ -437,13 +459,13 @@ {\dodoubleempty\strc_references_define_reference} \def\strc_references_define_reference[#name][#specification]% - {\ctxlua{structures.references.define("\referenceprefix","#name",\!!bs\detokenize{#specification}\!!es)}} + {\ctxcommand{definereference("\referenceprefix","#name",\!!bs\detokenize{#specification}\!!es)}} \unexpanded\def\resetreference[#name]% - {\ctxlua{structures.references.reset("\referenceprefix","#name")}} + {\ctxcommand{resetreference("\referenceprefix","#name")}} \def\setpagereference#name#specification% hm,. low level ? - {\ctxlua{structures.references.define("","#name",\!!bs\v!page(\luaescapestring{#specification})\!!es)}} + {\ctxcommand{definereference("","#name",\!!bs\v!page(\luaescapestring{#specification})\!!es)}} %D Chained references are defined as: %D @@ -473,13 +495,13 @@ \newconditional\gotonewwindow \setfalse\gotonewwindow \def\expandtexincurrentreference % will happen in lua some time - {\ifcase\referencehastexstate\else\ctxlua{structures.references.expandcurrent()}\fi} + {\ifcase\referencehastexstate\else\ctxcommand{expandcurrentreference()}\fi} \def\expandreferenceoperation#tag#content{\ctxcommand{setreferenceoperation(#tag,\!!bs#content\!!es)}} \def\expandreferencearguments#tag#content{\ctxcommand{setreferencearguments(#tag,\!!bs#content\!!es)}} \def\doifreferencefoundelse#labels#yes#nop% - {\ctxlua{structures.references.doifelse("\referenceprefix","#labels",\luaconditional\highlighthyperlinks,\luaconditional\gotonewwindow)}% + {\ctxcommand{doifelsereference("\referenceprefix","#labels",\luaconditional\highlighthyperlinks,\luaconditional\gotonewwindow)}% {\expandtexincurrentreference #yes}% {#nop}} @@ -562,8 +584,8 @@ %D the special driver modules (see \type{spec-ini}). The flag %D \type{\iflocation} signals if we're in interactive mode. -\ifx\buttonheight\undefined \newdimen\buttonheight \fi -\ifx\buttonwidth \undefined \newdimen\buttonwidth \fi +\ifdefined\buttonheight \else \newdimen\buttonheight \fi +\ifdefined\buttonwidth \else \newdimen\buttonwidth \fi %D Internal references can best be set using the next few %D macros. Setting such references to unique values is @@ -588,14 +610,14 @@ {\global\advance\locationcount\plusone} \def\setnextinternalreferences#kind#name% plural - {\ctxlua{structures.references.setnextinternal("#kind","#name")}} + {\ctxcommand{setnextinternalreference("#kind","#name")}} \def\getinternalorderreference#kind#name% - {\ctxlua{structures.references.currentorder("#kind","#name")}} + {\ctxcommand{currentreferenceorder("#kind","#name")}} \def\thisissomeinternal#kind#name% only for old time sake {\begingroup - \ctxlua{structures.references.setinternalreference("","#kind:#name")}% + \ctxcommand{setinternalreference("","#kind:#name")}% \hbox attr \destinationattribute\lastdestinationattribute{}% \endgroup} @@ -630,8 +652,6 @@ %D \goto{some text}[\v!action(PreviousJump] %D \stoptyping -\newif\ifreferencing \referencingtrue - %D One can also activate an automatic prefix mechanism. By %D setting the \type{\prefix} variable to \type{+}, the prefix %D is incremented, when set to \type{-} or empty, the prefix is @@ -639,64 +659,24 @@ \newcount\prefixcounter -%D These settings are accomplished by: -%D -%D \showsetup{setupreferencing} -%D -%D In interactive documents verbose references don't always -%D make sense (what is a page number in an unnumbered -%D document). By setting the \type{interaction} variable, one -%D can influences the way interactive references are set. - -\newtoks \everysetupreferencing - -\unexpanded\def\setupreferencing - {\dosingleargument\strc_references_setup_referencing} - -\def\strc_references_setup_referencing[#settings]% - {\getparameters[\??rf][\c!prefix=\s!unknown,#settings]% - \the\everysetupreferencing} - -\appendtoks - \processaction - [\@@rfstate] - [ \v!stop=>\referencingfalse, - \v!start=>\referencingtrue]% -\to \everysetupreferencing - \newconditional\autocrossfilereferences \appendtoks - \doifelse\@@rfautofile\v!yes\settrue\setfalse\autocrossfilereferences + \edef\p_autofile{\referencingparameter\c!autofile}% + \ifx\p_autofile\v!yes + \settrue \autocrossfilereferences + \else + \setfalse\autocrossfilereferences + \fi \to \everysetupreferencing -\def\exportreferences - {\doif\@@rfexport\v!yes{\ctxlua{structures.references.export()}}} - \appendtoks - \exportreferences + \edef\p_export{\referencingparameter\c!export}% + \ifx\p_export\v!yes + \ctxcommand{exportreferences()}% + \fi \to \everygoodbye -\def\incrementreferenceprefix{+} -\def\decrementreferenceprefix{-} - -\unexpanded\def\setupreferenceprefix[#prefix]% - {\edef\@@rfprefix{#prefix}% - \ifx\@@rfprefix\empty - \let\referenceprefix\empty - \else\ifx\@@rfprefix\incrementreferenceprefix - \global\advance\prefixcounter \plusone - \edef\referenceprefix{\the\prefixcounter}% - \let\@@rfprefix\s!unknown - \else\ifx\@@rfprefix\decrementreferenceprefix - \let\referenceprefix\empty - \let\@@rfprefix\s!unknown - \else\ifx\@@rfprefix\s!unknown - % forget about it - \else - \edef\referenceprefix{\@@rfprefix}% expanded ! - \fi\fi\fi\fi} - \unexpanded\def\setupglobalreferenceprefix[#prefix]% {\xdef\referenceprefix{#prefix}} @@ -707,8 +687,28 @@ \unexpanded\def\popreferenceprefix {\popmacro\referenceprefix} +\def\m_strc_references_prefix_yes{+} +\def\m_strc_references_prefix_nop{-} + +\unexpanded\def\setupreferenceprefix[#prefix]% + {\edef\p_prefix{#prefix}% + \ifx\p_prefix\empty + \let\referenceprefix\empty + \else\ifx\p_prefix\m_strc_references_prefix_yes + \letreferencingparameter\c!prefix\s!unknown + \global\advance\prefixcounter\plusone + \edef\referenceprefix{\the\prefixcounter}% + \else\ifx\p_prefix\m_strc_references_prefix_nop + \letreferencingparameter\c!prefix\s!unknown + \let\referenceprefix\empty + \else\ifx\p_prefix\s!unknown + % forget about it + \else + \let\referenceprefix\p_prefix + \fi\fi\fi\fi} + \appendtoks - \setupreferenceprefix[\@@rfprefix] + \setupreferenceprefix[\referencingparameter\c!prefix] \to \everysetupreferencing %D We can typeset a reference using \type{\in}, \type{\at} and @@ -808,11 +808,11 @@ \let\crlf\space \let\\\space \postponenotes - \@@rfleft + \referencingparameter\c!left \doifreferencefoundelse{#label} - {\goto{\limitatetext\currentreferencetitle\@@rfwidth\unknown}[#label]}% not so efficient (dup lookup) + {\goto{\limitatetext\currentreferencetitle{\referencingparameter\c!width}\unknown}[#label]}% not so efficient (dup lookup) {}% todo - \@@rfright + \referencingparameter\c!right \endgroup} %D The previously discussed setup macro lets us specify the @@ -883,7 +883,9 @@ \let\leftofreference \empty \let\rightofreference \empty -\setvalue{\??rf\c!interaction\v!all}% +\installcorenamespace{referencinginteraction} + +\setvalue{\??referencinginteraction\v!all}% {\the\leftreferencetoks \doifsometokselse\leftreferencetoks \leftofreferencecontent \donothing \leftofreference @@ -892,24 +894,24 @@ \doifsometokselse\rightreferencetoks\rightofreferencecontent\donothing \the\rightreferencetoks} -\setvalue{\??rf\c!interaction\v!label}% +\setvalue{\??referencinginteraction\v!label}% {\leftofreference \the\leftreferencetoks \the\rightreferencetoks \rightofreference} -\setvalue{\??rf\c!interaction\v!text}% +\setvalue{\??referencinginteraction\v!text}% {\leftofreference \currentreferencecontent \rightofreference} -\setvalue{\??rf\c!interaction\v!symbol}% +\setvalue{\??referencinginteraction\v!symbol}% {\referencesymbol} \def\referencesequence - {\csname \??rf\c!interaction - \ifcsname\??rf\c!interaction\@@rfinteraction\endcsname - \@@rfinteraction + {\csname\??referencinginteraction + \ifcsname\??referencinginteraction\referencingparameter\c!interaction\endcsname + \referencingparameter\c!interaction \else \v!all \fi @@ -1067,7 +1069,7 @@ \def\autoreferencelabeltextflag{*} % a proper key like 'auto' or 'name' can clash with a label key \unexpanded\def\autoreferencelabeltext - {\ctxlua{structures.references.getcurrentmetadata("name")}} + {\ctxcommand{getcurrentreferencemetadata("name")}} % \starttext % \definereferenceformat[inxx] [left=(,right=),text=txt] @@ -1144,7 +1146,7 @@ \attribute\referenceattribute\attributeunsetvalue \global\lastsavedreferenceattribute\attributeunsetvalue \iflocation - \ctxlua{structures.references.inject("\referenceprefix","#label",\number\ht\strutbox,\number\dp\strutbox,\extrareferencearguments)}% + \ctxcommand{injectreference("\referenceprefix","#label",\number\ht\strutbox,\number\dp\strutbox,\extrareferencearguments)}% \setlocationattributes \setstrut % can be option \global\lastsavedreferenceattribute\lastreferenceattribute @@ -1163,7 +1165,7 @@ \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{structures.references.inject("\referenceprefix","#label",\number\dimexpr\interactionparameter\c!height\relax,\number\dimexpr\interactionparameter\c!depth\relax,\extrareferencearguments)}% + \ctxcommand{injectreference("\referenceprefix","#label",\number\dimexpr\interactionparameter\c!height\relax,\number\dimexpr\interactionparameter\c!depth\relax,\extrareferencearguments)}% \setlocationattributes \attribute\referenceattribute\lastreferenceattribute \global\lastsavedreferenceattribute\lastreferenceattribute @@ -1182,9 +1184,9 @@ \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{structures.references.doifelse("\referenceprefix","#label",\extrareferencearguments)}% + \ctxcommand{doifelsereference("\referenceprefix","#label",\extrareferencearguments)}% {\expandtexincurrentreference - \ctxlua{structures.references.injectcurrentset(\number\ht\strutbox,\number\dp\strutbox)}% + \ctxcommand{injectcurrentreference(\number\ht\strutbox,\number\dp\strutbox)}% \setlocationattributes \setstrut % can be option \global\lastsavedreferenceattribute\lastreferenceattribute @@ -1205,9 +1207,9 @@ \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{structures.references.doifelse("\referenceprefix","#label",\extrareferencearguments)}% + \ctxcommand{doifelsereference("\referenceprefix","#label",\extrareferencearguments)}% {\expandtexincurrentreference - \ctxlua{structures.references.injectcurrentset(\number\dimexpr\interactionparameter\c!height\relax,\number\dimexpr\interactionparameter\c!depth\relax)}% + \ctxcommand{injectcurrentreference(\number\dimexpr\interactionparameter\c!height\relax,\number\dimexpr\interactionparameter\c!depth\relax)}% \setlocationattributes \global\lastsavedreferenceattribute\lastreferenceattribute \attribute\referenceattribute\lastreferenceattribute @@ -1226,7 +1228,7 @@ \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{structures.references.inject("\referenceprefix","#label",nil,nil,\extrareferencearguments)}% + \ctxcommand{injectreference("\referenceprefix","#label",nil,nil,\extrareferencearguments)}% \setlocationattributes \global\lastsavedreferenceattribute\lastreferenceattribute \dostarttagged\t!link\empty @@ -1243,7 +1245,7 @@ \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{structures.references.inject("\referenceprefix","#label",nil,nil,\extrareferencearguments)}% + \ctxcommand{injectreference("\referenceprefix","#label",nil,nil,\extrareferencearguments)}% \setlocationcolorspec{#resolver}% no consequence for strut \global\lastsavedreferenceattribute\lastreferenceattribute \dostarttagged\t!link\empty @@ -1260,7 +1262,7 @@ \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{structures.references.inject("\referenceprefix","#label",nil,nil,\extrareferencearguments)}% + \ctxcommand{injectreference("\referenceprefix","#label",nil,nil,\extrareferencearguments)}% \global\lastsavedreferenceattribute\lastreferenceattribute \dostarttagged\t!link\empty \hbox attr \referenceattribute \lastreferenceattribute {#content}% @@ -1276,9 +1278,9 @@ \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue \iflocation - \ctxlua{structures.references.doifelse("\referenceprefix","#label",\extrareferencearguments)}% + \ctxcommand{doifelsereference("\referenceprefix","#label",\extrareferencearguments)}% {\expandtexincurrentreference - \ctxlua{structures.references.injectcurrentset(nil,nil)}% + \ctxcommand{injectcurrentreference(nil,nil)}% \setlocationattributes \global\lastsavedreferenceattribute\lastreferenceattribute \dostarttagged\t!link\empty @@ -1298,8 +1300,8 @@ \ht\scratchbox#height% \global\lastsavedreferenceattribute\attributeunsetvalue \attribute\referenceattribute\attributeunsetvalue - \ctxlua{structures.references.doifelse("\referenceprefix","#label",\extrareferencearguments)}% - {\ctxlua{structures.references.injectcurrentset(nil,nil)}% + \ctxcommand{doifelsereference("\referenceprefix","#label",\extrareferencearguments)}% + {\ctxcommand{injectcurrentreference(nil,nil)}% \global\lastsavedreferenceattribute\lastreferenceattribute \hbox attr \referenceattribute \lastreferenceattribute {\box\scratchbox}} {\box\scratchbox}% @@ -1425,7 +1427,7 @@ \def\strc_references_do_special_from[#label]% {\dontleavehmode - \goto{\ctxlua{structures.references.from("#label")}}[fileorurl(#label)]} + \goto{\ctxcommand{from("#label")}}[fileorurl(#label)]} \def\dofromurldescription#content% called at the lua end {#content} @@ -1470,14 +1472,14 @@ {\dotripleargument\strc_references_define_program} \def\strc_references_define_program[#name][#program][#description]% - {\ctxlua{structures.references.programs.define("#name","#program","#description")}} + {\ctxcommand{defineprogram("#name","#program","#description")}} \def\program[#name]% incompatible, more consistent, hardy used anyway {\dontleavehmode \begingroup \dousestyleparameter\@@prstyle \dousecolorparameter\@@prcolor - \ctxlua{structures.references.programs.get("#name","\@@pralternative","\@@prspace")}% + \ctxcommand{getprogram("#name","\@@pralternative","\@@prspace")}% \endgroup} %D As we can see, we directly use the special reference @@ -1571,7 +1573,11 @@ \setbox\scratchbox\hbox{#text}% to be solved some day \ifdim\wd\scratchbox>\zeropoint \unhbox\scratchbox - \doifsomething\@@rfseparator{\removeunwantedspaces\@@rfseparator}% remove is new + \edef\p_separator{\referencingparameter\c!separator}% + \ifx\p_separator\empty \else + \removeunwantedspaces % remove is new + \p_separator + \fi \else \unhbox\scratchbox \fi @@ -1699,7 +1705,9 @@ % todo: parameterhandler -\def\getreferencestructureprefix#kind#name#category% +\installcorenamespace{referencingprefix} + +\def\getreferencestructureprefix#kind#name#category% name will change {{ prefix = "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefix", separatorset = "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixseparatorset", @@ -1715,22 +1723,22 @@ \def\strc_references_setup_reference_structure_prefix[#kind][#category][#settings]% {\ifthirdargument - \getparameters[\??rf:\c!prefix:#kind:#category][#settings]% + \getparameters[\??referencingprefix#kind:#category][#settings]% \else\ifsecondargument - \getparameters[\??rf:\c!prefix::#kind][#category]% + \getparameters[\??referencingprefix:#kind][#category]% \fi\fi} \def\referencestructureprefixparameter#kind#name#category#parameter% - {\ifcsname\??rf:\c!prefix:#name:#category#parameter\endcsname - \csname\??rf:\c!prefix:#name:#category#parameter\endcsname - \else\ifcsname\??rf:\c!prefix:#kind:#category#parameter\endcsname - \csname \??rf:\c!prefix:#kind:#category#parameter\endcsname - \else\ifcsname\??rf:\c!prefix::#category#parameter\endcsname - \csname \??rf:\c!prefix::#category#parameter\endcsname + {\ifcsname\??referencingprefix#name:#category#parameter\endcsname + \csname\??referencingprefix#name:#category#parameter\endcsname + \else\ifcsname\??referencingprefix#kind:#category#parameter\endcsname + \csname \??referencingprefix#kind:#category#parameter\endcsname + \else\ifcsname\??referencingprefix:#category#parameter\endcsname + \csname \??referencingprefix:#category#parameter\endcsname \fi\fi\fi} \def\currentreferencedefault - {\ctxlua{structures.references.filter("default",\ctxlua{structures.references.getcurrentprefixspec("\v!default")})}} + {\ctxcommand{filterdefaultreference()}} %D Not all support is visible by looking at the \TEX\ code; here is one of those:^ %D |