%D \module %D [ file=strc-syn, %D version=2008.10.20, %D title=\CONTEXT\ Structure Macros, %D subtitle=Synonyms and Sorting, %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 / Synonyms and Sorting} \registerctxluafile{strc-syn}{1.001} % todo: add 'define only' option to descriptions, then add sorting (also based on key) % and call to definition -> replaces this module \unprotect % split but common in lua \def\preprocessexpansion#1#2#3#4% {\ifx#1\s!xml \xmlstartraw \xdef#2{#4}% \xmlstopraw \globallet#3\s!xml \else \ifx#1\v!yes \xdef#2{#4}% \else \xdef#2{\detokenize{#4}}% \fi \globallet#3\s!tex \fi} %D We now use a simple list variant: \installcorenamespace {simplelist} \installcommandhandler \??simplelist {simplelist} \??simplelist \let\setupsimplelists\setupsimplelist \setupsimplelists[% %c!title=, %c!text=, % %c!style=, %c!color=, %c!command=, %c!align=, % %c!headstyle=, %c!headcolor=, %c!headalign=, % %c!titlestyle=, %c!titlecolor=, %c!titlecommand=, %c!titleleft=, %c!titleright=, % %c!closesymbol=, %c!closecommand=, % \c!alternative=\v!left, \c!display=\v!yes, \c!width=7\emwidth, \c!distance=\emwidth, \c!titledistance=.5\emwidth, %c!hang=, %c!sample=, \c!margin=\v!no, \c!before=\blank, \c!inbetween=\blank, \c!after=\blank, %c!indentnext=, %c!indenting=, % \c!expansion=\v!no, %c!xmlsetup=, %s!catcodes=, \s!language=\currentmainlanguage, ] \appendtoks \setfalse\c_strc_constructions_define_commands \ifx\currentsimplelistparent\empty \defineconstruction[\currentsimplelist][\s!handler=\v!simplelist,\c!level=1]% \else \defineconstruction[\currentsimplelist][\currentsimplelistparent][\s!handler=\v!simplelist,\c!level=1]% \fi \settrue\c_strc_constructions_define_commands \to \everydefinesimplelist \setuvalue{\??constructioninitializer\v!simplelist}% {\let\currentsimplelist \currentconstruction \let\constructionparameter \simplelistparameter \let\detokenizedconstructionparameter\detokenizedsimplelistparameter \let\letconstructionparameter \letsimplelistparameter \let\useconstructionstyleandcolor \usesimpleliststyleandcolor \let\setupcurrentconstruction \setupcurrentsimplelist} \setuvalue{\??constructionfinalizer\v!simplelist}% {} \setuvalue{\??constructiontexthandler\v!simplelist}% {\begingroup \useconstructionstyleandcolor\c!headstyle\c!headcolor \the\everyconstruction \constructionparameter\c!headcommand {\strut \currentsimplelistentry}% \endgroup} % And we build on top of this. \ifdefined\dotagsynonym \else \let\dotagsynonym\relax \fi \ifdefined\dotagsorting \else \let\dotagsorting\relax \fi \definesimplelist [\v!synonym] [\c!state=\v!start, %\c!synonymstyle=, %\c!textstyle=, %\c!headstyle=, %\c!headcolor=, %\c!criterium=, \c!location=\v!left, \c!width=5\emwidth, \c!distance=\zeropoint, %\c!sample=, %\c!hang=, %\c!align=, %\c!before=, %\c!inbetween=, %\c!after=, \c!indentnext=\v!no, %\c!expansion=, \c!method=] \let\setupsynonyms\setupsimplelist \unexpanded\def\definesynonyms {\doquadrupleempty\strc_synonyms_define} \def\strc_synonyms_define[#1][#2][#3][#4]% name plural \meaning \use {\edef\currentsynonym{#1}% \iffourthargument \unexpanded\def#4##1{\strc_synonyms_insert{#1}{##1}}% name tag \ifthirdargument \unexpanded\def#3##1{\strc_synonyms_insert_meaning{#1}{##1}}% \meaning \fi \setuvalue{#1}{\definesynonym[\v!no][#1]}% \name \else \ifthirdargument \unexpanded\def#3##1{\strc_synonyms_insert_meaning{#1}{##1}}% \meaning \fi \setuvalue{#1}{\definesynonym[\v!yes][#1]}% \name \fi % % \checksynonymparent % \setupcurrentsynonym[\s!single={#1},\s!multi={#2}]% \setfalse\c_strc_constructions_define_commands \definesimplelist [\currentsynonym]% [\v!sorting] [\s!single={#1},% \s!multi={#2}]% \settrue\c_strc_constructions_define_commands % \presetheadtext[#2=\Word{#2}]% changes the \if...argument % \setvalue{\e!setup #2\e!endsetup}{\setupsynonym[#1]}% obsolete definition \setvalue{\e!place \e!listof#2}{\placelistofsynonyms[#1]}% accepts extra argument \setvalue{\e!complete\e!listof#2}{\completelistofsynonyms[#1]}} \unexpanded\def\definesynonym {\dotripleempty\strc_synonyms_define_entry} \def\strc_synonyms_define_entry[#1][#2][#3]#4#5% {\begingroup \edef\currentsynonym{#2}% \edef\currentsynonymtag{#3}% \let\currentsimplelist\currentsimplelist \ifx\currentsynonymtag\empty \edef\currentsynonymtag{#4}% \fi \ifx\currentsynonymtag\empty % todo: error message \else \edef\currentsynonymexpansion{\simplelistparameter\c!expansion}% \preprocessexpansion\currentsynonymexpansion\currentsynonymtext \currentsynonymcoding{#4}% \preprocessexpansion\currentsynonymexpansion\currentsynonymmeaning\currentsynonymcoding{#5}% \ctxcommand{registersynonym("\currentsynonym", "synonym", { metadata = { catcodes = \the\catcodetable, coding = "\currentsynonymcoding", xmlroot = \ifx\currentsynonymcoding\s!xml "\xmldocument" \else nil \fi, }, definition = { tag = "\currentsynonymtag", synonym = \!!bs\currentsynonymtext\!!es, meaning = \!!bs\currentsynonymmeaning\!!es, used = false, } })}% \doif{#1}\v!yes{\setuxvalue\currentsynonymtag{\strc_synonyms_insert{\currentsynonym}{\currentsynonymtag}}}% \fi \endgroup} \unexpanded\def\registersynonym {\dodoubleargument\strc_synonyms_register} \def\strc_synonyms_register[#1][#2]% {\ctxcommand{registerusedsynonym("#1","#2")}} \unexpanded\def\strc_synonyms_insert_meaning#1#2% name tag {\begingroup \def\currentsimplelist{#1}% \usesimpleliststyleandcolor\c!textstyle\c!textcolor \simplelistparameter\c!textcommand{\ctxcommand{synonymmeaning("#1","#2")}}% \endgroup} \unexpanded\def\strc_synonyms_insert#1#2% name tag {\begingroup \edef\currentsimplelist{#1}% \let\currentsynonym\currentsimplelist % for a while \def\currentsynonymtag{#2}% \dostarttagged\t!synonym\currentsynonym \dotagsynonym \usesimpleliststyleandcolor\c!synonymstyle\c!synonymcolor \simplelistparameter\c!synonymcommand{\ctxcommand{synonymname("#1","#2")}}% \dostoptagged \normalexpanded{\endgroup\simplelistparameter\c!next}} \unexpanded\def\placelistofsynonyms {\dodoubleempty\strc_synonyms_place_list} \def\strc_synonyms_place_list[#1][#2]% {\begingroup \edef\currentsimplelist{#1}% \strc_constructions_initialize{#1}% \setupcurrentsimplelist[#2]% \let\synonymentry\strc_synonym_normal \startpacked \ctxcommand{processsynonyms('#1',{ criterium = "\simplelistparameter\c!criterium", language = "\simplelistparameter\s!language", method = "\simplelistparameter\c!method", })}% \stoppacked \endgroup} \def\completelistofsynonyms {\dodoubleempty\strc_synonyms_complete_list} \def\strc_synonyms_complete_list[#1][#2]% {\begingroup \edef\currentsimplelist{#1}% \normalexpanded{\startnamedsection[\v!chapter][\c!title={\headtext{\simplelistparameter\s!multi}},\c!reference=#1]}% \strc_synonyms_place_list[#1][#2]% \page \stopnamedsection \endgroup} \unexpanded\def\strc_synonym_normal#1#2#3#4% {\begingroup \def\currentsimplelistentry{#3}% \csname\??constructionstarthandler\v!construction\endcsname #4% \csname\??constructionstophandler\v!construction\endcsname \endgroup} %D Sorting (a simplified version of synonym). \definesimplelist [\v!sorting] [\c!state=\v!start, %\c!command=, % we test for defined ! %\c!criterium=, %\c!style=, %\c!before=, \c!after=\endgraf, %\c!expansion=, \c!method=] \let\setupsorting\setupsimplelist \unexpanded\def\definesorting {\dotripleempty\strc_sorting_define} % if #3=\relax or \v!none, then no command but still protected \def\strc_sorting_define[#1][#2][#3]% {\edef\currentsorting{#1}% \ifthirdargument \doifnot{#3}\v!none {\ifx#3\relax \else \unexpanded\def#3##1{\strc_sorting_insert{#1}{##1}}% \fi}% \setuvalue{#1}{\definesort[\v!no][#1]}% \else \setuvalue{#1}{\definesort[\v!yes][#1]}% \fi \setfalse\c_strc_constructions_define_commands \definesimplelist [\currentsorting]% [\v!sorting] [\s!single={#1},% \s!multi={#2}]% \settrue\c_strc_constructions_define_commands % \presetheadtext[#2=\Word{#2}]% after \ifthirdargument -) % \setvalue{\e!setup #2\e!endsetup}{\setupsorting[#1]}% obsolete definition \setvalue{\e!place \e!listof#2}{\placelistofsorts[#1]}% \setvalue{\e!complete\e!listof#2}{\completelistofsorts[#1]}} \unexpanded\def\definesort {\dotripleempty\strc_sorting_define_entry} \def\strc_sorting_define_entry[#1][#2][#3]#4% {\begingroup \edef\currentsorting{#2}% \edef\currentsortingtag{#3}% \let\currentsimplelist\currentsimplelist \ifx\currentsortingtag\empty \edef\currentsortingtag{#4}% \fi \ifx\currentsortingtag\empty % todo: error message \else \edef\currentsortingexpansion{\simplelistparameter\c!expansion}% \preprocessexpansion\currentsortingexpansion\currentsortingtext\currentsortingcoding{#4}% \ctxcommand{registersynonym("\currentsorting", "sorting", { metadata = { catcodes = \the\catcodetable, coding = "\currentsortingcoding", xmlroot = \ifx\currentsortingcoding\s!xml "\xmldocument" \else nil \fi, }, definition = { tag = "\currentsortingtag", synonym = \!!bs\currentsortingtext\!!es, % used = false, } })}% \doif{#1}\v!yes{\setuxvalue\currentsortingtag{\strc_sorting_insert{\currentsorting}{\currentsortingtag}}}% \fi \endgroup} \unexpanded\def\strc_sorting_insert#1#2% name tag {\begingroup % no kap currently, of .. we need to map cap onto WORD \edef\currentsorting{#1}% \def\currentsortingtag{#2}% \let\currentsimplelist\currentsorting \dostarttagged\t!sorting\currentsorting \dotagsorting \usesimpleliststyleandcolor\c!style\c!color \ctxcommand{synonymname("#1","#2")}% \dostoptagged \normalexpanded{\endgroup\simplelistparameter\c!next}} \unexpanded\def\registersort {\dodoubleargument\strc_sorting_register} \def\strc_sorting_register[#1][#2]% {\ctxcommand{registerusedsynonym("#1","#2")}} % before after % % maybe just 'commandset' and then combine \unexpanded\def\placelistofsorts {\dodoubleempty\strc_sorting_place_list} \def\strc_sorting_place_list[#1][#2]% {\begingroup \edef\currentsimplelist{#1}% \strc_constructions_initialize{#1}% \setupcurrentsimplelist[#2]% \edef\p_simplelist_command{\simplelistparameter\c!command}% \ifx\p_simplelist_command\empty \let\synonymentry\strc_sorting_normal \else \let\synonymentry\strc_sorting_command \fi \startpacked \ctxcommand{processsynonyms('#1',{ criterium = "\simplelistparameter\c!criterium", language = "\simplelistparameter\s!language", method = "\simplelistparameter\c!method", })}% \stoppacked \endgroup} \unexpanded\def\completelistofsorts {\dodoubleempty\strc_sorting_complete_list} \def\strc_sorting_complete_list[#1][#2]% {\begingroup \edef\currentsimplelist{#1}% \normalexpanded{\startnamedsection[\v!chapter][\c!title={\headtext{\simplelistparameter\s!multi}},\c!reference=#1]}% \strc_sorting_place_list[#1][#2]% \page \stopnamedsection \endgroup} \def\strc_sorting_command#1#2#3#4% #4 is meaning but empty here {\p_simplelist_command{#1}{#2}{#3}} \def\strc_sorting_normal#1#2#3#4% #4 is meaning but empty here {\begingroup \usesimpleliststyleandcolor\c!style\c!color #3% \endgroup \par} %D Presets. % To be considered: % % \setupsimplelist % [\v!sorting] % [\c!headstyle=\simplelistparameter\c!synonymstyle, % \c!headcolor=\simplelistparameter\c!synonymcolor, % \c!style=\simplelistparameter\c!textstyle, % \c!color=\simplelistparameter\c!textcolor] \definesynonyms [\v!abbreviation] [\v!abbreviations] [\infull] \setupsynonyms [\v!abbreviation] [\c!textstyle=\v!capital] \definesorting [\v!logo] [\v!logos] % [\logogram] % no \protect \endinput