summaryrefslogtreecommitdiff
path: root/tex/context/base/strc-des.mkvi
blob: 845fb648caf857fda464c1ba67465e12e00313f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
%D \module
%D   [       file=strc-des,
%D        version=2008.10.20,
%D          title=\CONTEXT\ Structure Macros,
%D       subtitle=Descriptions,
%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 / Descriptions}

\unprotect

\installcorenamespace{description}

\installcommandhandler \??description {description} \??description

\let\setupdescriptions\setupdescription

% \setupdescriptions % check with old
%   [\c!alternative=\descriptionparameter\c!location,
%    \c!location=\v!left]

\setupdescriptions % check with old
  [\c!alternative=\v!left,
   \c!headstyle=\v!bold,
   \c!titlestyle=\v!bold,
  %\c!style=,
  %\c!color=,
  %\c!headcolor=,
  %\c!titlecolor=,
   \c!width=7em,
   \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!title=\v!yes,
  %\c!text=,
  ]

\appendtoks
    \ifx\currentdescriptionparent\empty
        \defineconstruction[\currentdescription][\currentdescriptionparent][\s!handler=\v!description,\c!level=1]%
    \else
        \defineconstruction[\currentdescription][\s!handler=\v!description,\c!level=1]%
    \fi
    \setuevalue        {\currentdescription}{\strc_descriptions_command{\currentdescription}}%
    \setuevalue{\e!start\currentdescription}{\strc_descriptions_start  {\currentdescription}}%
    \setuevalue{\e!stop \currentdescription}{\strc_descriptions_stop}%
\to \everydefinedescription

\setvalue{\??constructioninitializer\v!description}%
  {\let\currentdescription              \currentconstruction
   \let\constructionparameter           \descriptionparameter
   \let\detokenizedconstructionparameter\detokenizeddescriptionparameter
   \let\letconstructionparameter        \letdescriptionparameter
   \let\useconstructionstyleandcolor    \usedescriptionstyleandcolor
   \let\setupcurrentconstruction        \setupcurrentdescription
   \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}

% We keep the command variant around but rather would move to the
% start-stop one. Also, passing the title as argument has some
% history so we need to keep that as well.

\ifdefined\dotagsetdescription \else \let\dotagsetdescription\relax \fi

% \startdescription [reference]                text \stopdescription
% \startdescription [reference]{title}         text \stopdescription
% \startdescription [title=,title=,reference=] text \stopdescription

\unexpanded\def\strc_descriptions_start#1%
  {\begingroup
   \strc_constructions_initialize{#1}%
   \doifnextoptionalelse\strc_descriptions_start_yes\strc_descriptions_start_nop}

\unexpanded\def\strc_descriptions_start_yes[#1]%
  {\doifassignmentelse{#1}\strc_descriptions_start_yes_assignment\strc_descriptions_start_yes_reference[#1]}

\unexpanded\def\strc_descriptions_start_yes_assignment[#1]% todo userdata
  {\strc_constructions_register[\c!label={\descriptionparameter\c!text},\c!reference=,\c!title=,\c!bookmark=,\c!list=,#1][]%
   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}

\unexpanded\def\strc_descriptions_start_yes_reference
  {\ifconditional\c_strc_descriptions_title_state
     \expandafter\strc_descriptions_start_yes_titled
   \else
     \expandafter\strc_descriptions_start_yes_normal
   \fi}

\unexpanded\def\strc_descriptions_start_yes_titled[#1]#2% todo userdata
  {\strc_constructions_register[\c!label={\descriptionparameter\c!text},\c!reference={#1},\c!title={#2},\c!bookmark=,\c!list=][]%
   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}

\unexpanded\def\strc_descriptions_start_yes_normal[#1]% todo userdata
  {\strc_constructions_register[\c!label={\descriptionparameter\c!text},\c!reference={#1},\c!title=,\c!bookmark=,\c!list=][]%
   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}

\unexpanded\def\strc_descriptions_start_nop
  {\ifconditional\c_strc_constructions_title_state
     \expandafter\strc_descriptions_start_nop_titled
   \else
     \expandafter\strc_descriptions_start_nop_normal
   \fi}

\unexpanded\def\strc_descriptions_start_nop_titled#1%
  {\strc_constructions_register[\c!label={\descriptionparameter\c!text},\c!reference=,\c!title={#1},\c!bookmark=,\c!list=][]%
   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}

\unexpanded\def\strc_descriptions_start_nop_normal
  {\strc_constructions_register[\c!label={\descriptionparameter\c!text},\c!reference=,\c!title=,\c!bookmark=,\c!list=][]%
   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}

\unexpanded\def\strc_descriptions_stop
  {\csname\??constructionstophandler\currentconstructionhandler\endcsname}

% \description [reference]         text \par
% \description [reference] {title} text \par

\unexpanded\def\strc_descriptions_command#1%
  {\begingroup
   \strc_constructions_initialize{#1}%
   \doifnextoptionalelse\strc_descriptions_yes\strc_descriptions_nop}

\unexpanded\def\strc_descriptions_yes
  {\ifconditional\c_strc_constructions_title_state
     \expandafter\strc_descriptions_yes_titled
   \else
     \expandafter\strc_descriptions_yes_normal
   \fi}

\unexpanded\def\strc_descriptions_yes_titled[#1]#2%
  {\strc_constructions_register[\c!label={\descriptionparameter\c!text},\c!reference={#1},\c!title={#2},\c!bookmark=,\c!list=][]%
   \csname\??constructioncommandhandler\currentconstructionhandler\endcsname}

\unexpanded\def\strc_descriptions_yes_normal[#1]%
  {\strc_constructions_register[\c!label={\descriptionparameter\c!text},\c!reference={#1},\c!title=,\c!bookmark=,\c!list=][]%
   \csname\??constructioncommandhandler\currentconstructionhandler\endcsname}

\unexpanded\def\strc_descriptions_nop
  {\ifconditional\c_strc_constructions_title_state
     \expandafter\strc_descriptions_nop_titled
   \else
     \expandafter\strc_descriptions_nop_normal
   \fi}

\unexpanded\def\strc_descriptions_nop_titled#1%
  {\strc_constructions_register[\c!label={\descriptionparameter\c!text},\c!reference=,\c!title={#1},\c!bookmark=,\c!list=][]%
   \csname\??constructioncommandhandler\currentconstructionhandler\endcsname}

\unexpanded\def\strc_descriptions_nop_normal
  {\strc_constructions_register[\c!label={\descriptionparameter\c!text},\c!reference=,\c!title=,\c!bookmark=,\c!list=][]%
   \csname\??constructioncommandhandler\currentconstructionhandler\endcsname}

%D Handlers:

\expandafter\let\csname\??constructionmainhandler   \v!description\expandafter\endcsname\csname\??constructionmainhandler   \v!construction\endcsname
\expandafter\let\csname\??constructioncommandhandler\v!description\expandafter\endcsname\csname\??constructioncommandhandler\v!construction\endcsname
\expandafter\let\csname\??constructiontexthandler   \v!description\expandafter\endcsname\csname\??constructiontexthandler   \v!construction\endcsname

\setvalue{\??constructioncommandhandler\v!description}%
  {\dowithpar
     {\csname\??constructionstarthandler\v!construction\endcsname}%
     {\csname\??constructionstophandler \v!construction\endcsname\endgroup}}

\setvalue{\??constructionstarthandler\v!description}%
  {\BeforePar{\csname\??constructionstarthandler\v!construction\endcsname}%
   \GotoPar}

\setvalue{\??constructionstophandler\v!description}%
  {\csname\??constructionstophandler\v!construction\endcsname
   \endgroup}

\protect \endinput