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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
% --------------------------------------------------------------------------
%
% the CHEMMACROS package -- module: `reactions'
%
% --------------------------------------------------------------------------
% Clemens Niederberger
% --------------------------------------------------------------------------
% https://github.org/cgnieder/chemmacros/
% contact@mychemistry.eu
% --------------------------------------------------------------------------
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% --------------------------------------------------------------------------
% Copyright 2011-2016 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clemens Niederberger.
% --------------------------------------------------------------------------
\ChemModule{reactions}{2016/05/04 reaction environments}
\chemmacros_load_module:n {chemformula}
\RequirePackage{mathtools}
% --------------------------------------------------------------------------
\cs_new_protected:Npn \__chemmacros_record_for_lor:nnnnn #1#2#3#4#5
{
\tl_if_eq:nnT {#1} {reaction}
{
\group_begin:
% we need to prevent \Hy@make@anchor from being written to the lor
% file:
\bool_if:NT \l__chemmacros_hyperref_bool
{ \cs_set:Npn \Hy@make@anchor {} }
\addcontentsline {lor} {reaction}
{
\tl_use:N \l__chemmacros_reaction_lorname_tl
\tl_use:N \c_space_tl
#2 #3 #4 #5
\tl_use:N \g__chemmacros_reaction_description_tl
}
\tl_gclear:N \g__chemmacros_reaction_description_tl
\group_end:
}
}
% redefine mathtools' command \MT_define_tagform:nwnn to ensure we add an
% entry to the list of reactions even if the user redefines the reaction tag
% this should probably be done via patching...
\AfterPackage* { mathtools }
{
\cs_set_protected:Npn \MT_define_tagform:nwnn #1[#2]#3#4
{
\@namedef{MT_tagform_#1:n}##1
{
% this is the original part:
\maketag@@@{#3\ignorespaces#2{##1}\unskip\@@italiccorr#4}
% this is added => this disturbs hyperref:
\__chemmacros_record_for_lor:nnnnn
{#1} {#3} {#2} {##1} {#4}
}
}
}
\tl_new:N \g__chemmacros_reaction_description_tl
\cs_new_protected:Npn \chemmacros_add_reaction_description:n #1
{
\tl_if_blank:nF {#1}
{ \tl_gset:Nn \g__chemmacros_reaction_description_tl {:~#1} }
}
\NewDocumentCommand \AddRxnDesc {m}
{ \chemmacros_add_reaction_description:n {#1} }
% define \listofreactions
\tl_new:N \l__chemmacros_reaction_lorname_tl
\tl_new:N \reactionlistname
\tl_new:N \l__chemmacros_reaction_heading_tl
\cs_new:Npn \__chemmacros_reaction_heading:n #1
{ \l__chemmacros_reaction_heading_tl {#1} }
\cs_generate_variant:Nn \__chemmacros_reaction_heading:n { V }
\ChemCompatibilityTo{5.5}
\tl_set:Nn \l__chemmacros_reaction_lorname_tl
{ \chemmacros_translate:n {reaction} }
\EndChemCompatibility
\ChemCompatibilityFrom{5.6}
\tl_set:Nn \l__chemmacros_reaction_lorname_tl
{ \chemmacros_translate:n {Reaction} }
\EndChemCompatibility
\tl_set:Nn \reactionlistname { \chemmacros_translate:n {list-of-reactions} }
\chemmacros_define_keys:nn {reactions}
{
list-name .tl_set:N = \reactionlistname ,
list-entry .tl_set:N = \l__chemmacros_reaction_lorname_tl ,
}
\ChemCompatibilityFrom{5.2}
\chemmacros_define_keys:nn {reactions}
{
list-heading-cmd .code:n =
\cs_set_protected:Npn \__chemmacros_reaction_heading:n ##1 {#1}
}
\EndChemCompatibility
\cs_if_exist:NTF \chapter
{
\chemmacros_if_compatiblity:nnTF {>=} {5.2}
{
\chemmacros_set_keys:nn {reactions}
{ list-heading-cmd = \chapter* {#1} }
}
{ \cs_set_protected:Npn \__chemmacros_reaction_heading:n { \chapter* } }
}
{
\chemmacros_if_compatiblity:nnTF {>=} {5.2}
{
\chemmacros_set_keys:nn {reactions}
{ list-heading-cmd = \section* {#1} }
}
{ \cs_set_protected:Npn \__chemmacros_reaction_heading:n { \section* } }
}
\cs_new_protected:Npn \listofreactions
{
\__chemmacros_reaction_heading:V \reactionlistname
\@starttoc {lor}
}
\ChemCompatibilityTo{5.5}
\cs_new_protected:Npn \l@reaction #1#2
{ \@dottedtocline {1} {1.5em} {2.3em} {#1} {#2} }
\EndChemCompatibility
\ChemCompatibilityFrom{5.6}
\cs_new_eq:NN \l@reaction \l@figure
\bool_new:N \l__chemmacros_reactions_tocbasic_bool
\cs_if_exist:NT \KOMAClassName
{ \bool_set_true:N \l__chemmacros_reactions_tocbasic_bool }
\tl_new:N \l__chemmacros_reactions_tag_open_tl
\tl_new:N \l__chemmacros_reactions_tag_close_tl
\tl_new:N \l__chemmacros_reactions_before_tag_tl
\chemmacros_define_keys:nn {reactions}
{
tocbasic .bool_set:N = \l__chemmacros_reactions_tocbasic_bool ,
tag-open .tl_set:N = \l__chemmacros_reactions_tag_open_tl ,
tag-open .initial:n = \{ ,
tag-close .tl_set:N = \l__chemmacros_reactions_tag_close_tl ,
tag-close .initial:n = \} ,
before-tag .tl_set:N = \l__chemmacros_reactions_before_tag_tl
}
\AtEndPreamble
{
\bool_if:nT
{
\chemmacros_if_package_loaded_p:n {tocbasic} ||
\l__chemmacros_reactions_tocbasic_bool
}
{
\RequirePackage {tocbasic}
\addtotoclist [float] {lor}
\cs_set_protected:Npn \listofreactions { \listoftoc {lor} }
\cs_new:Npn \listoflorname { \reactionlistname }
}
}
\ChemCleverefSupport {reaction}
{ \chemmacros_translate:n {reaction} }
[ \chemmacros_translate:n {Reaction} ]
{ \chemmacros_translate:n {reactions} }
[ \chemmacros_translate:n {Reactions} ]
\AfterPackage* {cleveref}
{
\creflabelformat {reaction}
{
#2
\l__chemmacros_reactions_tag_open_tl
#1
\l__chemmacros_reactions_tag_close_tl
#3
}
}
\ChemFancyrefSupport {rct}
{ \chemmacros_translate:n {reaction} }
[ \chemmacros_translate:n {Reaction} ]
\EndChemCompatibility
% create new tagform
\ChemCompatibilityTo{5.5}
\newtagform {reaction} {\{} {\}}
\EndChemCompatibility
\ChemCompatibilityFrom{5.6}
\newtagform {reaction}
[\l__chemmacros_reactions_before_tag_tl]
{\l__chemmacros_reactions_tag_open_tl}
{\l__chemmacros_reactions_tag_close_tl}
\EndChemCompatibility
\newcounter {chemmacros_save_reaction}
\newcounter {reaction}
\ChemCompatibilityTo{5.5}
\cs_new_protected:Npn \__chemmacros_begin_reaction:
{
% create individual names for `hyperref':
\bool_if:NT \l__chemmacros_hyperref_bool
{
\cs_set:Npn \theHequation
{ R . \theHsection . \arabic {reaction} }
}
% enable labelformat `reaction':
\bool_if:NT \l__chemmacros_varioref_bool
{ \cs_set_eq:NN \p@equation \p@reaction }
\setcounter {chemmacros_save_reaction} { \value {equation} }
\setcounter {equation} { \value {reaction} }
\usetagform {reaction}
}
\EndChemCompatibility
\ChemCompatibilityFrom{5.6}
\cs_new_protected:Npn \__chemmacros_begin_reaction:
{
\patchcmd \thereaction {reaction} {equation} {} {}
\cs_set_eq:NN \theequation \thereaction
\cs_set_eq:NN \r@equation \r@reaction
\cs_set_eq:NN \p@equation \p@reaction
\cs_set:Npn \theHequation { R . \theHsection . \theequation }
\setcounter {chemmacros_save_reaction} { \value {equation} }
\setcounter {equation} { \value {reaction} }
\chemmacros_if_package_loaded:nT {cleveref}
{ \crefalias {equation} {reaction} }
\usetagform {reaction}
}
\EndChemCompatibility
% switch back to equation tags
\cs_new_protected:Npn \__chemmacros_end_reaction:
{
\setcounter {reaction} { \value {equation} }
\setcounter {equation} { \value {chemmacros_save_reaction} }
}
\tl_new:N \l__chemmacros_reactions_args_tl
\cs_new_protected:Npn \__chemmacros_reactions_build_args:n #1
{ \tl_put_right:Nn \l__chemmacros_reactions_args_tl { {## #1} } }
\cs_new_protected:Npn \chemmacros_define_reaction:nnn #1#2#3
{
\int_compare:nNnT {#3+0} > {0}
{
\tl_clear:N \l__chemmacros_reactions_args_tl
\int_step_function:nnnN {2} {1} {#3+1} \__chemmacros_reactions_build_args:n
}
\chemmacros_declare_reaction_env:nnnV {#1} {#2} {#3} \l__chemmacros_reactions_args_tl
}
% #1: chem
% #2: math
% #3: args number
% #4: argument list ({#2}{#3}...)
\cs_new_protected:Npn \chemmacros_declare_reaction_env:nnnn #1#2#3#4
{
\exp_args:Nnx \DeclareDocumentEnvironment {#1} { O{} \prg_replicate:nn {#3+0} {m} }
{
\chemmacros_add_reaction_description:n {##1}
\__chemmacros_begin_reaction:
\chemmacros_reaction_read:nnw {#2} {#4}
}
{
\__chemmacros_end_reaction:
\ignorespacesafterend
}
}
\cs_generate_variant:Nn \chemmacros_declare_reaction_env:nnnn {nnnV}
\ChemCompatibilityTo{5.5}
\cs_new_protected:Npn \chemmacros_reaction_read:nnw #1#2#3 \end
{
\begin{#1}#2
\chemmacros_reaction:n {#3}
\end{#1}
\end
}
\EndChemCompatibility
\ChemCompatibilityFrom{5.6}
\cs_new_protected:Npn \chemmacros_reaction_read:nnw #1#2#3 \end
{
\tl_clear:N \l__chemmacros_tmpa_tl
\seq_clear:N \l__chemmacros_tmpc_seq
\seq_set_split:Nnn \l__chemmacros_tmpa_seq {\\} {#3}
\int_set:Nn \l__chemmacros_tmpa_int
{ \seq_count:N \l__chemmacros_tmpa_seq }
\int_zero:N \l__chemmacros_tmpb_int
\seq_map_inline:Nn \l__chemmacros_tmpa_seq
{
\int_incr:N \l__chemmacros_tmpb_int
\seq_clear:N \l__chemmacros_tmpc_seq
\seq_set_split:Nnn \l__chemmacros_tmpb_seq {&} {##1}
\seq_map_inline:Nn \l__chemmacros_tmpb_seq
{
\seq_put_right:Nn \l__chemmacros_tmpc_seq
{ \chemmacros_reaction:n {####1} }
}
\tl_put_right:Nx \l__chemmacros_tmpa_tl
{ \seq_use:Nn \l__chemmacros_tmpc_seq {&} }
\int_compare:nF
{ \l__chemmacros_tmpa_int = \l__chemmacros_tmpb_int }
{ \tl_put_right:Nn \l__chemmacros_tmpa_tl {\\} }
}
\chemmacros_reaction_write:nnV {#1} {#2} \l__chemmacros_tmpa_tl
\end
}
\cs_new_protected:Npn \chemmacros_reaction_write:nnn #1#2#3
{
\begin{#1}#2
#3
\end{#1}
}
\cs_generate_variant:Nn \chemmacros_reaction_write:nnn { nnV }
\EndChemCompatibility
\NewChemMacroset* {Reaction} {mO{}m}
{ \chemmacros_define_reaction:nnn {#1} {#3} {#2} }
\NewChemReaction {reaction} {equation}
\NewChemReaction {reaction*} {equation*}
\NewChemReaction {reactions} {align}
\NewChemReaction {reactions*} {align*}
% --------------------------------------------------------------------------
\ChemCompatibilityTo{5.5}
\DeclareTranslationFallback {list-of-reactions} {List~ of~ Reactions}
\DeclareTranslation {English} {list-of-reactions} {List~ of~ Reactions}
\DeclareTranslation {German} {list-of-reactions} {Reaktionsverzeichnis}
\DeclareTranslation {Italian} {list-of-reactions} {Elenco~ delle~ reazioni}
\DeclareTranslation {French} {list-of-reactions} {Table~ des~ r\'{e}actions}
\DeclareTranslation {Dutch} {list-of-reactions} {Lijst~ van~ reacties}
\DeclareTranslationFallback {reaction} {Reaction}
\DeclareTranslation {English} {reaction} {Reaction}
\DeclareTranslation {German} {reaction} {Reaktion}
\DeclareTranslation {Italian} {reaction} {Reazione}
\DeclareTranslation {French} {reaction} {R\'{e}action}
\DeclareTranslation {Dutch} {reaction} {Reactie}
\EndChemCompatibility
\ChemCompatibilityFrom{5.6}
\chemmacros_declare_translations:nn {list-of-reactions}
{
fallback = List~ of~ Reactions ,
English = List~ of~ Reactions ,
German = Reaktionsverzeichnis ,
Italian = Elenco~ delle~ reazioni ,
French = Table~ des~ r\'{e}actions ,
Dutch = Lijst~ van~ reacties
}
\chemmacros_declare_translations:nn {reaction}
{
fallback = reaction ,
English = reaction ,
German = Reaktion ,
Italian = reazione ,
French = r\'{e}action ,
Dutch = reactie
}
\chemmacros_declare_translations:nn {reactions}
{
fallback = reactions ,
English = reactions ,
German = Reaktionen ,
Italian = reazioni ,
French = r\'{e}actions ,
Dutch = reacties
}
\chemmacros_declare_translations:nn {Reaction}
{
fallback = Reaction ,
English = Reaction ,
German = Reaktion ,
Italian = Reazione ,
French = R\'{e}action ,
Dutch = Reactie
}
\chemmacros_declare_translations:nn {Reactions}
{
fallback = Reactions ,
English = Reactions ,
German = Reaktionen ,
Italian = Reazioni ,
French = R\'{e}actions ,
Dutch = Reacties
}
\EndChemCompatibility
% --------------------------------------------------------------------------
\tex_endinput:D
2015/09/15 - adapt to `method' option => do not use chemformula's macros
directly
2015/10/14 - new option `list-heading-cmd'
2016/02/09 - added \ignorespacesafterend to environments
2016/03/17 - tocbasic integration of lor
- add missing compatibility check for the usage of the
`list-heading-cmd' option
2016/04/02 - adapt to new formula methods
2016/04/27 - correct \__chemmacros_begin_reaction: so tags obey \thereaction
- add cleveref support
- add fancyref support
- moved translations from lang module to reactions module
2016/05/04 - options `tag-open', `tag-close' and `before-tag'
|