summaryrefslogtreecommitdiff
path: root/tex/context/base/strc-syn.tex
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/strc-syn.tex')
-rw-r--r--tex/context/base/strc-syn.tex392
1 files changed, 392 insertions, 0 deletions
diff --git a/tex/context/base/strc-syn.tex b/tex/context/base/strc-syn.tex
new file mode 100644
index 000000000..a739be902
--- /dev/null
+++ b/tex/context/base/strc-syn.tex
@@ -0,0 +1,392 @@
+%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 / Hans Hagen]
+%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}
+
+\unprotect
+
+% general help, can be shared
+
+% simplifiedcommands -> flag in lua
+%
+% expansion
+% criterium -> when start, then flag in list
+% command-> wanneer?
+% state -> flagging enabled
+% conversion ?
+% todo: register xml mode etc
+
+% 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}
+
+\let\currentsynonym\empty
+
+\def\synonymparameter #1{\csname\dosynonymparameter{\??sm\currentsynonym}#1\endcsname}
+\def\synonymparameterhash#1{\dosynonymparameterhash {\??sm\currentsynonym}#1}
+
+\def\dosynonymparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\dosynonymparentparameter \csname#1\s!parent\endcsname#2\fi}
+\def\dosynonymparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\dosynonymparentparameterhash\csname#1\s!parent\endcsname#2\fi}
+
+\def\dosynonymparentparameter #1#2{\ifx#1\relax\s!empty\else\dosynonymparameter #1#2\fi}
+\def\dosynonymparentparameterhash#1#2{\ifx#1\relax \else\dosynonymparameterhash#1#2\fi}
+
+\def\dosetsynonymattributes#1#2% style color
+ {\edef\fontattributehash {\synonymparameterhash#1}%
+ \edef\colorattributehash{\synonymparameterhash#2}%
+ \ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash #1\fi
+ \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash#2\fi}
+
+\newtoks\everysetupsynonyms
+
+\def\setupsynonyms
+ {\dodoubleargument\dosetupsynonyms}
+
+\def\dosetupsynonyms[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??sm#1][#2]%
+ \else
+ \getparameters[\??sm][#1]%
+ \fi
+ \the\everysetupsynonyms}
+
+\setupsynonyms
+ [\c!state=\v!start,
+ %\c!synonymstyle=,
+ %\c!textstyle=,
+ %\c!headstyle=,
+ %\c!headcolor=,
+ %\c!criterium=,
+ \c!location=\v!left,
+ \c!width=5em,
+ \c!distance=0pt,
+ %\c!sample=,
+ %\c!hang=,
+ %\c!align=,
+ %\c!before=,
+ %\c!inbetween=,
+ %\c!after=,
+ \c!indentnext=\v!no,
+ %\c!expansion=,
+ \s!language=\currentmainlanguage]
+
+\def\definesynonyms
+ {\doquadrupleempty\dodefinesynonyms}
+
+\def\dodefinesynonyms[#1][#2][#3][#4]% name plural \meaning \use
+ {\iffourthargument
+ \unexpanded\def#4##1{\doinsertsynonym{#1}{##1}}% name tag
+ \ifthirdargument
+ \unexpanded\def#3##1{\doinsertsynonymmeaning{#1}{##1}}% \meaning
+ \fi
+ \setvalue{#1}{\definesynonym[\v!no][#1]}% \name
+ \else
+ \ifthirdargument
+ \unexpanded\def#3##1{\doinsertsynonymmeaning{#1}{##1}}% \meaning
+ \fi
+ \setvalue{#1}{\definesynonym[\v!yes][#1]}% \name
+ \fi
+ \getparameters[\??sm#1][\s!parent=\??sm]%
+ \presetheadtext[#2=\Word{#2}]% changes the \if...argument
+ %\ctxlua{joblists.define('#1')}%
+ \setvalue{\e!setup #2\e!endsetup}{\dodoubleargument\getparameters[\??sm#1]}% to be obsolete
+ \setvalue{\e!place \e!listof#2}{\doplacelistofsynonyms{#1}{#2}}%
+ \setvalue{\e!complete\e!listof#2}{\docompletelistofsynonyms{#1}{#2}}}
+
+\def\definesynonym
+ {\dotripleempty\dodefinesynonym}
+
+\def\dodefinesynonym[#1][#2][#3]#4#5%
+ {\begingroup
+ \edef\currentsynonym{#2}%
+ \edef\currentsynonymtag{#3}%
+ \ifx\currentsynonymtag\empty
+ \edef\currentsynonymtag{#4}%
+ \fi
+ \ifx\currentsynonymtag\empty
+ % todo: error message
+ \else
+ \edef\currentsynonymexpansion{\synonymparameter\c!expansion}%
+ \preprocessexpansion\currentsynonymexpansion\currentsynonymtext \currentsynonymcoding{#4}%
+ \preprocessexpansion\currentsynonymexpansion\currentsynonymmeaning\currentsynonymcoding{#5}%
+ \ctxlua{joblists.register("\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{\unexpanded\setxvalue\currentsynonymtag{\noexpand\doinsertsynonym{\currentsynonym}{\currentsynonymtag}}}%
+ \fi
+ \endgroup}
+
+\def\doinsertsynonym#1#2% name tag
+ {\begingroup
+ % no kap currently, of .. we need to map cap onto WORD
+ \dosetsynonymattributes\c!synonymstyle\c!synonymcolor
+ \ctxlua{joblists.synonym("#1","#2")}%
+ \endgroup}
+
+\def\doinsertsynonymmeaning#1#2% name tag
+ {\begingroup
+ % no kap currently, of .. we need to map cap onto WORD
+ \dosetsynonymattributes\c!textstyle\c!textcolor
+ \ctxlua{joblists.meaning("#1","#2")}%
+ \endgroup}
+
+\def\doplacelistofsynonyms#1#2%
+ {\begingroup
+ \def\currentsynonym{#1}%
+\definedescription % todo, per class
+ [syndef]
+ [\c!location=\synonymparameter\c!location,
+ \c!width=\synonymparameter\c!width,
+ \c!distance=\synonymparameter\c!distance,
+ \c!sample=\synonymparameter\c!sample,
+ \c!hang=\synonymparameter\c!hang,
+ \c!align=\synonymparameter\c!align,
+ \c!before=\synonymparameter\c!before,
+ \c!inbetween=\synonymparameter\c!inbetween,
+ \c!after=\synonymparameter\c!after,
+ \c!indentnext=\synonymparameter\c!indentnext,
+ \c!headstyle=\synonymparameter\c!headstyle,
+ \c!headcolor=\synonymparameter\c!headcolor,
+ \c!style=,
+ \c!color=]%
+ \startpacked
+ \ctxlua{joblists.process('#1',{ criterium = "\synonymparameter\c!criterium" })}%
+ \stoppacked
+ \endgroup}
+
+\def\docompletelistofsynonyms#1#2% expansion needed to avoid v! (due to french active !)
+ {\normalexpanded{\noexpand\systemsuppliedchapter[#1]{\noexpand\headtext{#2}}}%
+ \doplacelistofsynonyms{#1}{#2}%
+ \page[\v!yes]}
+
+\let\startsynonymoutput \relax
+\let\stopsynonymoutput \relax
+\let\startsynonymsection\gobbleoneargument
+\let\stopsynonymsection \relax
+
+\def\synonymentry#1#2#3%
+ {\syndef{\dosetsynonymattributes\c!textstyle\c!textcolor#2}#3\par}
+
+\let\currentsorting\empty
+
+% we can share if we also have synonymprefix = so
+
+\def\sortingparameter #1{\csname\dosortingparameter{\??so\currentsorting}#1\endcsname}
+\def\sortingparameterhash#1{\dosortingparameterhash {\??so\currentsorting}#1}
+
+\def\dosortingparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\dosortingparentparameter \csname#1\s!parent\endcsname#2\fi}
+\def\dosortingparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\dosortingparentparameterhash\csname#1\s!parent\endcsname#2\fi}
+
+\def\dosortingparentparameter #1#2{\ifx#1\relax\s!empty\else\dosortingparameter #1#2\fi}
+\def\dosortingparentparameterhash#1#2{\ifx#1\relax \else\dosortingparameterhash#1#2\fi}
+
+\def\dosetsortingattributes#1#2% style color
+ {\edef\fontattributehash {\sortingparameterhash#1}%
+ \edef\colorattributehash{\sortingparameterhash#2}%
+ \ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash #1\fi
+ \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash#2\fi}
+
+\newtoks\everysetupsorting
+
+\def\setupsorting
+ {\dodoubleargument\dosetupsorting}
+
+\def\dosetupsorting[#1][#2]%
+ {\ifsecondargument
+ \getparameters[\??so#1][#2]%
+ \else
+ \getparameters[\??so][#1]%
+ \fi
+ \the\everysetupsorting}
+
+\setupsorting
+ [\c!state=\v!start,
+ %\c!command=, % we test for defined !
+ %\c!criterium=,
+ %\c!style=,
+ %\c!before=,
+ \c!after=\endgraf,
+ %\c!expansion=,
+ \s!language=\currentmainlanguage]
+
+\def\definesorting
+ {\dotripleempty\dodefinesorting}
+
+% if #3=\relax or \v!none, then no command but still protected
+
+\def\dodefinesorting[#1][#2][#3]%
+ {\ifthirdargument
+ \doifnot{#3}\v!none
+ {\ifx#3\relax \else
+ \def#3##1{\doinsertsort{#1}{##1}}%
+ \fi}%
+ \setvalue{#1}{\definesort[\v!no][#1]}%
+ \else
+ \setvalue{#1}{\definesort[\v!yes][#1]}%
+ \fi
+ \getparameters[\??so#1][\s!parent=\??so]%
+ \presetheadtext[#2=\Word{#2}]% after \ifthirdargument -)
+ %\ctxlua{joblists.define('#1')}%
+ \setvalue{\e!setup #2\e!endsetup}{\dodoubleargument\getparameters[\??so#1]}% to be obsolete
+ \setvalue{\e!place \e!listof#2}{\doplacelistofsortings{#1}{#2}}%
+ \setvalue{\e!complete\e!listof#2}{\docompletelistofsortings{#1}{#2}}}
+
+
+\def\definesort
+ {\dotripleempty\dodefinesort}
+
+\def\dodefinesort[#1][#2][#3]#4%
+ {\begingroup
+ \edef\currentsorting{#2}%
+ \edef\currentsortingtag{#3}%
+ \ifx\currentsortingtag\empty
+ \edef\currentsortingtag{#4}%
+ \fi
+ \ifx\currentsortingtag\empty
+ % todo: error message
+ \else
+ \edef\currentsortingexpansion{\sortingparameter\c!expansion}%
+ \preprocessexpansion\currentsortingexpansion\currentsortingtext\currentsortingcoding{#4}%
+ \ctxlua{joblists.register("\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{\unexpanded\setxvalue\currentsortingtag{\noexpand\doinsertsort{\currentsorting}{\currentsortingtag}}}%
+ \fi
+ \endgroup}
+
+\def\doinsertsort#1#2% name tag
+ {\begingroup
+ % no kap currently, of .. we need to map cap onto WORD
+ \dosetsynonymattributes\c!style\c!color
+ \ctxlua{joblists.synonym("#1","#2")}%
+ \endgroup}
+
+% before after
+%
+% maybe just 'commandset' and then combine
+
+\def\doplacelistofsorts#1% NOG EEN RUWE VERSIE MAKEN ZONDER WITRUIMTE ETC ETC
+ {\begingroup
+ \def\currentsorting{#1}%
+ \startpacked
+ \ctxlua{joblists.process('#1',{})}%
+ \stoppacked
+ \endgroup}
+
+\def\docompletelistofsorts#1#2%
+ {\normalexpanded{\noexpand\systemsuppliedchapter[#1]{\noexpand\headtext{#2}}}%
+ \doplacelistofsorts{#1}%
+ \page[\v!yes]}
+
+\let\startsortingoutput \relax
+\let\stopsortingoutput \relax
+\let\startsortingsection\gobbleoneargument
+\let\stopsortingsection \relax
+
+\def\sortingentry#1#2#3%
+ {\begingroup\dosetsortingattributes\c!style\c!color#2\endgroup\par} % todo
+
+%D Here we define a support macro that can sort simple comma
+%D separated lists. It's a multi-list variant of a prototype
+%D written by Taco.
+
+% \def\mkloadsortedlist#1% class
+% {\bgroup
+% \getvalue{\s!set#1}%
+% \ctxlua{joblists.process('#1')}%
+% \getvalue{\s!reset#1}%
+% \egroup}
+
+% \def\processlistofsorts[#1]%
+% {\mkloadsortedlist{#1}}
+
+% \newcounter\nofsortedalphalists
+
+% \def\sortalphacommacommand#1%
+% {\begingroup
+% \doglobal\increment\nofsortedalphalists
+% \edef\currentsortedalphalist{alpha:\nofsortedalphalists}%
+% \definesorting[\currentsortedalphalist][\currentsortedalphalist]%
+% \processcommacommand[#1]{\getvalue\currentsortedalphalist}%
+% \global\let\sortedcommalist\empty
+% \def\makesortedlist##1{\doglobal\appendtocommalist{##1}\sortedcommalist}%
+% \setupsorting[\currentsortedalphalist][\c!criterium=\v!all,\c!command=\makesortedlist]%
+% \processlistofsorts[\currentsortedalphalist]%
+% \endgroup
+% \dodoglobal\let#1\sortedcommalist}
+
+% \starttext
+% \def\whatever{a,b,q,d,r,f} \sortalphacommacommand\whatever \whatever \endgraf
+% \def\whatever{ax,bx,qx,dx,rx,fx} \sortalphacommacommand\whatever \whatever \endgraf
+% \stoptext
+
+%D Presets.
+
+\definesynonyms
+ [\v!abbreviation]
+ [\v!abbreviations]
+ [\infull]
+
+\setupsynonyms
+ [\v!abbreviation]
+ [\c!textstyle=\v!capital]
+
+\definesorting
+ [\v!logo]
+ [\v!logos]
+ % no [\logogram]
+
+\definesynonyms
+ [\v!unit]
+ [\v!units]
+ [\unitmeaning]
+
+\setupsynonyms
+ [\v!unit]
+ [\c!textstyle=\dimension]
+
+\protect \endinput