strc-des.mklx /size: 7804 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=strc-des,
3%D        version=2008.10.20,
4%D          title=\CONTEXT\ Structure Macros,
5%D       subtitle=Descriptions,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Structure Macros / Descriptions}
15
16\unprotect
17
18\installcorenamespace{description}
19
20\installcommandhandler \??description {description} \??description
21
22\aliased\let\setupdescriptions\setupdescription
23
24% \setupdescription % check with old
25%   [\c!alternative=\descriptionparameter\c!location,
26%    \c!location=\v!left]
27
28\setupdescription % check with old
29  [\c!alternative=\v!left,
30   \c!headstyle=\v!bold,
31   \c!titlestyle=\v!bold,
32  %\c!style=,
33  %\c!color=,
34  %\c!headcolor=,
35  %\c!titlecolor=,
36   \c!width=7\emwidth,
37   \c!distance=\emwidth,
38   \c!titledistance=.5\emwidth,
39  %\c!hang=,
40  %\c!sample=,
41  %\c!align=,
42  %\c!headalign=,
43   \c!margin=\v!no,
44   \c!before=\blank,
45   \c!inbetween=\blank,
46   \c!after=\blank,
47   \c!indentnext=\v!yes,
48   \c!indenting=\v!never,
49   \c!titleleft=(,
50   \c!titleright=),
51  %\c!closesymbol=,
52   \c!closecommand=\wordright,
53   \c!display=\v!yes,
54  %\c!command=,
55   \c!titlecommand=,
56   \c!expansion=\v!no,
57  %\c!xmlsetup=,
58  %\s!catcodes=,
59   \c!title=\v!yes,
60  %\c!text=,
61   \c!define=\v!yes,
62  ]
63
64\appendtoks
65    \ifempty\currentdescriptionparent
66        \defineconstruction[\currentdescription][\currentdescriptionparent][\s!handler=\v!description,\c!level=1]%
67    \else
68        \defineconstruction[\currentdescription][\s!handler=\v!description,\c!level=1]%
69    \fi
70    % We can combine these but in tracing (or errors) using a different caller is nicer.
71    \ifcstok{\descriptionparameter\c!define}\v!yes
72        \frozen\protected\instance\edefcsname        \currentdescription\endcsname{\nameddescription[\currentdescription]}%
73        \frozen\protected\instance\edefcsname\e!start\currentdescription\endcsname{\startnameddescription[\currentdescription]}%
74        \frozen\protected\instance \defcsname \e!stop\currentdescription\endcsname{\stopnameddescription}%
75    \fi
76\to \everydefinedescription
77
78\protected\defcsname\??constructioninitializer\v!description\endcsname
79  {\let         \currentdescription              \currentconstruction
80   \enforced\let\constructionparameter           \descriptionparameter
81   \enforced\let\constructionnamespace           \??description
82   \enforced\let\detokenizedconstructionparameter\detokenizeddescriptionparameter
83   \enforced\let\letconstructionparameter        \letdescriptionparameter
84   \enforced\let\useconstructionstyleandcolor    \usedescriptionstyleandcolor
85   \enforced\let\setupcurrentconstruction        \setupcurrentdescription
86   \ifcstok{\constructionparameter\c!title}\v!yes
87     \c_strc_constructions_title_state\conditionaltrue
88   \else
89     \c_strc_constructions_title_state\conditionalfalse
90   \fi}
91
92% We keep the command variant around but rather would move to the
93% start-stop one. Also, passing the title as argument has some
94% history so we need to keep that as well.
95
96% \startdescription [reference]                text \stopdescription
97% \startdescription [reference]{title}         text \stopdescription
98% \startdescription [title=,title=,reference=] text \stopdescription
99
100% A bit over the top, the optional title but mkii has it too.
101
102\tolerant\permanent\protected\def\startnameddescription[#1]#*[#S#2]%
103  {\begingroup
104   \strc_constructions_initialize{#1}%
105   \ifhastok={#2}%
106     \expandafter\strc_descriptions_start_setups
107   \orelse\ifconditional\c_strc_constructions_title_state
108     \expandafter\strc_descriptions_start_title
109   \else
110     \expandafter\strc_descriptions_start_reference
111   \fi[#2]}
112
113% we could use this:
114%
115% \def\strc_descriptions_preset
116%   {\setdescriptionparameter\c!label{\descriptionparameter\c!text}%
117%    \resetdescriptionparameter\c!bookmark
118%    \resetdescriptionparameter\c!list
119%    \resetdescriptionparameter\c!referencetext}
120
121\protected\def\strc_descriptions_start_setups[#S#1]%
122  {\strc_constructions_register[][\c!label={\descriptionparameter\c!text},\c!reference=,\c!title=,\c!bookmark=,\c!list=,\c!referencetext=,#1]%
123   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}
124
125\protected\tolerant\def\strc_descriptions_start_title[#1]#*#=%
126  {\strc_constructions_register[][\c!label={\descriptionparameter\c!text},\c!reference={#1},\c!title={#2},\c!bookmark=,\c!list=,\c!referencetext=]%
127   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}
128
129\protected\def\strc_descriptions_start_reference[#1]%
130  {\strc_constructions_register[][\c!label={\descriptionparameter\c!text},\c!reference={#1},\c!title=,\c!bookmark=,\c!list=,\c!referencetext=]%
131   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}
132
133\permanent\protected\def\stopnameddescription
134  {\csname\??constructionstophandler\currentconstructionhandler\endcsname}
135
136% \description [reference]         text \par
137% \description [reference] {title} text \par
138
139\tolerant\permanent\protected\def\nameddescription[#1]#*[#S#2]%
140  {\begingroup
141   \strc_constructions_initialize{#1}%
142   \ifhastok={#2}%
143     \expandafter\strc_descriptions_command_setups
144   \orelse\ifconditional\c_strc_constructions_title_state
145     \expandafter\strc_descriptions_command_title
146   \else
147     \expandafter\strc_descriptions_command_reference
148   \fi[#2]}
149
150\protected\def\strc_descriptions_command_setups[#S#1]%
151  {\strc_constructions_register[][\c!label={\descriptionparameter\c!text},\c!reference=,\c!title=,\c!bookmark=,\c!list=,\c!referencetext=,#1]%
152   \csname\??constructioncommandhandler\currentconstructionhandler\endcsname}
153
154\protected\tolerant\def\strc_descriptions_command_title[#1]#:#*#=%
155  {\strc_constructions_register[][\c!label={\descriptionparameter\c!text},\c!reference={#1},\c!title={#2},\c!bookmark=,\c!list=,\c!referencetext=]%
156   \csname\??constructioncommandhandler\currentconstructionhandler\endcsname}
157
158\protected\def\strc_descriptions_command_reference[#1]%
159  {\strc_constructions_register[][\c!label={\descriptionparameter\c!text},\c!reference={#1},\c!title=,\c!bookmark=,\c!list=,\c!referencetext=]%
160   \csname\??constructioncommandhandler\currentconstructionhandler\endcsname}
161
162%D Handlers:
163
164\letcsname\??constructionmainhandler   \v!description\expandafter\endcsname\csname\??constructionmainhandler   \v!construction\endcsname
165\letcsname\??constructioncommandhandler\v!description\expandafter\endcsname\csname\??constructioncommandhandler\v!construction\endcsname
166\letcsname\??constructiontexthandler   \v!description\expandafter\endcsname\csname\??constructiontexthandler   \v!construction\endcsname
167
168\protected\defcsname\??constructioncommandhandler\v!description\endcsname
169  {\dowithpar
170     {\csname\??constructionstarthandler\v!construction\endcsname}%
171     {\csname\??constructionstophandler \v!construction\endcsname\endgroup}}
172
173\protected\defcsname\??constructionstarthandler\v!description\endcsname
174  {\dogotopar
175     {\csname\??constructionstarthandler\v!construction\endcsname}}
176
177\protected\defcsname\??constructionstophandler\v!description\endcsname
178  {\csname\??constructionstophandler\v!construction\endcsname
179   \endgroup}
180
181%D For historic reasons we have (from now on undocumented):
182
183\definedescription
184  [tab]
185  [\c!alternative=\v!left,
186   \c!headstyle=\v!normal,
187   \c!headcolor=,
188   \c!style=\v!normal,
189   \c!color=,
190   \c!width=\v!broad,
191   \c!sample=\kern4\emwidth, % was \hskip but that no longer is okay
192   \c!before=,
193   \c!after=]
194
195\permanent\protected\def\setuptab{\setupdescription[tab]} % for old times
196
197%D Maybe we should remove this definition.
198
199\protect \endinput
200