diff options
Diffstat (limited to 'tex/context/base/strc-enu.mkvi')
-rw-r--r-- | tex/context/base/strc-enu.mkvi | 371 |
1 files changed, 371 insertions, 0 deletions
diff --git a/tex/context/base/strc-enu.mkvi b/tex/context/base/strc-enu.mkvi new file mode 100644 index 000000000..9cacbd556 --- /dev/null +++ b/tex/context/base/strc-enu.mkvi @@ -0,0 +1,371 @@ +%D \module +%D [ file=strc-enu, % moved from strc-des +%D version=2008.10.20, +%D title=\CONTEXT\ Structure Macros, +%D subtitle=Enumerations, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\writestatus{loading}{ConTeXt Structure Macros / Enumerations} + +\unprotect + +% command -> headcommand + +%D Enumerations are just super descriptions. Therefore we implement +%D them as an extension. After all, the keys don't clash. In order +%D to be able to differentiate between specific settings we use +%D some flags. Unfortunately we have some historic differences +%D in default values. Therefore we push an extra step in the +%D parent chain (we might do the same for regular descriptions). + +%D In order to be more flexible with theorems Aditya Mahajan added +%D support for titles and endsymbols. At the same time we added more +%D flexible support for inheriting numbers. +%D +%D \startbuffer +%D \defineenumeration[one] +%D \defineenumeration[two] [one] % clone one +%D \defineenumeration[three] [counter=one,style=slanted] % only use counter of one +%D \defineenumeration[four] [three] % clone three +%D \defineenumeration[five] [three] [counter=five] % clone three and use own counter +%D \defineenumeration[six] [three] [counter=four] % clone tree and use counter four (undefined) +%D +%D \startone test test 6 \stopone +%D \starttwo test test 7 \stoptwo +%D \startthree test test 8 \stopthree +%D \startfour test test 9 \stopfour +%D \startfive test test 2 \stopfive +%D \startsix test test 10 \stopsix +%D \stopbuffer +%D +%D \typebuffer \start \getbuffer \stop +%D +%D \starttyping +%D \setupenumerations[one] [prefix=yes,prefixsegments=section] +%D \setupenumerations[two] [prefix=yes,prefixsegments=section] +%D \setupenumerations[three][prefix=yes,prefixsegments=section] +%D \setupenumerations[four] [prefix=yes,prefixsegments=chapter:section] +%D \setupenumerations[five] [prefix=yes,prefixsegments=chapter:section] +%D \setupenumerations[six] [prefix=yes,prefixsegments=chapter:section] +%D \stoptyping + +% list and titles are experimental +% +% \definedescription[test] [location=left,hang=4,headalign={right},distance=1em,list=test] +% \defineenumeration[lemma][title=yes,right=:,textdistance=1em, location=top, titlestyle=\bs,list=lemma] +% \defineenumeration[ammel][title=yes,right=:,textdistance=.5em,location=left,titlestyle=\it,width=9em] +% +% \placelist[enumeration:lemma] +% \placelist[description:test][width=0pt] +% +% \starttest {something something something} \input zapf \stoptest +% \startlemma {with a title of a certain length} \input tufte \stoplemma +% \startammel {with a title} \input zapf \stopammel +% +% \defineenumeration[lemma][...] +% \defineenumeration[titledlemma][lemma][title=yes,right=:,text=lemma,list=lemma] + +\installcorenamespace{enumeration} + +\installcommandhandler \??enumeration {enumeration} \??enumeration + +\let\setupenumerations\setupenumeration + +\setupenumerations % check with old + [\c!alternative=\v!top, + \c!headstyle=\v!bold, + \c!titlestyle=\v!bold, + %\c!style=, + %\c!color=, + %\c!headcolor=, + %\c!titlecolor=, + \c!width=8em, + \c!distance=0pt, +\c!distance=1em, + \c!titledistance=0.5em, + %\c!hang=, + %\c!sample=, + %\c!align=, + %\c!headalign=, + \c!margin=\v!no, + \c!before=\blank, + \c!inbetween=\blank, + \c!after=\blank, + \c!indentnext=\v!yes, + \c!indenting=\v!never, + \c!titleleft=(, + \c!titleright=), + %\c!closesymbol=, + \c!closecommand=\wordright, + \c!display=\v!yes, + %\c!command=, + \c!titlecommand=, + \c!expansion=\v!no, + %\c!xmlsetup=, + %\s!catcodes=, + % + \c!way=\v!by\v!text, + \c!prefix=\v!no, + \c!prefixconnector=., + %\c!starter=, + %\c!stopper=, + \c!text=\currentenumeration, + \c!number=\v!yes, % else description + \c!start=0, + \c!state=\v!start, + \c!levels=4] + +\unexpanded\def\strc_define_commands_enumeration#1#2#3% current level parent + {\doifelsenothing{#3} + {\defineconstruction[#1][\s!handler=\v!enumeration,\c!level=#2]}% + {\defineconstruction[#1][#3][\s!handler=\v!enumeration,\c!level=#2]}% + \setuevalue{\e!next #1}{\strc_enumerations_next }% + \setuevalue{\c!reset#1}{\strc_enumerations_reset }% + %setuevalue{\c!set #1}{\strc_enumerations_set }% + \setuevalue {#1}{\strc_enumerations_command{\currentenumeration}}% + \setuevalue{\e!start#1}{\strc_enumerations_start {\currentenumeration}}% + \setuevalue{\e!stop #1}{\strc_enumerations_stop }} + +\appendtoks + \ifx\currentenumerationparent\empty + % clone => parent | subclone => clone | subsubclone => subclone + \let\currentenumerationsub\empty + \strc_define_commands_enumeration + {\currentenumerationsub\currentenumeration}% + \plusone + \empty + \edef\p_levels{\enumerationparameter\c!levels}% + \dostepwiserecurse\plustwo\p_levels\plusone + {\strc_define_commands_enumeration + {\v!sub\currentenumerationsub\currentenumeration}% + \recurselevel + {\currentenumerationsub\currentenumeration}% + \edef\currentenumerationsub{\v!sub\currentenumerationsub}}% + \else + % clone => parent | subclone => subparent | subsubclone => subsubparent + \let\currentenumerationsub\empty + \edef\p_levels{\enumerationparameter\c!levels}% + \dorecurse\p_levels + {\strc_define_commands_enumeration + {\currentenumerationsub\currentenumeration}% + \recurselevel + {\currentenumerationsub\currentenumerationparent}% + \edef\currentenumerationsub{\v!sub\currentenumerationsub}}% + \fi + \edef\p_counter{\enumerationparameter\s!counter}% can inherit from parent + \ifx\p_counter\empty % + \let\p_counter\currentenumeration + \fi + \doifstructurecounterelse\p_counter\donothing{\strc_enumerations_define_counter\p_counter}% + \letenumerationparameter\s!counter\p_counter + \strc_enumerations_setup_counter\currentenumeration +\to \everydefineenumeration + +\setvalue{\??constructioninitializer\v!enumeration}% + {\let\currentenumeration \currentconstruction + \let\constructionparameter \enumerationparameter + \let\detokenizedconstructionparameter\detokenizedenumerationparameter + \let\letconstructionparameter \letenumerationparameter + \let\useconstructionstyleandcolor \useenumerationstyleandcolor + \let\setupcurrentconstruction \setupcurrentenumeration + \edef\p_number{\constructionparameter\c!number}% + \ifx\p_number\v!yes + \settrue\c_strc_constructions_number_state + \iftrialtypesetting + \strc_counters_save\currentconstructionnumber + \fi + \strc_counters_increment_sub\currentconstructionnumber\currentconstructionlevel + \else + \setfalse\c_strc_constructions_number_state + \fi + \edef\p_title{\constructionparameter\c!title}% + \ifx\p_title\v!yes + \settrue\c_strc_constructions_title_state + \else + \setfalse\c_strc_constructions_title_state + \fi} + +\setvalue{\??constructionfinalizer\v!enumeration}% + {\ifconditional\c_strc_constructions_number_state + \iftrialtypesetting + \strc_counters_restore\currentconstructionnumber + \fi + \fi} + +%D Interfaces: + +\let\strc_enumerations_command\strc_descriptions_command +\let\strc_enumerations_start \strc_descriptions_start +\let\strc_enumerations_stop \strc_descriptions_stop + +\unexpanded\def\strc_enumerations_next {\strc_counters_increment_sub{\specificconstructionnumber\currentconstruction}{\currentconstructionlevel}} +\unexpanded\def\strc_enumerations_reset {\strc_counters_reset_sub {\specificconstructionnumber\currentconstruction}{\currentconstructionlevel}} +%unexpanded\def\strc_enumerations_set #3{\strc_counters_set_sub {\specificconstructionnumber\currentconstruction}{\currentconstructionlevel}{#2}} + +%D Counters + +%D WILL MOVE: + +\newtoks\everysetupenumerationcounter +\let\v_strc_enumerations_counter_name\empty + +\def\strc_enumerations_setup_counter#1% + {\edef\v_strc_enumerations_counter_name{#1}% only used in the token list + \edef\currentconstruction{#1}% + \the\everysetupenumerationcounter} + +\def\strc_enumerations_define_counter#1% todo: fast inheritance (was mainparameter + {\definestructurecounter[#1]% + \strc_enumerations_setup_counter{#1}} + +\appendtoks + \dostructurecountersetup\v_strc_enumerations_counter_name\constructionparameter +\to \everysetupenumerationcounter + +\def\currentconstructionnumber {\constructionparameter\s!counter} +\def\specificconstructionnumber#1{\namedconstructionparameter{#1}\s!counter} + +%D Initializer: + +%D The handlers. + +\newtoks\everyenumeration + +\appendtoks + \disablepseudocaps % sorry, uppercase causes troubles +\to \everyenumeration + +\expandafter\let\csname\??constructionmainhandler \v!enumeration\expandafter\endcsname\csname\??constructionmainhandler \v!description\endcsname +\expandafter\let\csname\??constructioncommandhandler\v!enumeration\expandafter\endcsname\csname\??constructioncommandhandler\v!description\endcsname +\expandafter\let\csname\??constructionstarthandler \v!enumeration\expandafter\endcsname\csname\??constructionstarthandler \v!description\endcsname +\expandafter\let\csname\??constructionstophandler \v!enumeration\expandafter\endcsname\csname\??constructionstophandler \v!description\endcsname + +\setvalue{\??constructiontexthandler\v!enumeration}% + {\begingroup + \useconstructionstyleandcolor\c!headstyle\c!headcolor + \strc_enumerations_text + \endgroup} + +\unexpanded\def\strc_enumerations_text + {\the\everyenumeration % will become obsolete + \ifconditional\c_strc_constructions_number_state + \ifx\currentconstructionreference\!!plustoken + \strc_enumerations_full_number_symbol + \else\ifx\currentconstructionreference\!!minustoken + \strc_enumerations_full_number_nop + \else + \strc_enumerations_full_number_coupling + \fi\fi + \else + \strc_enumerations_full_number_nop + \fi} + +\unexpanded\def\strc_enumerations_inject_text_with_space + {\edef\p_text{\constructionparameter\c!text}% + \ifx\p_text\empty \else + \p_text + \removeunwantedspaces + \nobreakspace + \fi} + +\unexpanded\def\strc_enumerations_inject_extra_text + {\ifconditional\c_strc_constructions_title_state + \ctxcommand{doiflisthastitleelse("\currentconstructionmain",\currentconstructionlistentry)} + \strc_enumerations_inject_extra_text_indeed + \donothing + \fi} + +\unexpanded\def\strc_enumerations_inject_text + {\constructionparameter\c!numbercommand + {\constructionparameter\c!text}} + +% head ( number title ) + +\unexpanded\def\strc_enumerations_inject_extra_text_indeed + {\begingroup + \hskip\constructionparameter\c!titledistance % we listen to the headstyle + \useconstructionstyleandcolor\c!titlestyle\c!titlecolor + \constructionparameter\c!titlecommand + {\constructionparameter\c!titleleft + \ctxcommand{savedlisttitle("\currentconstructionmain",\currentconstructionlistentry)}% + \constructionparameter\c!titleright}% + \endgroup} + +\unexpanded\def\strc_enumerations_inject_symbol % todo check + {\constructionparameter\c!left + \constructionparameter\c!symbol + \constructionparameter\c!right} + +\unexpanded\def\strc_enumerations_inject_number + {\constructionparameter\c!left + \constructionparameter\c!starter + \ctxcommand{savedlistprefixednumber("\currentconstructionmain",\currentconstructionlistentry)}% + \constructionparameter\c!stopper + \constructionparameter\c!right} + +\unexpanded\def\strc_enumerations_inject_text_and_number + {\constructionparameter\c!numbercommand + {\strc_enumerations_inject_text_with_space + \strc_enumerations_inject_number}} + +\unexpanded\def\strc_enumerations_inject_text_and_symbol + {\constructionparameter\c!numbercommand + {\strc_enumerations_inject_text_with_space + \strc_enumerations_inject_symbol}} + +\unexpanded\def\strc_enumerations_full_number_yes + {\constructionparameter\c!headcommand + {\begstrut + \strc_enumerations_inject_text_and_number + \strc_enumerations_inject_extra_text + \endstrut}} + +\unexpanded\def\strc_enumerations_full_number_nop + {\constructionparameter\c!headcommand + {\begstrut + \strc_enumerations_inject_text + \strc_enumerations_inject_extra_text + \endstrut}} + +\unexpanded\def\strc_enumerations_full_number_symbol + {\constructionparameter\c!headcommand + {\begstrut + \strc_enumerations_inject_text_and_symbol + \strc_enumerations_inject_extra_text + \endstrut}} + +% to be used in for instance: +% +% coupling=questions .... coupling=answers +% +% we will provide some more control, like skipping etc or reference relates + +% todo + + \unexpanded\def\strc_enumerations_full_number_coupling + {\iflocation + \strc_enumerations_full_number_yes + \else + \iftrialtypesetting \else + % \doenumerationregistercoupling + \fi + \strc_enumerations_full_number_yes + \edef\p_coupling{\constructionparameter\c!coupling}% + \ifx\p_coupling\empty \else + \symbolreference[order(construction:\p_coupling:\nextinternalorderreference)]% + \fi + \fi} + + \def\skipenumerationcoupling[#1]% e.g. for questions with no answer + {\ctxlua{structures.references.setnextorder("construction","#1")}} + + \unexpanded\def\structurecounterreference#1% + {[enumref: #1]} + +\protect \endinput |