summaryrefslogtreecommitdiff
path: root/tex/context/base/x-chemml.tex
blob: 8475fe81a207501db427ebd5f4837f040ea613d5 (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
201
202
203
204
205
206
207
208
209
210
211
212
%D \module
%D   [       file=m-chemml,
%D        version=2001.09.12,
%D          title=\CONTEXT\ XML Modules,
%D       subtitle=Loading \CHEMML\ Filters, 
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 
%C details. 

\useXMLfilter[cml] 

%D Structural formulas are codes in a \PPCHTEX\ way; this 
%D will change -)  
%D
%D \startbuffer
%D <dchem>
%D   <structure>
%D     <component>
%D       <graphic>SIX,B</graphic>
%D       <graphic>R135</graphic>
%D     </component>
%D     <component>
%D       <graphic>R246</graphic>
%D     </component>
%D     <component>
%D       <graphic>RZ</graphic>
%D       <text>A,B,C,D,E,F</text>
%D     </component>
%D     <component>
%D       <graphic>Z</graphic>
%D       <oxidation n="3">A</oxidation>
%D       <text>A</text>
%D       <annotation location="t">
%D         <text>B</text>
%D         <caption>x<context:b>x<context:compound token="*"/>x</context:b>x</caption>
%D       </annotation>
%D       <oxidation n="3" sign="+">B</oxidation>
%D       <text>C,D,E,F</text>
%D     </component>
%D   </structure>
%D   <structure>
%D     <component>
%D       <graphic>SIX,B</graphic>
%D       <graphic>r135</graphic>
%D     </component>
%D     <component>
%D       <graphic>R246</graphic>
%D     </component>
%D     <component>
%D       <graphic>RZ</graphic>
%D       <text>A,B,C,D,E,F</text>
%D     </component>
%D   </structure>
%D </dchem>
%D \stopbuffer
%D
%D \typebuffer

% \ifx\XMLgtoks\undefined \newtoks\XMLgtoks \fi 
% \ifx\XMLttoks\undefined \newtoks\XMLttoks \fi 
% 
% \defineXMLenvironment [structure]
%   {\startchemical\ignorespaces}
%   {\relax\stopchemical}
% 
% \def\chemicalXMLg#1% \defineXMLcollect [graphic] \XMLgtoks 
%   {\doifelsenothing{\the\XMLgtoks}
%      {\doglobal\appendtoks #1\to\XMLgtoks\ignorespaces}
%      {\doglobal\appendtoks,#1\to\XMLgtoks\ignorespaces}}
% 
% \def\chemicalXMLt#1%
%   {\doifelsenothing{\the\XMLttoks}
%      {\doglobal\appendtoks #1\to\XMLttoks\ignorespaces}
%      {\doglobal\appendtoks,#1\to\XMLttoks\ignorespaces}}
% 
% \defineXMLenvironment [component] [type=]
%   {\global\XMLgtoks\emptytoks
%    \global\XMLttoks\emptytoks
%    \defineXMLargument[graphic]\chemicalXMLg
%    \defineXMLargument[text]\chemicalXMLt
%    \ignorespaces}
%   {\expanded{\chemical[\the\XMLgtoks][\the\XMLttoks]}%
%    \ignorespaces}
% 
% \defineXMLargument [oxidation] [sign=,n=1] \chemicalXMLo % +/- 1..7 
% 
% \def\chemicalXMLo#1%
%   {\expanded{\chemicalXMLt
%      {\noexpand\chemicaloxidation{\XMLop{sign}}{\XMLop{n}}{#1}}}%
%    \ignorespaces}
% 
% \defineXMLenvironment [annotation] [location=] 
%   {\bgroup
%    \defineXMLenvironmentsave[text]{\ignorespaces}{\ignorespaces}%
%    \defineXMLenvironmentsave[caption]{\ignorespaces}{\ignorespaces}%
%    \ignorespaces}
%   {\scratchtoks{\chemicalright}%
%    \processaction 
%      [\XMLop{location}]
%      [ t=>\scratchtoks{\chemicaltop},
%        b=>\scratchtoks{\chemicalbottom},
%        l=>\scratchtoks{\chemicalleft},
%        r=>\scratchtoks{\chemicalright},
%       lc=>\scratchtoks{\chemicalleftcentered},
%       rc=>\scratchtoks{\chemicalrightcentered},
%       tl=>\scratchtoks{\chemicaltopleft},
%       bl=>\scratchtoks{\chemicalbottomleft},
%       tr=>\scratchtoks{\chemicaltopright},
%       br=>\scratchtoks{\chemicalbottomright},
%       lt=>\scratchtoks{\chemicallefttop},
%       lb=>\scratchtoks{\chemicalleftbottom},
%       rt=>\scratchtoks{\chemicalrighttop},
%       rb=>\scratchtoks{\chemicalrightbottom},
%        x=>\scratchtoks{\chemicaltighttext}, 
%       sl=>\scratchtoks{\chemicalsmashedleft},
%       sm=>\scratchtoks{\chemicalsmashedmiddle},
%       sr=>\scratchtoks{\chemicalsmashedright}]% 
%     \expanded{\chemicalXMLt
%       {\the\scratchtoks{\XMLflush{text}}{\XMLflush{caption}}}}%
%    \egroup
%    \ignorespaces}
% 
% \defineXMLenvironment [forever]
%   {\chemicalXMLt{\[}\ignorespaces} 
%   {\chemicalXMLt{\]}\ignorespaces} 

\ifx\XMLgtoks\undefined \newtoks\XMLgtoks \fi 
\ifx\XMLttoks\undefined \newtoks\XMLttoks \fi 

\startXMLmapping [cml]

% this will be a more natural method; this also triggers it 

\installXMLunknownremapping 

% extensions 

\remapXMLsequence [structure] [CPA] \doCMLstructure
\remapXMLsequence [component] [CPA] \doCMLcomponent
\remapXMLsequence [graphic]   [CPA] \doCMLgraphic
\remapXMLsequence [text]      [CPA] \doCMLtext

\remapXMLsequence [caption]   [CPA] \doCMLcaption
\remapXMLsequence [oxidation] [CPA] \doCMLoxidation
\remapXMLsequence [annotation][CPA] \doCMLannotation
\remapXMLsequence [forever]   [CPA] \doCMLforever

\def\doCMLstructure#1#2%
  {\startchemical\ignorespaces#2\unskip\stopchemical}

\def\doCMLgraphic#1#2% 
  {\doifelsenothing{\the\XMLgtoks}
     {\uppercase{\doglobal\appendtoks #2\to\XMLgtoks\ignorespaces}}
     {\uppercase{\doglobal\appendtoks,#2\to\XMLgtoks\ignorespaces}}%
   \ignorespaces}

\def\doCMLtext#1#2%
  {\doifelsenothing{\the\XMLttoks}
     {\doglobal\appendtoks #2\to\XMLttoks\ignorespaces}
     {\doglobal\appendtoks,#2\to\XMLttoks\ignorespaces}%
   \ignorespaces}

\def\doCMLcomponent#1#2%
  {\global\XMLgtoks\emptytoks
   \global\XMLttoks\emptytoks
   \ignorespaces#2\unskip
   \expanded{\chemical[\the\XMLgtoks][\the\XMLttoks]}%
   \ignorespaces}

\def\doCMLannotation#1#2%
  {\getXMLarguments{cml}{location="" #1}%
   \def\dodoCMLannotation##1% 
     {\doCMLtext\empty{##1%
        {\let\doCMLtext   \secondoftwoarguments\processXMLRchild{text}{#2}}%
        {\let\doCMLcaption\unmapXMLdata        \processXMLRchild{caption}{#2}}}}%
   \processaction 
     [\XMLpar{cml}{location}{r}]
     [ t=>\dodoCMLannotation\chemicaltop,
       b=>\dodoCMLannotation\chemicalbottom,
       l=>\dodoCMLannotation\chemicalleft,
       r=>\dodoCMLannotation\chemicalright,
      lc=>\dodoCMLannotation\chemicalleftcentered,
      rc=>\dodoCMLannotation\chemicalrightcentered,
      tl=>\dodoCMLannotation\chemicaltopleft,
      bl=>\dodoCMLannotation\chemicalbottomleft,
      tr=>\dodoCMLannotation\chemicaltopright,
      br=>\dodoCMLannotation\chemicalbottomright,
      lt=>\dodoCMLannotation\chemicallefttop,
      lb=>\dodoCMLannotation\chemicalleftbottom,
      rt=>\dodoCMLannotation\chemicalrighttop,
      rb=>\dodoCMLannotation\chemicalrightbottom,
       x=>\dodoCMLannotation\chemicaltighttext, 
      sl=>\dodoCMLannotation\chemicalsmashedleft,
      sm=>\dodoCMLannotation\chemicalsmashedmiddle,
      sr=>\dodoCMLannotation\chemicalsmashedright]%
   \ignorespaces}

\def\doCMLoxidation#1#2%
  {\getXMLarguments{cml}{sign="" n="1" #1}%
   \expanded{\doCMLtext{}%
     {\noexpand\chemicaloxidation{\XMLpar{cml}{sign}{}}{\XMLpar{cml}{n}{}}{#2}}}%
   \ignorespaces}

\def\doCMLforever#1#2{\[#2\]}

\stopXMLmapping

\endinput