Debian Codegraph @

texmf-dist/tex/generic/chemfig/chemfig.tex

raw
1 % !TeX encoding = UTF-8
2 % Ce fichier contient le code de l'extension "chemfig"
3 %
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 % %
6 \def\CFname {chemfig} %
7 \def\CFver {1.71} %
8 % %
9 \def\CFdate {2025/10/30} %
10 % %
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 %
13 %____________________________________________________________________
14 % Author : Christian Tellechea |
15 % Status : Maintained |
16 % Email : [email protected] |
17 % Package URL: https://www.ctan.org/pkg/chemfig |
18 % Copyright : Christian Tellechea 2010-2025 |
19 % Licence : Released under the LaTeX Project Public License v1.3c |
20 % or later, see http://www.latex-project.org/lppl.txt |
21 % Files : 1) chemfig.tex |
22 % 2) chemfig.sty |
23 % 3) README |
24 % 4) chemfig_doc_fr.tex |
25 % 5) chemfig_doc_fr.pdf |
26 % 6) chemfig_doc_en.tex |
27 % 7) chemfig_doc_fr.pdf |
28 % 8) chemfig-lewis.tex |
29 % 9) changelog.tex |
30 %--------------------------------------------------------------------
31
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 %%% P R É A L A B L E %%%
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 \csname CFloadonce\endcsname
36 \let\CFloadonce\endinput
37 %-------------------------- Annonce package --------------------------
38 \ifdefined\CFfromsty\else
39 \immediate\write -1 {%
40 Package: \CFname\space\CFdate\space\space v\CFver\space\space
41 Draw molecule with an easy syntax (CT)}%
42 \fi
43
44 %-------------------------- Régime catcodes --------------------------
45 \begingroup
46 \def\X#1{\catcode\number`#1=\number\catcode`#1\relax}
47 \xdef\CFrestorecatcode{\X\[\X\]\X\:\X\(\X\)\X\,\X\-\X\=\X\~\X\!\X\?\X\<\X\>\X\;\X\*\X\|\X\@\X\ \X\_}%
48 \endgroup
49 \catcode`\[12
50 \catcode`\]12
51 \catcode`\:12
52 \catcode`\(12
53 \catcode`\)12
54 \catcode`\,12
55 \catcode`\-12
56 \catcode`\=12
57 \catcode`\~12
58 \catcode`\!12
59 \catcode`\?12
60 \catcode`\<12
61 \catcode`\>12
62 \catcode`\;12
63 \catcode`\*12
64 \catcode`\|12
65 \catcode`\@12
66 \catcode`\#6
67 \catcode`\ 10
68 \catcode`\_11
69
70 %-------------------- Vérification des prérequis ---------------------
71 \def\CF_error#1{\errmessage{Package \CFname\space Error: #1.}}
72 \def\CF_warning#1{\immediate\write-1{Package \CFname\space Warning: #1^^J}}
73 \def\CF_checkprimitive#1#2{% Vérifie que #1 est une primitive et sinon, émet le message #2 et exécute \endinput
74 \begingroup
75 \edef\__tempa{\meaning#1}%
76 \edef\__tempb{\string#1}%
77 \expandafter
78 \endgroup
79 \ifx\__tempa\__tempb\else
80 \CF_error{#2}%
81 \def\CF_temp{\CFrestorecatcode\endinput}%
82 \expandafter\CF_temp
83 \fi
84 }
85 \CF_checkprimitive\eTeXversion{You are not using an eTeX engine, \CFname\space cannot work.}
86 \CF_checkprimitive\expanded{the \string\expanded\space primitive is not provided by your TeX engine, \CFname\space cannot work.}
87
88 %------------------------ Chargement simplekv ------------------------
89 \input simplekv.tex
90
91 %-------------------------- Chargement tikz --------------------------
92 \unless\ifdefined\tikzpicture
93 \begingroup\def\CF_temp{\endgroup\input tikz.tex\relax}%
94 \expandafter\CF_temp
95 \fi
96 \usetikzlibrary{arrows.meta}
97
98 %--------------------------- Allocations -----------------------------
99 \newcount\CF_cnt_atomgroup
100 \newcount\CF_cnt_group
101 \newcount\CF_cnt_atom
102 \newcount\CF_cnt_cycle
103 \newcount\CF_cnt_cyclebonds
104 \newcount\CF_cnt_compound
105
106 \newif\ifCF_in_cycle
107 \newif\ifCF_cycle_arc
108 \newif\ifCF_define_submol
109 \newif\ifCF_adjust_name_dp
110 \newif\ifCF_macro_fixed_bond_length
111 \newif\ifCF_compound_is_chemfig
112
113 \newdimen\CF_dim
114 \newdimen\CF_turnangle
115 \newdimen\CF_arrowsize
116 \newdimen\CF_zero
117 \CF_zero=0pt
118
119 \newbox\CF_box
120 \newbox\CF_boxstuff
121 \newbox\CF_testbox
122 \newbox\CF_chargebox
123
124 \newtoks\CF_substtoks
125
126 %-------------------------- Petites macros ---------------------------
127 \let\CF_begintikzpicture\tikzpicture
128 \let\CF_endtikzpicture \endtikzpicture
129 \def\CF_quark{\CF_quark}
130 \def\CF_execfirst#1#2{#1}
131 \def\CF_execsecond#1#2{#2}
132 \def\CF_id#1{#1}
133 \def\CF_gobarg#1{}
134 \def\CF_gobtwoargs#1#2{}
135 \def\CF_firsttonil#1#2\_nil{#1}
136 \def\CF_sanitizelastitem#1,\empty#2\_nil{#1}
137 \def\CF_gobtikzinstruction#1;{}
138 \def\CF_makeother#1{\catcode`#1=12\relax}
139 \def\CF_lettoken#1#2{\let#1= #2}
140 \CF_lettoken\CF_sptoken{ }
141 \def\CF_ifx#1#2{\ifx#1#2\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi}
142 \def\CF_ifempty#1{\ifx\empty#1\empty\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi}
143 \def\CF_ifnum#1{\ifnum#1\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi}
144 \def\CF_ifinsidetikz{\ifdefined\pgfpictureid\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi}
145 \def\CF_ifzerodim#1{%r bugfix 1.71 : rollback à v1.66 !
146 \setbox\CF_testbox\hbox{\pgfinterruptpicture\printatom{#1}\endpgfinterruptpicture}% bugfix 1.53
147 \CF_ifnum{1\ifdim\wd\CF_testbox=\CF_zero0\fi\ifdim\ht\CF_testbox=\CF_zero0\fi\ifdim\dp\CF_testbox=\CF_zero0\fi=1000 }
148 }
149 \def\CF_doifempty#1{\ifx\empty#1\empty\expandafter\CF_id\else\expandafter\CF_gobarg\fi}
150 \def\CF_doifnotempty#1{\ifx\empty#1\empty\expandafter\CF_gobarg\else\expandafter\CF_id\fi}
151 \def\CF_gobtonil#1\_nil{}
152 \def\CF_striplastsp#1{%
153 \long\def\CF_stripsp##1##2{\expanded{\CF_stripsp_i\_marksp##1\__nil\_marksp#1\_marksp\_nil{##2}}}%
154 \long\def\CF_stripsp_i##1\_marksp#1##2\_marksp##3\_nil{\CF_stripsp_ii##3##1##2\__nil#1\__nil\_nil}%
155 \long\def\CF_stripsp_ii##1#1\__nil##2\_nil{\CF_stripsp_iii##1##2\_nil}%
156 \long\def\CF_stripsp_iii##1##2\__nil##3\_nil##4{\unexpanded{##4{##2}}}%
157 \long\def\CF_striplastsp##1##2{\expanded{\CF_striplastsp_i\_marksp##1\__nil#1\__nil\_nil{##2}}}%
158 \long\def\CF_striplastsp_i##1#1\__nil##2\_nil{\CF_stripsp_iii##1\__nil\_nil}%
159 }\CF_striplastsp{ }
160 \edef\CFhash{\string#}
161 \begingroup
162 \catcode`\_8
163 \expandafter\gdef\csname CF\string_underscore\endcsname{_}
164 \endgroup
165 \def\CF_threeea{\expandafter\expandafter\expandafter}
166 \def\CF_exptwomacroargs#1#2#3{\CF_expsecond{\CF_expsecond#1{#2}}{#3}}
167 \def\CF_expthreemacroargs#1#2#3#4{\CF_expsecond{\CF_exptwomacroargs#1{#2}{#3}}{#4}}
168 \def\CF_swaparg#1#2{#2{#1}}
169 \def\CF_expsecond#1#2{\expandafter\CF_swaparg\expandafter{#2}{#1}}% \CF_expsecond<{arg1>}{<arg2>} donne "<arg1>{*<arg2>}"
170 \def\CF_eexpsecond#1#2{\expandafter\expandafter\expandafter\CF_swaparg\expandafter\expandafter\expandafter{#2}{#1}}% \CF_eexpsecond{<arg1>}{<arg2>} donne "<arg1>{**<arg2>}"
171 \def\CF_swapunbrace#1#2{#2#1}
172 \def\CF_expafter#1#2{\expandafter\CF_swapunbrace\expandafter{#2}{#1}}% \CF_expafter{<arg1>}{<arg2>} donne "<arg1>*<arg2>"
173 \def\CF_eexpafter#1#2{\expandafter\expandafter\expandafter\CF_swapunbrace\expandafter\expandafter\expandafter{#2}{#1}}% \CF_eexpafter{<arg1>}{<arg2>} donne "<arg1>**<arg2>"
174 \def\CF_addtomacro#1#2{\CF_expsecond{\def#1}{#1#2}}
175 \def\CF_eaddtomacro#1#2{\CF_expsecond{\CF_addtomacro#1}{#2}}
176 \def\CF_preaddtomacro#1#2{\CF_expsecond{\CF_preaddtomacroa#1{#2}}#1}
177 \def\CF_preaddtomacroa#1#2#3{\def#1{#2#3}}
178 \def\CF_addtotoks#1#2{#1\expandafter{\the#1#2}}
179 \def\CF_eaddtotoks#1#2{\expandafter\CF_addtotoks\expandafter#1\expandafter{#2}}
180 \def\CF_assigntonil#1#2\_nil{\def#1{#2}}
181 \def\CF_edefaddtomacro#1#2{\CF_expsecond{\CF_addtomacro#1}{\expanded{#2}}}
182 \def\CF_ifnextchar#1#2#3{%
183 \let\CF_ifnextchartok=#1% <- espace indésirable, bugfix v1.31
184 \def\CF_ifnextcharcodetrue{#2}%
185 \def\CF_ifnextcharcodefalse{#3}%
186 \futurelet\CF_temptok\CF_ifnextchara
187 }
188 \def\CF_ifnextchara{%
189 \CF_ifx\CF_temptok\CF_sptoken
190 {%
191 \CF_ifnextcharb
192 }
193 {%
194 \CF_ifx\CF_temptok\CF_ifnextchartok
195 \CF_ifnextcharcodetrue
196 \CF_ifnextcharcodefalse
197 }%
198 }
199 \expandafter\def\expandafter\CF_ifnextcharb\space{\futurelet\CF_temptok\CF_ifnextchara}
200 \def\CF_ifstar#1{\CF_ifnextchar*{\CF_execfirst{#1}}}
201 \def\CF_testopt#1#2{\CF_ifnextchar[{#1}{#1[{#2}]}}
202 \def\CF_ifinteger#1{%
203 \begingroup
204 \afterassignment\CF_afterinteger
205 \CF_cnt_cyclebonds0#1\relax
206 }
207 \def\CF_afterinteger#1\relax{%
208 \endgroup
209 \CF_ifempty{#1}%
210 }
211 \def\CF_iffirsttokmatch#1#2{% est ce que #1 et #2 commencent par les mêmes tokens ?
212 \futurelet\CF_toksa\CF_gobtonil#1\relax\_nil
213 \futurelet\CF_toksb\CF_gobtonil#2\relax\_nil
214 \CF_ifx\CF_toksa\CF_toksb
215 }
216 \def\CF_iffirsttokin#1{% teste si le token qui commence #1 appartient aux tokens mis dans #2
217 \futurelet\CF_toksa\CF_gobtonil#1\relax\_nil
218 \CF_iffirsttokina
219 }
220 \def\CF_iffirsttokina#1{%
221 \CF_ifempty{#1}
222 {%
223 \CF_execsecond
224 }
225 {%
226 \futurelet\CF_toksb\CF_gobtonil#1\relax\_nil
227 \CF_ifx\CF_toksa\CF_toksb
228 {%
229 \CF_execfirst
230 }
231 {%
232 \CF_expsecond\CF_iffirsttokina{\CF_gobarg#1}%
233 }%
234 }%
235 }
236 \def\CF_ifinstr#1#2{%
237 \def\CF_ifinstra##1#2##2\_nil{%
238 \ifx\empty##2\empty
239 \expandafter\CF_execsecond
240 \else
241 \expandafter\CF_execfirst
242 \fi}%
243 \CF_ifinstra#1\__nil#2\_nil
244 }
245 \def\CF_afterspace#1 #2\_nil{#2}
246 \def\CF_ifxcase_endif{\CF_ifxcase_endif}
247 \def\CF_ifxcase_elseif{\CF_ifxcase_elseif}
248 \def\CF_idto_endif#1\CF_ifxcase_endif{#1}
249 \def\CF_firstto_endif#1#2\CF_ifxcase_endif{#1}
250 \def\CF_ifxcase#1#2{% #1=token à tester #2=token courant auquel #1 est comparé
251 \CF_ifx\CF_ifxcase_elseif#2%
252 {%
253 \CF_idto_endif
254 }
255 {%
256 \CF_ifx\CF_ifxcase_endif#2%
257 {}
258 {%
259 \CF_ifx#1#2
260 {\CF_firstto_endif}
261 {\CF_ifxcase_a#1}%
262 }%
263 }%
264 }
265 \def\CF_ifxcase_a#1#2{\CF_ifxcase{#1}}
266
267 %--------------------------- Substitution ----------------------------
268 \def\CF_ifstartwith#1#2{% #1=<texte> #2=<motif>
269 \CF_ifempty{#1}%
270 {%
271 \CF_execsecond
272 }
273 {%
274 \def\CF_startwithcode{#1}%
275 \def\CF_startwithpattern{#2}%
276 \CF_ifstartwitha
277 }%
278 }
279 \def\CF_ifstartwitha{%
280 \CF_grabfirstarg\CF_startwithcode\CF_firstargcode
281 \CF_grabfirstarg\CF_startwithpattern\CF_firstargpattern
282 \CF_ifx\CF_firstargcode\CF_firstargpattern
283 {%
284 \CF_expsecond\CF_ifempty\CF_startwithpattern
285 {%
286 \CF_execfirst
287 }
288 {%
289 \CF_expsecond\CF_ifempty\CF_startwithcode
290 \CF_execsecond
291 \CF_ifstartwitha
292 }%
293 }
294 {%
295 \CF_execsecond
296 }%
297 }
298 \def\CF_grabfirstarg#1#2{%
299 \CF_ifx#1\empty
300 {%
301 \let#2\empty
302 }
303 {%
304 \def\CF_grabmacro{#2}%
305 \CF_expsecond\CF_ifbracefirst#1%
306 {%
307 \expandafter\CF_grabbracearg#1\_nil#1%
308 }
309 {%
310 \CF_expafter{\futurelet\CF_nexttok\CF_grabfirstarga}#1\_nil#1%
311 }%
312 }%
313 }
314 \def\CF_grabfirstarga{%
315 \CF_ifx\CF_nexttok\CF_sptoken
316 \CF_grabspacearg
317 \CF_grabnormalarg
318 }
319 \def\CF_grabbracearg#1{%
320 \expandafter\def\CF_grabmacro{{#1}}%
321 \CF_grabargassigntonil\relax
322 }
323 \expandafter\def\expandafter\CF_grabspacearg\space{%
324 \expandafter\def\CF_grabmacro{ }%
325 \CF_grabargassigntonil\relax
326 }
327 \def\CF_grabnormalarg#1{%
328 \expandafter\def\CF_grabmacro{#1}%
329 \CF_grabargassigntonil\relax
330 }
331 \def\CF_grabargassigntonil#1\_nil#2{\CF_expsecond{\def#2}{\CF_gobarg#1}}
332 \def\CF_ifbracefirst#1{\CF_ifnum{\catcode\CF_threeea`\expandafter\CF_firsttonil\detokenize{#1.}\_nil=1 }}
333 \def\CF_substonly#1#2{% #1=entier maxi>0 #2=macro : dans la sc#1, remplace tous les <motif> par <pattern> sauf lorsque le motif est suivi d'un caractère >#1
334 \def\CF_atendsubstitute{\edef#2{\the\CF_substtoks}}% macro exécutée à la fin
335 \let\CF_substnogroups\CF_substnogrouponly
336 \CF_ifnum{#1>0 }
337 {%
338 \let\CF_testifx\empty
339 \foreach\CF_x in {1,...,#1}
340 {%
341 \xdef\CF_testifx{\unexpanded\expandafter{\CF_testifx}\unexpanded\expandafter{\expandafter\ifx\CF_x\CF_nexttok1\fi}}%
342 }%
343 \let\CF_testif\empty
344 \foreach\CF_x in {1,...,#1}
345 {%
346 \xdef\CF_testif{\unexpanded\expandafter{\CF_testif}\unexpanded\expandafter{\expandafter\if\CF_x\CF_nexttok1\fi}}%
347 }%
348 \CF_expsecond\CF_substi#2%
349 }
350 {%
351 \CF_substall#2%
352 }%
353 }
354 \def\CF_substnogrouponly{%
355 \CF_exptwomacroargs\CF_ifstartwith\CF_substcode\CF_substsubst
356 {%
357 \CF_grabfirstarg\CF_substcode\CF_temp
358 \CF_expafter{\futurelet\CF_nexttok\CF_gobtonil}\CF_substcode\relax\_nil
359 \CF_ifnum{0\CF_testifx=1 }% si le prochain token est \let-égal à 1...#1
360 {%
361 \edef\CF_nexttok{\CF_threeea\CF_firsttonil\expandafter\string\CF_substcode\_nil}% le détokéniser
362 \CF_ifnum{0\CF_testif=1 }
363 {%
364 \CF_eaddtotoks\CF_substtoks\CF_temp
365 \CF_grabfirstarg\CF_substcode\CF_temp
366 \CF_eaddtotoks\CF_substtoks\CF_temp
367 }
368 {%
369 \CF_eaddtotoks\CF_substtoks\CF_substpattern
370 }%
371 }
372 {%
373 \CF_eaddtotoks\CF_substtoks\CF_substpattern
374 }%
375 \CF_substgroups
376 }
377 {%
378 \CF_expsecond\CF_ifempty\CF_substcode
379 {%
380 \CF_atendsubstitute
381 }
382 {%
383 \CF_grabfirstarg\CF_substcode\CF_substauxarg
384 \CF_eaddtotoks\CF_substtoks\CF_substauxarg
385 \CF_substgroups
386 }%
387 }%
388 }
389 \def\CF_substall#1{% #1=macro
390 \def\CF_atendsubstitute{\edef#1{\the\CF_substtoks}}% macro exécutée à la fin
391 \let\CF_substnogroups\CF_substnogroupall
392 \CF_expsecond\CF_substi#1%
393 }
394 \def\CF_substnogroupall{%
395 \CF_exptwomacroargs\CF_ifstartwith\CF_substcode\CF_substsubst
396 {%
397 \CF_eaddtotoks\CF_substtoks\CF_substpattern
398 \CF_grabfirstarg\CF_substcode\CF_temp
399 \CF_substgroups
400 }
401 {%
402 \CF_expsecond\CF_ifempty\CF_substcode
403 {%
404 \CF_atendsubstitute
405 }
406 {%
407 \CF_grabfirstarg\CF_substcode\CF_substauxarg
408 \CF_eaddtotoks\CF_substtoks\CF_substauxarg
409 \CF_substgroups
410 }%
411 }%
412 }
413 \def\CF_substi#1#2#3{% #1=<texte> #2=<motif> #3=<motif de substi>
414 \def\CF_substcode{#1}\def\CF_substsubst{#2}\def\CF_substpattern{#3}%
415 \CF_substtoks={}%
416 \CF_substgroups
417 }
418
419 \def\CF_substgroups{%
420 \CF_expsecond\CF_ifbracefirst\CF_substcode
421 {%
422 \CF_grabfirstarg\CF_substcode\CF_substauxarg
423 \begingroup
424 \def\CF_atendsubstitute{%
425 \expandafter\endgroup\expandafter\CF_addtotoks\expandafter\CF_substtoks\expandafter{\expandafter{\the\CF_substtoks}}%
426 \CF_substgroups
427 }%
428 \CF_substtoks{}% initialiser à vide
429 \expandafter\def\expandafter\CF_substcode\CF_substauxarg
430 \CF_substgroups
431 }%
432 {%
433 \CF_substnogroups
434 }%
435 }
436
437 %---------------------------- Paramètres -----------------------------
438 \def\CF_defifempty#1#2#3{\CF_ifempty{#2}{\def#1{#3}}{\def#1{#2}}}
439 \defKV[chemfig]{%
440 atom style = \def\CF_atomstyle {#1},
441 baseline = \CF_defifempty\CF_baseline {#1}{0pt},% nouveau v 1.6e
442 chemfig style = \def\CF_chemfigstyle {#1},
443 cram width = \CF_defifempty\CF_crambasewidth {#1}{1.5ex},
444 cram dash width = \CF_defifempty\CF_cramdashlength {#1}{1pt},
445 cram dash sep = \CF_defifempty\CF_cramdashsep {#1}{2pt},
446 atom sep = \CF_defifempty\CF_atomsep {#1}{3em},
447 bond offset = \CF_defifempty\CF_bondoffset {#1}{2pt},
448 double bond sep = \CF_defifempty\CF_doublesep {#1}{2pt},
449 angle increment = \CF_defifempty\CF_angleincrement {#1}{45},
450 node style = \def\CF_nodestyle {#1},
451 bond style = \def\CF_bondstyle {#1},
452 cycle radius coeff = \CF_defifempty\CF_cycleradiuscoeff {#1}{0.75},
453 stack sep = \CF_defifempty\CF_stacksep {#1}{1.5pt},
454 compound style = \def\CF_defaultcompoundstyle {#1},
455 compound sep = \CF_defifempty\CF_compoundsep {#1}{5em},
456 arrow offset = \CF_defifempty\CF_arrowoffset {#1}{1em},
457 arrow angle = \CF_defifempty\CF_arrowangle {#1}{0},
458 arrow coeff = \CF_defifempty\CF_arrowlength {#1}{1},
459 arrow style = \def\CF_defaultarrowstyle {#1},
460 arrow double sep = \CF_defifempty\CF_arrowdoublesep {#1}{2pt},
461 arrow double coeff = \CF_defifempty\CF_arrowdoubleposstart{#1}{0.6},
462 arrow label sep = \CF_defifempty\CF_arrowlabelsep {#1}{3pt},
463 arrow head = \CF_defifempty\CF_arrowhead {#1}{-CF},
464 init anchor = \CF_defifempty\CF_nextnodeanchor {#1}{text},% new v1.71
465 + sep left = \CF_defifempty\CF_signspaceante {#1}{0.5em},
466 + sep right = \CF_defifempty\CF_signspacepost {#1}{0.5em},
467 + vshift = \CF_defifempty\CF_signvshift {#1}{0pt},
468 harrow minwidth = \CF_defifempty\CF_harrow_min_width {#1}{3em},
469 label xsep = \CF_defifempty\CF_harrow_label_xsep {#1}{3pt},
470 label align = \CF_set_label_align {#1},
471 name sep = \CF_defifempty\CF_hreac_name_sep {#1}{1.5ex},
472 hreac anchor = \def\CF_hreac_init_anchor {#1},
473 hreac sep = \CF_defifempty\CF_hreac_sep {#1}{0.5em},
474 }
475 \def\CF_set_label_align#1{%
476 \let\CF_harrow_label_align_right\hss
477 \let\CF_harrow_label_align_left \hss
478 \expandafter\CF_ifxcase\CF_firsttonil#1c\_nil
479 c {}
480 l {\let\CF_harrow_label_align_left\empty}
481 r {\let\CF_harrow_label_align_right\empty}
482 \CF_ifxcase_elseif
483 \CF_error{Illegal alignment directive '#1'}%
484 \CF_ifxcase_endif
485 }
486 \def\setchemfig{\setKV[chemfig]}
487 \def\resetchemfig{\restoreKV[chemfig]}
488 \setKVdefault[chemfig]{%
489 atom style = {},% code tikz mis à la fin de every node/.style
490 use atom strut = false,% met à chaque atome le strut de l'atome précédent nouveau 1.7
491 baseline = {0pt},% nouveau v 1.6e
492 chemfig style = {},% code tikz mis à la fin de l'arugment optionnel de \tikzpicture
493 bond join = false,
494 fixed length = false,
495 cram rectangle = false,
496 cram width = 1.5ex,
497 cram dash width = 1pt,
498 cram dash sep = 2pt,
499 atom sep = 3em,
500 bond offset = 2pt,
501 double bond sep = 2pt,
502 angle increment = 45,
503 node style = {},
504 bond style = {},
505 cycle radius coeff = 0.75,
506 stack sep = 1.5pt,
507 autoreset cntcycle = true,
508 show cntcycle = false,
509 debug = false,
510 scheme debug = false,
511 compound style = {},
512 compound sep = 5em,
513 arrow offset = 1em,
514 arrow angle = 0,
515 arrow coeff = 1,
516 arrow style = {},
517 arrow double sep = 2pt,
518 arrow double coeff = 0.6,
519 arrow double harpoon= true,
520 arrow label sep = 3pt,
521 arrow head = -CF,
522 init anchor = text, % new v1.71
523 + sep left = 0.5em,
524 + sep right = 0.5em,
525 + vshift = 0pt,
526 gchemname = true, % ajout de cette clé v1.6c
527 schemestart code = {}, % ajout de cette clé v1.6c
528 schemestop code = {}, % ajout de cette clé v1.6c
529 harrow minwidth = 3em, % dimension minimale de la flèche
530 hreac debug = false,
531 label xsep = 3pt, % dist H supplémentaire
532 label align = c, % vaut c, l ou r
533 name sep = 1.5ex, % distance v entre composé et nom
534 hreac anchor = text, % ancre de la ligne de base du 1er composé
535 hreac sep = 0.5em % espace horizontal entre composés
536 }%
537
538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539 %%% D E S S I N M O L É C U L E S %%%
540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541 \def\CF_sanitizecatcode{%
542 \CF_makeother\[%
543 \CF_makeother\]%
544 \CF_makeother\:%
545 \CF_makeother\(%
546 \CF_makeother\)%
547 \CF_makeother\,%
548 \CF_makeother\-%
549 \CF_makeother\=%
550 \CF_makeother\~%
551 \CF_makeother\!%
552 \CF_makeother\?%
553 \CF_makeother\<%
554 \CF_makeother\>%
555 \CF_makeother\;%
556 \CF_makeother\*%
557 \CF_makeother\|%
558 \CF_makeother\#%
559 \CF_makeother\@%
560 }
561
562 \def\printatom#1{\ifmmode\rm#1\else$\rm#1$\fi}
563 \def\CF_nodecontent{% \CF_nodestrut = \empty si "use atom strut=true"
564 \CF_eexpsecond\printatom{\csname atom_\number\CF_cnt_atom\expandafter\endcsname\CF_nodestrut}%
565 }
566
567 \def\chemskipalign{%
568 \CF_doifempty\CF_bondoutcontentsaved% sauf si un \chemskipalign a été fait à l'atome précédent
569 {%
570 \global\let\CF_bondoutcontentsaved\CF_bondoutcontent% sauvegarder l'atome d'où vient la liaison
571 }%
572 \let\CF_nodestrut\empty
573 }
574
575 \def\definesubmol{\CF_define_submoltrue\CF_defsubmol}
576 \def\redefinesubmol{\CF_define_submolfalse\CF_defsubmol}
577
578 \def\CF_defsubmol#1{%
579 \CF_cnt_atomgroup=0 % nombre d'arguments supposé
580 \def\CF_temp{#1}% nom
581 \futurelet\CF_toksa\CF_submoltestnxttok
582 }
583
584 \def\CF_submoltestnxttok{%
585 \if[\noexpand\CF_toksa\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi
586 {%
587 \begingroup\CF_sanitizecatcode\CF_expsecond\CF_submolgrabopt{\CF_temp}%
588 }
589 {%
590 \afterassignment\CF_submoltestnxttoka% pas d'argument entre crochet
591 \CF_cnt_atomgroup=0% cherche le nombre d'arguments éventuels
592 }%
593 }
594
595 \def\CF_submoltestnxttoka{\futurelet\CF_toksa\CF_submoltestnxttokb}
596
597 \def\CF_submoltestnxttokb{%
598 \if[\noexpand\CF_toksa\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi
599 {%
600 \begingroup\CF_sanitizecatcode\CF_expsecond\CF_submolgrabopt{\CF_temp}%
601 }
602 {%
603 \CF_expsecond{\CF_defsubmola}\CF_temp{}%
604 }%
605 }
606
607 \def\CF_submolgrabopt#1[#2]#{\endgroup\CF_defsubmola{#1}{#2}}
608
609 \def\CF_defsubmola#1{% #1 nom
610 \CF_ifnum{0\CF_ifnum{\CF_cnt_atomgroup<0 }1{\CF_ifnum{\CF_cnt_atomgroup>9 }10}>0 }
611 {%
612 \CF_error{Invalid number of arguments in submol \detokenize\expandafter{\string#1}. Defining it with 0 argument}%
613 \CF_cnt_atomgroup=0
614 }
615 {}%
616 \ifcat\relax\expandafter\noexpand\CF_firsttonil#1\_nil\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi% si #1 est une séquence de contrôle
617 {%
618 \expandafter\ifdefined\CF_firsttonil#1\_nil
619 \ifCF_define_submol
620 \CF_warning{the submol \expandafter\string\CF_firsttonil#1\_nil\space is already defined, the previous definition is lost}%
621 \fi
622 \fi
623 \begingroup
624 \CF_sanitizecatcode
625 \CF_defsubmolb{#1}%
626 }
627 {%
628 \ifcsname CF__#1\endcsname
629 \ifCF_define_submol
630 \CF_warning{the submol "#1" is already defined, the previous definition is lost}%
631 \fi
632 \fi
633 \begingroup
634 \CF_sanitizecatcode
635 \expandafter\CF_defsubmolb\csname CF__#1\endcsname
636 }%
637 }
638
639 \def\CF_defsubmolb#1#2#3{% #1 nom sous forme de macro, #2 = code si liaison arrive de droite , #3 = code si liaison arrive de gauche, \CF_cnt_atomgroup = nombre d'arguments
640 \def\CF_tempa{#2}%
641 \CF_doifnotempty{#2}
642 {%
643 \CF_expsecond{\CF_expsecond\CF_substonly{\number\CF_cnt_atomgroup}\CF_tempa}{\CFhash}{\CFhash}%
644 }%
645 \def\CF_tempb{#3}%
646 \CF_expsecond{\CF_expsecond\CF_substonly{\number\CF_cnt_atomgroup}\CF_tempb}{\CFhash}{\CFhash}%
647 \CF_expsecond{\CF_expsecond{\CF_defsubmolc{#1}}\CF_tempa}\CF_tempb
648 }
649
650 \def\CF_defsubmolc#1#2#3{% #1 nom sous forme de macro, #2 = code si liaison arrive de droite , #3 = code si liaison arrive de gauche, \CF_cnt_atomgroup = nombre d'arguments
651 \endgroup
652 \begingroup
653 \global\toks0{\gdef\CFthesubmol}%
654 \CF_ifnum{\CF_cnt_atomgroup>0 }
655 {%
656 \foreach\CF_x in {1,...,\CF_cnt_atomgroup}%
657 {%
658 \global\toks0\expandafter{\expanded{\the\toks0\CFhash\CF_x}}%
659 }%
660 }
661 {}%
662 \CF_sanitizecatcode
663 \catcode`\#6
664 \endlinechar-1
665 \everyeof{\noexpand}%
666 \CF_ifempty{#2}%
667 {%
668 \scantokens\expandafter{\the\toks0{\empty#3}}%
669 }%
670 {%
671 \scantokens\expandafter
672 {%
673 \the\toks0
674 {%
675 \expanded
676 {% bugfix 1.52
677 \csname CF_exec%
678 \ifdim\csname CF_currentangle\endcsname pt>90pt
679 \ifdim\csname CF_currentangle\endcsname pt<270pt
680 first%
681 \else
682 second%
683 \fi
684 \else
685 second%
686 \fi
687 \endcsname
688 {\unexpanded{#2}}{\unexpanded{#3}}%
689 }%
690 }%
691 }%
692 }%
693 \endgroup
694 \let#1\CFthesubmol
695 }
696
697 \def\CF_searchnode#1#2#3{% cherche un noeud au début de #1 l'assigne dans la sc #2 et met le reste dans #3
698 \let#2\empty
699 \def#3{#1}%
700 \CF_iffirsttokmatch{#1}{ }%
701 {%
702 \CF_expsecond\CF_searchnodea{\romannumeral-`\.\noexpand#1}#2#3% ignore les espaces au début du groupe d'atome
703 }%
704 {%
705 \CF_searchnodea{#1}#2#3%
706 }%
707 }
708
709 \def\CF_searchnodea#1#2#3{%
710 \CF_ifempty{#1}%
711 {%
712 \let#3\empty
713 }
714 {%
715 \futurelet\CF_toksa\CF_gobtonil#1\relax\_nil
716 \CF_ifx\CF_toksa\CF_sptoken
717 {%
718 \CF_addtomacro#2{ }%
719 \CF_expsecond\CF_searchnodea{\CF_afterspace#1\_nil}#2#3%
720 }%
721 {%
722 \CF_ifx\CF_toksa\bgroup
723 {%
724 \CF_eaddtomacro#2{\expandafter{\CF_firsttonil#1\_nil}}%
725 \CF_expsecond\CF_searchnodea{\CF_gobarg#1}#2#3%
726 }%
727 {%
728 \CF_ifx!\CF_toksa% Bugfix v1.5
729 {%
730 \def\CF_seeksubmloltemp{#1}%
731 \CF_searchsubmola
732 \CF_expsecond\CF_searchnodea\CF_seeksubmloltemp#2#3%
733 }
734 {%
735 \CF_iffirsttokina{-=(*<>~}%
736 {%
737 \def#3{#1}%
738 }%
739 {%
740 \CF_eaddtomacro#2{\CF_firsttonil#1\_nil}%
741 \CF_expsecond\CF_searchnodea{\CF_gobarg#1}#2#3%
742 }%
743 }
744 }%
745 }%
746 }%
747 }
748
749 % on sait que #1 commence par -,=,~,<,>. On analyse cette liaison
750 % #2 reçoit le type de liaisons (1 pour -, 2 pour =, 3 pour ~)
751 \def\CF_assignbondcode#1#2{%
752 \futurelet\CF_toksa\CF_gobtonil#1\_nil
753 \edef#2{%
754 \ifx-\CF_toksa1\else
755 \ifx=\CF_toksa2\else
756 \ifx~\CF_toksa3\else
757 \ifx>\CF_toksa4\else
758 \ifx<\CF_toksa5\else0% si 0 --> il y a une erreur non due à l'utilisateur
759 \fi\fi\fi\fi\fi
760 }%
761 \ifnum#2>3 % si c'est une liaison de Cram
762 \CF_expafter{\futurelet\CF_toksa\CF_gobtonil}{\CF_gobarg#1\_nil}% chope le caractère suivant
763 \CF_ifx:\CF_toksa
764 {%
765 \edef#2{\number\numexpr#2+2}% si c 'est un ":", signe du pointillé, ajoute 2
766 }%
767 {%
768 \CF_ifx|\CF_toksa% si c 'est un "|", signe du triangle évidé, ajouter 4
769 {%
770 \edef#2{\number\numexpr#2+4}%
771 }
772 {}%
773 }%
774 \fi
775 }
776
777 \def\CF_grabbondoffseta#1,#2\_nil{%
778 \def\CF_startoffset{#1}\def\CF_endoffset{#2}%
779 }
780
781 \def\CF_grabbondoffset#1(#2)#3\_nil{%
782 \CF_doifnotempty{#2}%
783 {%
784 \CF_ifinstr{#2},%
785 {%
786 \CF_grabbondoffseta#2\_nil
787 }%
788 {%
789 \def\CF_startoffset{#2}%
790 }%
791 }%
792 \def\CF_remainafterbond{#3}%
793 }
794
795 \def\CF_analysebond#1#2{%
796 \CF_assignbondcode{#1}#2%
797 \CF_expsecond{\def\CF_remainafterbond}{\CF_gobarg#1}%mange le premier signe de la liaison
798 \let\CF_doublebondtype\CF_zero
799 \ifnum#2=2 % si c'est une double liaison, regarde s'il y a un + ou - derrière
800 \CF_expafter{\futurelet\CF_toksa\CF_gobtonil}{\CF_gobarg#1\_nil}%
801 \CF_ifx^\CF_toksa
802 {%
803 \def\CF_doublebondtype{1}%
804 \CF_expsecond{\def\CF_remainafterbond}{\CF_gobtwoargs#1}% mange le "^"
805 }
806 {%
807 \expandafter\ifx\CF_underscore\CF_toksa
808 \def\CF_doublebondtype{2}%
809 \CF_expsecond{\def\CF_remainafterbond}{\CF_gobtwoargs#1}% mange le "_"
810 \fi
811 }%
812 \else
813 \ifnum#2>5 % si c'est une laision de Cram pointillée ou triangle évidé
814 \CF_expsecond{\def\CF_remainafterbond}{\CF_gobtwoargs#1}% mange un caractère de plus
815 \fi
816 \fi
817 \CF_expsecond\CF_iffirsttokmatch\CF_remainafterbond\CFhash
818 {%
819 \CF_eexpsecond\CF_iffirsttokmatch{\expandafter\CF_gobarg\CF_remainafterbond.}(%si parenthèse juste après
820 {%
821 \expandafter\CF_grabbondoffset\CF_remainafterbond\_nil
822 }
823 {}%
824 }%
825 {}%
826 \CF_expsecond\CF_iffirsttokmatch\CF_remainafterbond @%
827 {%
828 \expandafter\CF_grabmovearg\CF_remainafterbond\_nil
829 }%
830 {}%
831 \CF_expsecond\CF_iffirsttokmatch{\CF_remainafterbond}[%
832 {%
833 \expandafter\CF_analyseoptarg\CF_remainafterbond\_nil\CF_remainafterbond
834 }%
835 {%
836 \let\CF_currentstringangle\CF_defaultstringangle
837 \let\CF_currentlength\CF_defaultlength
838 \let\CF_currentfromatom\CF_defaultfromatom
839 \let\CF_currenttoatom\CF_defaulttoatom
840 \let\CF_currenttikz\CF_defaulttikz
841 \let\CF_movebondname\empty
842 }%
843 \ifCF_in_cycle
844 \pgfmathsetmacro\CF_cycleincrementangle{360/\CF_cyclenum+\CF_initcycleangle}%
845 \edef\CF_currentstringangle{::+\CF_cycleincrementangle}%
846 \def\CF_initcycleangle{0}%
847 \let\CF_currentlength\CF_defaultlength% et on ignore la longueur de liaison spécifiée
848 \fi
849 \CF_expsecond\CF_setbondangle{\CF_currentstringangle}\CF_currentangle
850 }
851
852 \def\CF_setbondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
853 \CF_ifempty{#1}%
854 {%
855 \let#2\CF_defaultangle
856 }
857 {%
858 \if:\expandafter\noexpand\CF_firsttonil#1\_nil
859 \if:\CF_threeea\noexpand\expandafter\CF_firsttonil\CF_gobarg#1\_nil
860 \pgfmathsetmacro#2{\CF_previousangle+\expandafter\CF_gobarg\CF_gobarg#1}%
861 \else
862 \pgfmathsetmacro#2{\CF_gobarg#1}%
863 \fi
864 \else
865 \pgfmathsetmacro#2{#1*\CF_angleincrement}%
866 \fi% puis normalise l'angle entre 0 et 360
867 \ifdim\ifdim#2pt<0pt -\fi#2pt>360pt
868 \pgfmathsetmacro#2{#2-360*floor(#2/360)}%
869 \fi% si |#2|>360
870 \ifdim#2pt<0pt
871 \pgfmathsetmacro#2{#2+360}%
872 \fi
873 }%
874 }
875
876 \def\CF_analysemovearg#1,#2\_nil#3{%
877 \def#3{#1}%
878 \def\CF_movebondcoeff{#2}%
879 }
880
881 % Argument limités légitimes ici car #2 (qui est ce qui suit "@{<nom>}" dans l'argument optionnel) ne DOIT PAS commencer par une accolade.
882 \def\CF_grabmovearg @#1#2\_nil{%
883 \CF_ifinstr{#1},%
884 {%
885 \CF_analysemovearg#1\_nil\CF_movebondname
886 }%
887 {%
888 \def\CF_movebondname{#1}%
889 \def\CF_movebondcoeff{0.5}%
890 }%
891 \def\CF_remainoptarg{#2}%
892 }
893
894 \def\CF_testemptyandassign#1#2#3{%
895 \CF_ifempty{#2}
896 {%
897 \let#1#3%
898 }
899 {%
900 \def#1{#2}%
901 }%
902 }
903
904 \def\CF_parseoptlist#1,#2,#3,#4,#5\_nil{%
905 \CF_testemptyandassign\CF_currentstringangle{#1}\CF_defaultstringangle
906 \CF_testemptyandassign\CF_currentlength {#2}\CF_defaultlength
907 \CF_testemptyandassign\CF_currentfromatom {#3}\CF_defaultfromatom
908 \CF_testemptyandassign\CF_currenttoatom {#4}\CF_defaulttoatom
909 \CF_expsecond{\CF_testemptyandassign\CF_currenttikz}{\CF_sanitizelastitem#5,\empty\_nil}\CF_defaulttikz
910 }%
911
912 \def\CF_analyseoptarg[#1]{%
913 \CF_doifnotempty{#1}%
914 {%
915 \CF_iffirsttokmatch{#1}{@}%
916 {%
917 \CF_grabmovearg#1\_nil
918 }
919 {%
920 \let\CF_movebondname\empty
921 \def\CF_remainoptarg{#1}%
922 }%
923 \expandafter\CF_parseoptlist\CF_remainoptarg,\empty,\empty,\empty,\empty\_nil
924 }%
925 \CF_analyseoptarga\relax
926 }
927
928 \def\CF_analyseoptarga#1\_nil#2{%
929 \CF_expsecond{\def#2}{\CF_gobarg#1}%
930 }
931
932 \def\CF_searchsubmol#1#2{% cherche et remplace ! au début de #1. #1=code #2=macro recevant le résultat
933 \def\CF_seeksubmloltemp{#1}%
934 \CF_searchsubmola
935 \let#2\CF_seeksubmloltemp
936 }
937
938 \def\CF_searchsubmola{%
939 \CF_expsecond{\def\CF_seeksubmloltemp}{\romannumeral-`\.\expandafter\noexpand\CF_seeksubmloltemp}%
940 \CF_expsecond\CF_iffirsttokmatch{\CF_seeksubmloltemp}!%
941 {%
942 \CF_eexpsecond{\def\CF_seeksubmloltemp}{\expandafter\CF_gobarg\CF_seeksubmloltemp}% enlève le "!"
943 \CF_ifx\empty\CF_seeksubmloltemp
944 {%
945 \CF_error{no submol name found after "!"}%
946 }
947 {}%
948 \ifcat\relax\CF_threeea\noexpand\expandafter\CF_firsttonil\CF_seeksubmloltemp*\_nil
949 \expandafter\CF_searchsubmolb\CF_seeksubmloltemp\_nil
950 \else
951 \expandafter\CF_searchsubmolc\CF_seeksubmloltemp\_nil
952 \fi
953 \CF_searchsubmola
954 }%
955 {}%
956 }
957
958 \def\CF_searchsubmolb#1{\CF_searchsubmold#1\relax}
959
960 \def\CF_searchsubmolc#1{\expandafter\CF_searchsubmold\csname CF__#1\endcsname\relax}% nom de la sous molécule
961
962 \def\CF_searchsubmold#1#2\_nil{% #1=macro de la sous molécule #2=reste du code commençant par \relax
963 \CF_expsecond{\CF_eexpsecond{\def\CF_seeksubmloltemp}}{\expandafter#1\CF_gobarg#2}% supprime le \relax puis ajoute la macro au début et la 2-développe
964 }
965
966 \def\CF_insertemptygroup#1{% insère {} au début de la sc #1
967 \CF_expsecond{\def#1}{\expandafter{\expandafter}#1}%
968 }
969 \def\chemfig{\CF_testopt\CF_chemfiga{}}
970
971 \def\CF_chemfiga[#1]{%
972 \begingroup
973 \CF_sanitizecatcode
974 \CF_exptwomacroargs\CF_chemfigb\CF_begintikzpicture\CF_endtikzpicture[#1]%
975 }
976
977 \def\CF_chemfigb#1#2[#3]#4{%
978 \endgroup
979 \begingroup
980 \setchemfig{#3}%
981 \CF_ifinsidetikz
982 {%
983 \pgfinterruptpicture
984 \let\CF_atendofchemfig\endpgfinterruptpicture
985 }
986 {%
987 \let\CF_atendofchemfig\relax
988 }%
989 \expanded
990 {% début du tikzpicture
991 \unexpanded{#1}[%
992 remember picture,%
993 every node/.style={%
994 anchor=base,%
995 inner sep=0pt,%
996 outer sep=0pt,%
997 minimum size=0pt,%
998 \unexpanded\expandafter{\CF_atomstyle}%
999 },%
1000 baseline=\CF_baseline,%
1001 \unexpanded\expandafter{\CF_chemfigstyle}%
1002 ]%
1003 }%
1004 \begingroup% \endgroup rajouté en sortie de tracé par \CF_chemfigd
1005 \let\CF_hooklist\empty
1006 \ifboolKV[chemfig]{fixed length}
1007 {%
1008 \CF_macro_fixed_bond_lengthtrue
1009 }
1010 {%
1011 \CF_macro_fixed_bond_lengthfalse
1012 }%
1013 \ifboolKV[chemfig]{bond join}
1014 {%
1015 \let\CF_drawaxisbond\CF_drawaxisbondjoin
1016 }
1017 {%
1018 \let\CF_drawaxisbond\CF_drawaxisbondnojoin
1019 }%
1020 \ifboolKV[chemfig]{cram rectangle}
1021 {%
1022 \let\CF_clipcramornot\CF_gobtikzinstruction
1023 }
1024 {%
1025 \let\CF_clipcramornot\clip
1026 }%
1027 \CF_in_cyclefalse
1028 \CF_cnt_group0
1029 \ifboolKV[chemfig]{autoreset cntcycle}
1030 {%
1031 \global\CF_cnt_cycle0
1032 }
1033 {}%
1034 \let\CF_lastaction\CF_zero% 0=début du dessin 1=tracé d'un noeud 2=tracé d'une liaison
1035 \let\CF_startoffset\empty
1036 \let\CF_endoffset\empty
1037 \let\CF_bondoutcontentsaved\empty
1038 \def\CF_cycleanglecorrection{180/\CF_cyclenum}%
1039 \def\CF_defaultangle{0}%
1040 \def\CF_defaultstringangle{:0}% angle pris par défaut si le champ est vide
1041 \def\CF_defaultlength{1}%
1042 \let\CF_defaultfromatom\empty% numero de l'atome d'où partent les liaisons par défaut
1043 \let\CF_defaulttoatom\empty% numéro de l'atome où arrivent les laisons par défaut
1044 \let\CF_defaulttikz\empty
1045 \let\CF_previousbondangle\empty
1046 \def\CF_previousbondtype{0}%
1047 \def\CF_previousnode{}%
1048 \def\CF_previous_offset{0pt}%
1049 \let\CF_joinbond\CF_zero
1050 \let\CF_previoustikz\empty
1051 \everyeof{\_nil}\endlinechar-1
1052 \CF_sanitizecatcode
1053 \expandafter\CF_assigntonil\expandafter\CF_molecule\scantokens{#4}%
1054 \CF_expsecond{\CF_substall\CF_molecule}\CFhash\CFhash
1055 \CF_expsecond\CF_chemfigc{\CF_molecule}%
1056 %\endgroup <-- rajouté par \CF_chemfigd
1057 #2% fin du tikzpicture
1058 \CF_atendofchemfig
1059 \endgroup
1060 \let\CF_flipstate\CF_zero
1061 }
1062
1063 \def\CF_chemfigc#1{% #1 est le code de la molécule
1064 \ifnum\CF_lastaction=3
1065 \ifCF_in_cycle
1066 \def\CF_defaultangle{0}%
1067 \else
1068 \ifnum\CF_cnt_cyclebonds=0 % si c'est le début d'un cycle
1069 \pgfmathsetmacro\CF_defaultangle{\CF_previousangle+180+\CF_cycleanglecorrection}% on met la liaison à +180° + correction
1070 \else
1071 \pgfmathsetmacro\CF_defaultangle{\CF_previousangle-90+180/\CF_cyclenum}% sinon à la bissectrice du sommet du cycle
1072 \fi
1073 \fi
1074 \let\CF_defaultstringangle\empty
1075 \fi
1076 \let\CF_currentangle\CF_defaultangle
1077 \def\CF_molecule{#1}%
1078 \CF_expsecond\CF_searchsubmol\CF_molecule\CF_molecule% alias en premier ?
1079 \if[\CF_threeea\noexpand\expandafter\CF_firsttonil\CF_molecule\_nil
1080 \expandafter\CF_analyseoptarg\CF_molecule\_nil\CF_molecule
1081 \CF_expsecond\CF_setbondangle{\CF_currentstringangle}\CF_currentangle
1082 \let\CF_defaultangle\CF_currentangle
1083 \let\CF_previousangle\CF_currentangle
1084 \CF_doifnotempty\CF_currentstringangle{\let\CF_defaultangle\CF_currentangle}%
1085 \CF_doifnotempty\CF_currentlength {\let\CF_defaultlength\CF_currentlength}%
1086 \CF_doifnotempty\CF_currentfromatom {\let\CF_defaultfromatom\CF_currentfromatom}%
1087 \CF_doifnotempty\CF_currenttoatom {\let\CF_defaulttoatom\CF_currenttoatom}%
1088 \CF_doifnotempty\CF_currenttikz {\let\CF_defaulttikz\CF_currenttikz}%
1089 \CF_expsecond\CF_searchsubmol\CF_molecule\CF_molecule
1090 \fi
1091 \edef\CF_defaultstringangle{:\CF_defaultangle}%
1092 \let\CF_currentlength\CF_defaultlength
1093 \let\CF_currentfromatom\CF_defaultfromatom
1094 \let\CF_currenttoatom\CF_defaulttoatom
1095 \let\CF_currenttikz\CF_defaulttikz
1096 \ifCF_in_cycle% si on commence un cycle
1097 \let\CF_currentangle\CF_previousangle
1098 \pgfmathsetmacro\CF_cycle_arcinitangle{\CF_currentangle+\CF_initcycleangle+180/\CF_cyclenum+90}%
1099 \pgfmathsetmacro\CF_centeroffset{\CF_currentlength*\CF_atomsep/(2*sin(180/\CF_cyclenum))}%
1100 \node[at=(\CF_bondoutnode),shift=(\CF_cycle_arcinitangle:\CF_centeroffset pt),anchor=center](cyclecenter\number\CF_cnt_cycle){};% le centre du cycle
1101 \ifboolKV[chemfig]{show cntcycle}
1102 {%
1103 \node[at=(cyclecenter\number\CF_cnt_cycle),anchor=center,overlay]{\tiny\number\CF_cnt_cycle};%
1104 }
1105 {}%
1106 \ifCF_cycle_arc% on doit tracer l'arc de cercle dans le cycle ?
1107 \pgfmathsetmacro\CF_cycle_arcradius{\CF_cycleradiuscoeff*\CF_currentlength*\CF_atomsep/(2*tan(180/\CF_cyclenum))}%
1108 \node[at=(cyclecenter\number\CF_cnt_cycle),shift=(\CF_cycle_arcstartangle:\CF_cycle_arcradius pt)](initarc){};% le début de l'arc
1109 \CF_expafter{\draw[}\CF_cycle_arcdirecttikz](initarc) arc (\CF_cycle_arcstartangle:\CF_cycle_arcendangle:\CF_cycle_arcradius pt);%
1110 \fi
1111 \else
1112 \let\CF_currentangle\CF_defaultangle
1113 \fi
1114 \ifnum\CF_lastaction=0
1115 \let\CF_previousangle\CF_defaultangle
1116 \node(CF_node){};
1117 \CF_expsecond\CF_iffirsttokin{\CF_molecule}{-=(*~?<>}%
1118 {%
1119 \CF_insertemptygroup\CF_molecule
1120 }%
1121 {}%
1122 \fi
1123 \CF_chemfigd
1124 }
1125
1126 \def\CF_chemfigd{%
1127 \let\CF_nextaction\CF_chemfigd% à priori, on reboucle
1128 \CF_ifx\CF_molecule\empty
1129 {%
1130 \let\CF_nextaction\endgroup
1131 }
1132 {%
1133 \CF_expsecond\CF_searchnode{\CF_molecule}\CF_currentatomgroup\CF_molecule
1134 \CF_ifx\empty\CF_currentatomgroup% pas de noeud pour commencer ?
1135 {%
1136 \def\CF_bondoutnode{%
1137 n\CF_lastgroupnumber-%
1138 \ifx\CF_currentfromatom\empty
1139 \ifdim\CF_currentangle pt<90pt
1140 \number\CF_cnt_atomgroup
1141 \else
1142 \ifdim\CF_currentangle pt>270pt
1143 \number\CF_cnt_atomgroup
1144 \else
1145 1%
1146 \fi
1147 \fi
1148 \else
1149 \CF_currentfromatom
1150 \fi
1151 }%
1152 \CF_expafter{\futurelet\CF_toksa\CF_gobtonil}{\CF_molecule\relax\_nil}%
1153 \CF_iffirsttokina{-=<>~}% la suite est une liaison
1154 {%
1155 \ifnum\CF_lastaction=2 % c'est la deuxième liaison consécutive ?
1156 \CF_insertemptygroup\CF_molecule% insère un groupe vide
1157 \edef\CF_bondoutnode{\CF_bondoutnode}%
1158 \else
1159 \ifCF_in_cycle
1160 \advance\CF_cnt_cyclebonds1
1161 \fi
1162 \CF_expsecond\CF_analysebond{\CF_molecule}\CF_bondtype
1163 \edef\CF_bondoutnode{\CF_bondoutnode}%
1164 \let\CF_molecule\CF_remainafterbond
1165 \ifCF_in_cycle
1166 \ifnum\CF_cnt_cyclebonds=\CF_cyclenum\relax
1167 \CF_threeea\CF_execfirst
1168 \else
1169 \ifnum\CF_cnt_cyclebonds=1
1170 \let\CF_cyclefirsttikz\CF_currenttikz
1171 \CF_doifnotempty\CF_startoffset{\let\CF_cyclejoinlast\CF_zero}%
1172 \fi
1173 \CF_threeea\CF_execsecond
1174 \fi
1175 \else
1176 \expandafter\CF_execsecond
1177 \fi
1178 {%
1179 \let\CF_nextaction\endgroup
1180 \CF_drawbond\CF_bondtype{\CF_bondoutnode}{\CF_hookcycle}\CF_previousatomgroup\CF_hookatomgroup
1181 }%
1182 {%
1183 \node[at=(\CF_bondoutnode\ifCF_in_cycle\else\ifCF_macro_fixed_bond_length.\CF_currentangle\fi\fi),shift=(\ifcase\CF_flipstate\or180-\or-\fi\CF_currentangle:\CF_currentlength*\CF_atomsep)](CF_node){};
1184 \let\CF_previousangle\CF_currentangle
1185 \def\CF_lastaction{2}% on a tracé une liaison
1186 }%
1187 \fi
1188 \ifcat\relax\detokenize\expandafter{\romannumeral-`\.\expandafter\noexpand\CF_molecule}\relax
1189 % s'il ne reste plus rien après la liaison (sans tenir compte de l'espace devant)-> insère un groupe vide
1190 \CF_insertemptygroup\CF_molecule
1191 \fi
1192 }%
1193 {%
1194 \edef\CF_bondoutnode{\CF_bondoutnode}% évalue le l'atome de départ de liaison
1195 \CF_ifx(\CF_toksa% une parenthèse pour commencer ?
1196 {%
1197 \ifnum\CF_lastaction=2 % il y avait une liaison juste avant ?
1198 \CF_insertemptygroup\CF_molecule
1199 \else
1200 \CF_expsecond\CF_grabsubmol{\CF_molecule}%
1201 \begingroup
1202 \ifCF_in_cycle\def\CF_lastaction{3}\fi% on était dans un cycle
1203 \CF_in_cyclefalse
1204 \aftergroup\CF_chemfigd
1205 \def\CF_nextaction{\CF_expsecond\CF_chemfigc{\CF_molinparen}}%
1206 \fi
1207 }%
1208 {%
1209 \CF_ifx\CF_molecule\empty
1210 {%
1211 \let\CF_nextaction\endgroup
1212 }
1213 {% ce qui reste après le noeud courant n'est pas vide, ne commence pas par "-=~", ni par une parenthèse
1214 \CF_ifx*\CF_toksa% un cycle ?
1215 {%
1216 \ifnum\CF_lastaction=2
1217 \def\CF_currentfromatom{1}% Bugfix 1.6d
1218 \CF_insertemptygroup\CF_molecule% insère un groupe vide
1219 \else
1220 \ifCF_in_cycle
1221 \def\CF_lastaction{3}%
1222 \fi% on était dans un cycle
1223 \ifnum\CF_lastaction=3
1224 \let\CF_lastcyclenum\CF_cyclenum
1225 \fi
1226 \CF_eexpsecond\CF_iffirsttokmatch{\expandafter\CF_gobarg\CF_molecule}*%
1227 {%
1228 \CF_eexpsecond{\def\CF_molecule}{\expandafter\CF_gobarg\CF_molecule}% enlève la 1er étoile
1229 \CF_eexpsecond\CF_iffirsttokmatch{\expandafter\CF_gobarg\CF_molecule}[% un crochet ensuite ?
1230 {%
1231 \expandafter\CF_parsecyclepreamblewithoptarg\CF_molecule\_nil% \begingroup inclus
1232 }%
1233 {%
1234 \def\CF_cycle_arcstartangle{0}%
1235 \def\CF_cycle_arcendangle{360}%
1236 \let\CF_cycle_arcdirecttikz\empty
1237 \expandafter\CF_parsecyclepreamble\CF_molecule\_nil% \begingroup inclus
1238 }%
1239 \CF_cycle_arctrue
1240 }%
1241 {%
1242 \expandafter\CF_parsecyclepreamble\CF_molecule\_nil% \begingroup inclus
1243 \CF_cycle_arcfalse
1244 }%
1245 \CF_cnt_cyclebonds0
1246 \edef\CF_hookcycle{\CF_bondoutnode}%
1247 \let\CF_hookatomgroup\CF_previousatomgroup
1248 \CF_ifnum{\CF_previousatomgroup_nodim=0 }% bugfix v1.71
1249 {%
1250 \def\CF_cyclejoinlast{1}% joindre le dernier
1251 }%
1252 {%
1253 \def\CF_cyclejoinlast{0}%
1254 }%
1255 \CF_in_cycletrue
1256 \global\advance\CF_cnt_cycle1
1257 \CF_ifnum{\CF_lastaction=3 }
1258 {%
1259 \pgfmathsetmacro\CF_initcycleangle{360/\CF_lastcyclenum-180}% c'est un cycle dans un cycle
1260 }
1261 {%
1262 \pgfmathsetmacro\CF_initcycleangle{-180/\CF_cyclenum-90+\CF_cycleanglecorrection}%
1263 }
1264 \aftergroup\CF_chemfigd
1265 \def\CF_nextaction{\CF_expsecond\CF_chemfigc{\CF_molinparen}}%
1266 \fi
1267 }%
1268 {%
1269 \CF_error{something went wrong here: \detokenize\expandafter{\CF_molecule}^^JIf you think it's a bug, please, send a Minimal Example to the author}%
1270 }%
1271 }%
1272 }%
1273 }%
1274 }%
1275 {%
1276 \CF_expthreemacroargs\CF_drawatomgroup\CF_currentangle\CF_currenttoatom\CF_currentatomgroup
1277 }%
1278 }%
1279 \CF_nextaction
1280 }
1281
1282 \def\CF_parsecyclepreamble*#1#2\_nil{%
1283 \ifnum#1<3
1284 \CF_error{a cycle must be at least a triangle.^^JThe number following "*" must be 3 or more}%
1285 \fi
1286 \def\CF_molecule{#2}%
1287 \CF_expsecond\CF_grabsubmol{\CF_molecule}%
1288 \begingroup
1289 \def\CF_cyclenum{#1}%
1290 }
1291
1292 \def\CF_parsecyclepreamblewithoptarg*[#1]#2#3\_nil{%
1293 \CF_cycleparseoptarg#1,\empty,\empty,\empty\_nil
1294 \CF_parsecyclepreamble*#2#3\_nil
1295 }
1296
1297 \def\CF_cycleparseoptarg#1,#2,#3\_nil{%
1298 \CF_ifempty{#1}
1299 {%
1300 \def\CF_cycle_arcstartangle{0}%
1301 }
1302 {%
1303 \def\CF_cycle_arcstartangle{#1}%
1304 }%
1305 \CF_ifempty{#2}
1306 {%
1307 \def\CF_cycle_arcendangle{360}%
1308 }
1309 {%
1310 \def\CF_cycle_arcendangle{#2}%
1311 }%
1312 \CF_expsecond{\def\CF_cycle_arcdirecttikz}{\CF_sanitizelastitem#3,\empty\_nil}%
1313 }
1314
1315 \def\CF_grabsubmol#1{%
1316 \begingroup
1317 \catcode`(1 \catcode`)2
1318 \CF_threeea
1319 \endgroup
1320 \expandafter\CF_grabsubmola\scantokens{\relax#1}%
1321 }
1322
1323 \def\CF_grabsubmola#1\_nil{%
1324 \expandafter\CF_assigntonil\expandafter\CF_molecule\scantokens\CF_threeea{\expandafter\CF_gobarg \CF_gobarg#1}%
1325 \expandafter\CF_assigntonil\expandafter\CF_molinparen\scantokens\CF_threeea{\expandafter\CF_firsttonil\CF_gobarg#1\_nil}%
1326 }
1327
1328 \def\CF_ifcarisupperletter#1{%
1329 \ifcat\relax\noexpand#1%
1330 \let\CF_next\CF_execsecond% faux si c'est une sc
1331 \else
1332 \ifnum`#1<`A
1333 \let\CF_next\CF_execsecond
1334 \else
1335 \ifnum`#1>`Z
1336 \let\CF_next\CF_execsecond
1337 \else
1338 \let\CF_next\CF_execfirst
1339 \fi
1340 \fi
1341 \fi
1342 \CF_next
1343 }
1344
1345 % Créé 4 noeuds au dessus et au dessous des noeuds #1 et #2
1346 % à une distance de #3 du noeud #1 et #4 du noeud #2
1347 \def\CF_createnormnodes#1#2#3#4{%
1348 \CF_doifnotempty{#3}
1349 {%
1350 \node[shape=coordinate,at=(#1),xshift=#3*\CF_normx,yshift=#3*\CF_normy](#11){};%
1351 \node[shape=coordinate,at=(#1),xshift=-#3*\CF_normx,yshift=-#3*\CF_normy](#12){};%
1352 }%
1353 \CF_doifnotempty{#4}
1354 {%
1355 \node[shape=coordinate,at=(#2),xshift=#4*\CF_normx,yshift=#4*\CF_normy](#21){};%
1356 \node[shape=coordinate,at=(#2),xshift=-#4*\CF_normx,yshift=-#4*\CF_normy](#22){};%
1357 }%
1358 }
1359
1360 \def\CF_distancebetweenpoints#1#2#3#4#5{%
1361 \pgfextractx\CF_dim{\pgfpointanchor{#1}{#2}}\edef\CF_dimax{\the\CF_dim}%
1362 \pgfextracty\CF_dim{\pgfpointanchor{#1}{#2}}\edef\CF_dimay{\the\CF_dim}%
1363 \pgfextractx\CF_dim{\pgfpointanchor{#3}{#4}}\edef\CF_dimbx{\the\CF_dim}%
1364 \pgfextracty\CF_dim{\pgfpointanchor{#3}{#4}}\edef\CF_dimby{\the\CF_dim}%
1365 \pgfmathsetmacro#5{veclen(\CF_dimbx-\CF_dimax,\CF_dimby-\CF_dimay)}%
1366 }
1367
1368 \def\CF_computenodevect#1#2{%
1369 \CF_distancebetweenpoints{#1}{center}{#2}{center}\CF_vectorlen
1370 \pgfmathsetmacro\CF_normx{(\CF_dimay-\CF_dimby)/\CF_vectorlen}%
1371 \pgfmathsetmacro\CF_normy{(\CF_dimbx-\CF_dimax)/\CF_vectorlen}%
1372 }
1373
1374 \def\CF_ifzerodistance#1#2#3#4{% #1=nom du noeud 1 #2=ancre du noeud 1 #3=nom noeud 2 #4=ancre noeud 2 T-> si distance nulle F->sinon
1375 \pgfextractx\CF_dim{\pgfpointanchor{#3}{#4}}\edef\CF_dimax{\the\CF_dim}%
1376 \pgfextracty\CF_dim{\pgfpointanchor{#3}{#4}}\edef\CF_dimay{\the\CF_dim}%
1377 \pgfextractx\CF_dim{\pgfpointanchor{#1}{#2}}\edef\CF_dimbx{\the\CF_dim}%
1378 \pgfextracty\CF_dim{\pgfpointanchor{#1}{#2}}\edef\CF_dimby{\the\CF_dim}%
1379 \CF_ifnum{0\ifdim\CF_dimax=\CF_dimbx\space1\fi\ifdim\CF_dimay=\CF_dimby\space1\fi=11 }
1380 }
1381
1382 \def\CF_setoffset#1#2{% #1=macro recevant le résultat #2= nom du noeud bugfix 1.71
1383 \CF_doifempty#1%
1384 {%
1385 \CF_ifzerodistance{#2}{south west}{#2}{north east}% si noeud de dimension nulle
1386 {%
1387 \def#1{0pt}%
1388 }
1389 {%
1390 \edef#1{\CF_bondoffset}%
1391 }%
1392 }%
1393 }
1394
1395 \def\CF_drawbond#1#2#3#4#5{% #1=type de liaison #2 et #3:nom de noeuds de début et fin #4 et #5: sc contenant les atomes de débutet fin
1396 \CF_setoffset\CF_startoffset{#2}%
1397 \CF_setoffset\CF_endoffset{#3}%
1398 \let\CF_currentbondstyle\CF_bondstyle
1399 \CF_doifnotempty\CF_currenttikz
1400 {%
1401 \CF_eaddtomacro\CF_currentbondstyle{\expandafter,\CF_currenttikz}%
1402 }%
1403 \path(#2)--(#3)coordinate[pos=0](#2@)coordinate[pos=1](#3@);%
1404 \CF_computenodevect{#2@}{#3@}%
1405 \pgfmathsetmacro\CF_startcoeff{\CF_startoffset/\CF_vectorlen}%
1406 \pgfmathsetmacro\CF_endcoeff{1-\CF_endoffset/\CF_vectorlen}%
1407 \path(#2@)--(#3@)coordinate[pos=\CF_startcoeff](#2@@)coordinate[pos=\CF_endcoeff](#3@@);%
1408 \CF_doifnotempty\CF_movebondname% on doit poser un noeud sur la liaison
1409 {%
1410 \path(#2@@)--(#3@@)coordinate[overlay,pos=\CF_movebondcoeff](\CF_movebondname);
1411 \let\CF_movebondname\empty
1412 }%
1413 \ifcase#1\relax
1414 \CF_error{unknown bond type, this error should not occur^^JIf you think it's a bug, send a Minimal Example to the author}%
1415 \or% 1 = liaison simple
1416 \ifboolKV[chemfig]{bond join}% nouveau v1.66
1417 {%
1418 \scope
1419 \expandafter\tikzset\expandafter{\CF_currentbondstyle}%
1420 \ifnum\CF_previousbondtype=5
1421 \ifnum0\ifdim\CF_startoffset=0pt 1\fi\ifdim\CF_previous_offset=0pt 1\fi=11
1422 \CF_ifnum{\CF_previousatomgroup_nodim=1 }% bugfix 1.71
1423 {%
1424 \CF_turnangle=\CF_compute_turnangle{\CF_previousbondangle}{\CF_currentangle}%
1425 \pgfmathsetmacro\CF_cram_overlap{\CF_crambasewidth*cos(\CF_turnangle)-\pgflinewidth}%
1426 \ifdim\CF_cram_overlap pt>0pt
1427 \CF_warning{Cram base too wide to join}%
1428 \else
1429 \ifdim\CF_turnangle>0pt % si on tourne à gauche
1430 \fill(#2@@)--(\CF_previousnode@@2)--([shift=(\CF_currentangle-90:\pgflinewidth/2)]#2@@)--cycle;
1431 \else
1432 \fill(#2@@)--(\CF_previousnode@@1)--([shift=(\CF_currentangle+90:\pgflinewidth/2)]#2@@)--cycle;
1433 \fi
1434 \fi
1435 }
1436 {}%
1437 \fi
1438 \fi
1439 \expandafter
1440 \endscope
1441 \expanded{\def\noexpand\CF_simplebondwidth{\the\dimexpr\pgflinewidth}}% récupère l'épaisseur de ligne si une liaison ">" est à suivre
1442 }
1443 {}%
1444 \CF_drawaxisbond{#2}{#3}% trace la liaison simple dans l'axe
1445 \or% 2 = liaison double
1446 \ifCF_in_cycle
1447 \ifnum\CF_doublebondtype=0
1448 \def\CF_doublebondtype{1}%
1449 \fi
1450 \ifnum\CF_flipstate>0
1451 \def\CF_doublebondtype{2}%
1452 \fi
1453 \pgfmathsetmacro\CF_doublebondlengthcorrection{\CF_doublesep*tan(180/\CF_cyclenum)}%
1454 \fi
1455 \ifcase\CF_doublebondtype
1456 \CF_createnormnodes{#2@@}{#3@@}{\CF_doublesep/2}{\CF_doublesep/2}%
1457 \CF_drawbonda(#2@@1)--(#3@@1);
1458 \CF_drawbonda(#2@@2)--(#3@@2);
1459 \let\CF_joinbond\CF_zero
1460 \or
1461 \CF_createnormnodes{#2@@}{#3@@}\CF_doublesep\CF_doublesep
1462 \CF_drawaxisbond{#2}{#3}% trace la liaison simple dans l'axe\CF_drawbonda(#2@@)--(#3@@);
1463 \begingroup% ajuste éventuellement les longueurs des liaisons doubles
1464 \ifCF_in_cycle
1465 \ifdim\CF_startoffset=0pt
1466 \CF_edefaddtomacro\CF_currentbondstyle{,shorten <=\CF_doublebondlengthcorrection pt}%
1467 \fi
1468 \ifdim\CF_endoffset=0pt
1469 \CF_edefaddtomacro\CF_currentbondstyle{,shorten >=\CF_doublebondlengthcorrection pt}%
1470 \fi
1471 \fi
1472 \CF_drawbonda(#2@@1)--(#3@@1);
1473 \endgroup
1474 \or
1475 \CF_createnormnodes{#2@@}{#3@@}\CF_doublesep\CF_doublesep
1476 \CF_drawaxisbond{#2}{#3}% trace la liaison simple dans l'axe\CF_drawbonda(#2@@)--(#3@@);
1477 \begingroup% ajuste éventuellement les longueurs des liaisons doubles
1478 \ifCF_in_cycle
1479 \ifdim\CF_startoffset=0pt
1480 \CF_edefaddtomacro\CF_currentbondstyle{,shorten \ifnum\CF_flipstate=0 <=-\else>=\fi\CF_doublebondlengthcorrection pt}%
1481 \fi
1482 \ifdim\CF_endoffset=0pt
1483 \CF_edefaddtomacro\CF_currentbondstyle{,shorten \ifnum\CF_flipstate=0 >=-\else<=\fi\CF_doublebondlengthcorrection pt}%
1484 \fi
1485 \fi
1486 \CF_drawbonda(#2@@2)--(#3@@2);
1487 \endgroup
1488 \fi
1489 \or% 3 = liaison triple
1490 \CF_createnormnodes{#2@@}{#3@@}\CF_doublesep\CF_doublesep
1491 \CF_drawaxisbond{#2}{#3}% trace la liaison simple dans l'axe\CF_drawbonda(#2@@)--(#3@@);
1492 \CF_drawbonda(#2@@1)--(#3@@1);
1493 \CF_drawbonda(#2@@2)--(#3@@2);
1494 \or% 4 = liaison Cram pleine de #2 vers #3 : >
1495 \CF_createnormnodes{#2@@}{#3@@}{\CF_crambasewidth/2}{\pgflinewidth/2}%
1496 \CF_ifnum{\CF_previousatomgroup_nodim=1 }% bugfix 1.71
1497 {%
1498 \ifnum\ifboolKV[chemfig]{bond join}10\ifdim\CF_startoffset=0pt 1\fi\ifdim\CF_previous_offset=0pt 1\fi=111
1499 \ifnum\CF_previousbondtype=1
1500 \CF_turnangle=\CF_compute_turnangle{\CF_previousbondangle}{\CF_currentangle}%
1501 \pgfmathsetmacro\CF_cram_overlap{\CF_crambasewidth*cos(\CF_turnangle)-\CF_simplebondwidth}%
1502 \ifdim\CF_cram_overlap pt>0pt
1503 \CF_warning{Cram base too wide to join}%
1504 \else
1505 \CF_expafter{\fill[}\CF_currentbondstyle](#2@@1)--([shift=(\CF_previousbondangle\ifdim\CF_turnangle>0pt -\else+\fi90:\CF_simplebondwidth/2)]\CF_previousnode@@)--(#2@@2)--cycle;%
1506 \fi
1507 \else
1508 \ifnum\CF_previousbondtype=5
1509 \CF_turnangle=\CF_compute_turnangle{\CF_previousbondangle}{\CF_currentangle}%
1510 \CF_expafter{\fill[}\CF_currentbondstyle](#2@@1)--([shift=(\CF_previousbondangle\ifdim\CF_turnangle>0pt -\else+\fi90:\CF_crambasewidth/2)]\CF_previousnode@@)--(#2@@2)--cycle;%
1511 \fi
1512 \fi
1513 \fi
1514 }
1515 {}%
1516 \ifboolKV[chemfig]{bond join}
1517 {\CF_expafter{\fill[}}% pas de contour si liaisons jointes
1518 {\CF_expafter{\filldraw[}}
1519 \CF_currentbondstyle](#2@@1)--(#2@@2)--(#3@@2)--(#3@@1)--cycle;
1520 \let\CF_joinbond\CF_zero
1521 \or% 5 = liaison Cram pleine de #2 vers #3 : <
1522 \CF_createnormnodes{#3@@}{#2@@}{\CF_crambasewidth/2}{\pgflinewidth/2}%
1523 \ifboolKV[chemfig]{bond join}
1524 {\CF_expafter{\fill[}}% pas de contour si liaisons jointes
1525 {\CF_expafter{\filldraw[}}
1526 \CF_currentbondstyle](#2@@2)--(#2@@1)--(#3@@1)--(#3@@2)--cycle;
1527 \let\CF_joinbond\CF_zero
1528 \or% 6 = liaison Cram pointillée de #2 vers #3
1529 \scope
1530 \CF_createnormnodes{#2@@}{#3@@}{\CF_crambasewidth/2}{}%
1531 \CF_clipcramornot(#2@@1)--(#2@@2)--(#3@@)--(#2@@1);
1532 \CF_expafter{\draw[}\CF_currentbondstyle,dash pattern=on \CF_cramdashlength off \CF_cramdashsep,line width=\CF_crambasewidth](#2@@)--(#3@@);
1533 \endscope
1534 \let\CF_joinbond\CF_zero
1535 \or% 7 = liaison Cram pointillée de #3 vers #2
1536 \scope
1537 \CF_createnormnodes{#3@@}{#2@@}{\CF_crambasewidth/2}{}%
1538 \CF_clipcramornot(#3@@1)--(#3@@2)--(#2@@)--(#3@@1);
1539 \CF_expafter{\draw[}\CF_currentbondstyle,dash pattern=on \CF_cramdashlength off \CF_cramdashsep,line width=\CF_crambasewidth](#3@@)--(#2@@);
1540 \endscope
1541 \let\CF_joinbond\CF_zero
1542 \or% 8 = liaison cram rectangle évidé de #2 vers #3
1543 \CF_createnormnodes{#2@@}{#3@@}{\CF_crambasewidth/2}{}%
1544 \CF_expafter{\draw[}\CF_currentbondstyle,line join=bevel](#2@@1)--(#2@@2)--(#3@@)--cycle;
1545 \let\CF_joinbond\CF_zero
1546 \or% 9 = liaison cram rectangle évidé de #3 vers #1
1547 \CF_createnormnodes{#3@@}{#2@@}{\CF_crambasewidth/2}{}%
1548 \CF_expafter{\draw[}\CF_currentbondstyle,line join=bevel](#3@@1)--(#3@@2)--(#2@@)--cycle;
1549 \let\CF_joinbond\CF_zero
1550 \else
1551 \CF_error{unknown bond type, this error should not occur^^JIf you think it's a bug, send a Minimal Example to the author}%
1552 \fi
1553 \let\CF_startoffset\empty
1554 \let\CF_previous_offset\CF_endoffset
1555 \let\CF_endoffset\empty
1556 \let\CF_previoustikz\CF_currenttikz
1557 \let\CF_previousbondangle\CF_previousangle
1558 \edef\CF_previousnode{#3}%
1559 }
1560
1561 \def\CF_compute_turnangle#1#2{%
1562 \expandafter\CF_compute_turnangle_a\the\dimexpr #2pt-#1pt\relax\_nil
1563 }
1564 \def\CF_compute_turnangle_a#1\_nil{%
1565 \dimexpr#1
1566 \ifdim#1<-180pt +360pt\else
1567 \ifdim#1>180pt -360pt\fi\fi\relax
1568 }
1569
1570 \def\CF_drawaxisbondnojoin#1#2{\CF_drawbonda(#1@@)--(#2@@);}
1571
1572 \def\CF_drawaxisbondjoin#1#2{% dessine une liaison simple dans l'axe avec raccord rétrograde
1573 \ifCF_in_cycle\ifnum\CF_cnt_cyclebonds=\CF_cyclenum\relax
1574 \let\CF_nexttikz\CF_cyclefirsttikz
1575 \fi\fi
1576 \ifnum\CF_joinbond=0
1577 \ifCF_in_cycle
1578 \ifnum\CF_cnt_cyclebonds=\CF_cyclenum\relax
1579 \ifnum\CF_cyclejoinlast=1
1580 \CF_drawbonda(#1@@)--(#2@@)--%
1581 ([shift=(\CF_previousbondangle+2*\CF_cycleincrementangle:.5\pgflinewidth)]#2@@);
1582 \else
1583 \CF_drawbonda(#1@@)--(#2@@);
1584 \fi
1585 \else
1586 \CF_drawbonda(#1@@)--(#2@@);
1587 \fi
1588 \else
1589 \CF_drawbonda(#1@@)--(#2@@);
1590 \fi
1591 \def\CF_joinbond{1}%
1592 \else
1593 \CF_ifx\CF_previoustikz\CF_currenttikz
1594 {%
1595 \def\CF_joinbond{1}%
1596 \CF_ifnum{\CF_previousatomgroup_nodim=1 }% bugfix 1.71
1597 {%
1598 \CF_ifx\CF_previousbondangle\empty% si début molécule
1599 {%
1600 \CF_drawbonda(#1@@)--(#2@@);
1601 }
1602 {%
1603 \ifdim\CF_startoffset=0pt
1604 \ifCF_in_cycle
1605 \ifnum\CF_cnt_cyclebonds=\CF_cyclenum\relax
1606 \ifnum\CF_cyclejoinlast=1
1607 \CF_ifx\CF_cyclefirsttikz\CF_currenttikz
1608 {%
1609 \CF_drawbonda([shift=(\CF_previousbondangle:-.5\pgflinewidth)]#1@@)--(#1@@)--(#2@@)--([shift=(\CF_previousbondangle+2*\CF_cycleincrementangle:.5\pgflinewidth)]#2@@);
1610 }
1611 {%
1612 \CF_drawbonda([shift=(\CF_previousbondangle:-.5\pgflinewidth)]#1@@)--(#1@@)--(#2@@);
1613 }%
1614 \else
1615 \CF_drawbonda([shift=(\CF_previousbondangle:-.5\pgflinewidth)]#1@@)--(#1@@)--(#2@@);
1616 \fi
1617 \else
1618 \CF_drawbonda([shift=(\CF_previousbondangle:-.5\pgflinewidth)]#1@@)--(#1@@)--(#2@@);
1619 \fi
1620 \else
1621 \CF_drawbonda([shift=(\CF_previousbondangle:-.5\pgflinewidth)]#1@@)--(#1@@)--(#2@@);
1622 \fi
1623 \else
1624 \CF_drawbonda(#1@@)--(#2@@);
1625 \fi
1626 }%
1627 }
1628 {%
1629 \CF_drawbonda(#1@@)--(#2@@);%
1630 }%
1631 }
1632 {%
1633 \ifCF_in_cycle
1634 \ifnum\CF_cnt_cyclebonds=\CF_cyclenum\relax
1635 \ifnum\CF_cyclejoinlast=1
1636 \CF_ifx\CF_nexttikz\CF_currenttikz
1637 {%
1638 \CF_drawbonda(#1@@)--(#2@@)--([shift=(\CF_previousbondangle+2*\CF_cycleincrementangle:.5\pgflinewidth)]#2@@);%
1639 }%
1640 {%
1641 \CF_drawbonda(#1@@)--(#2@@);%
1642 }%
1643 \else
1644 \CF_drawbonda(#1@@)--(#2@@);
1645 \fi
1646 \else
1647 \CF_drawbonda(#1@@)--(#2@@);
1648 \fi
1649 \else
1650 \CF_drawbonda(#1@@)--(#2@@);%
1651 \fi
1652 }%
1653 \fi
1654 \ifdim\CF_endoffset=0pt \else
1655 \let\CF_joinbond\CF_zero
1656 \fi
1657 }
1658
1659 \def\CF_drawbonda{\CF_expafter{\draw[}\CF_currentbondstyle]}
1660
1661 \def\CF_drawallhooks{% dessine tous les crochets contenus dans la sc \CF_hookdraw
1662 \CF_doifnotempty\CF_hookdrawlist
1663 {%
1664 \expandafter\CF_drawfirsthook\CF_hookdrawlist\_nil% trace un lien de crochet à crochet
1665 \CF_drawallhooks
1666 }%
1667 }
1668
1669 \def\CF_drawfirsthook[#1,#2,#3]#4#5#6#7#8\_nil{%
1670 \def\CF_hookdrawlist{#8}%
1671 \begingroup
1672 \let\CF_joinbond\CF_zero
1673 \def\CF_currenttikz{#3}%
1674 \def\CF_hookstartcontent{#6}%
1675 \def\CF_hookendcontent{#7}%
1676 \CF_ifinteger{#2}%
1677 {%
1678 \CF_drawbond{#2}{#4}{#5}\CF_hookstartcontent\CF_hookendcontent
1679 }%
1680 {%
1681 \CF_assignbondcode{#2}\CF_bondcurrentnum
1682 \CF_drawbond\CF_bondcurrentnum{#4}{#5}\CF_hookstartcontent\CF_hookendcontent
1683 }%
1684 \endgroup
1685 }
1686
1687 \def\CF_extractatom#1-#2\_nil{#2}% transforme le bound@outnode en n° de l'atome
1688
1689 \def\CF_gobblemovearg @#1#2\_nil#3{%
1690 \expandafter\def\csname atom_\number\CF_cnt_atom\endcsname{#2}%
1691 \CF_ifinstr{#1},%
1692 {%
1693 \CF_analysemovearg#1\_nil#3\let\CF_movebondcoeff\empty
1694 }%
1695 {%
1696 \def#3{#1}%
1697 }%
1698 \CF_doifempty{#2}
1699 {%
1700 \let\CF_nodestrut\empty
1701 }%
1702 }%
1703
1704 \def\hflipnext{\def\CF_flipstate{1}}
1705
1706 \def\vflipnext{\def\CF_flipstate{2}}
1707 \let\CF_flipstate\CF_zero
1708
1709 \def\CF_drawatomgroup#1#2#3{% #1=angle d'arrivée de la liaison #2=numero atome sur lequel arrive la liaison #3=groupe d'atomes
1710 \expandafter\let\expandafter\CF_bondoutcontent% assigne le contenu de l'atome d'où part la liaison
1711 \csname
1712 \ifdefined\CF_bondoutnode
1713 atom_\expandafter\CF_extractatom\CF_bondoutnode\_nil
1714 \else
1715 empty%
1716 \fi
1717 \endcsname
1718 \global\advance\CF_cnt_group1
1719 \let\CF_currentatom\empty
1720 \global\let\CF_hookdrawlist\empty
1721 \CF_cnt_atomgroup0 % est le nombre d'atome dans le groupe que va calculer \CF_drawatomgroupa
1722 \CF_iffirsttokmatch{#3}?%
1723 {%
1724 \CF_drawatomgroupa{{}#3}%
1725 }
1726 {%
1727 \CF_drawatomgroupa{#3}%
1728 }%
1729 \def\CF_currentatomgroup{#3}%
1730 \CF_removemovearg\CF_currentatomgroup% enlève les "@{<nom>}"
1731 \CF_ifinstr{#3}?%
1732 {%
1733 \CF_removehook\CF_currentatomgroup
1734 \CF_expsecond\CF_stripsp\CF_currentatomgroup\CF_ifempty
1735 {%
1736 \let\CF_currentatomgroup\empty% rollback à 1.66
1737 }
1738 {}%
1739 }%
1740 {}%
1741 \CF_doifnotempty{#2}
1742 {%
1743 \ifnum#2<1
1744 \CF_warning{no atom found at position #2, pershaps you mispelled the optional argument of the bond.}%
1745 \else
1746 \ifnum#2>\CF_cnt_atomgroup
1747 \CF_error{no atom found at position #2, pershaps you mispelled the optional argument of the bond.}%
1748 \fi
1749 \fi
1750 }%
1751 \edef\CF_hookatomnumber{%
1752 \CF_ifempty{#2}
1753 {%
1754 \ifdim#1pt>90pt
1755 \ifdim#1pt<270pt
1756 \number\CF_cnt_atomgroup
1757 \else
1758 1%
1759 \fi
1760 \else
1761 1%
1762 \fi
1763 }
1764 {%
1765 #2%
1766 }%
1767 }%
1768 \CF_cnt_atom\CF_hookatomnumber
1769 \ifboolKV[chemfig]{use atom strut}% bugfix 1.71
1770 {% branche inutile si use atom strut=false
1771 \CF_ifzerodim\CF_currentatomgroup
1772 {%
1773 \let\CF_nodestrut\empty
1774 }
1775 {%
1776 \CF_ifx\empty\CF_bondoutcontentsaved
1777 {%
1778 \def\CF_nodestrut{\vphantom\CF_bondoutcontent}%
1779 }%
1780 {%
1781 \def\CF_nodestrut{\vphantom\CF_bondoutcontentsaved}%
1782 }%
1783 }%
1784 }
1785 {%
1786 \let\CF_nodestrut\empty
1787 }%
1788 \edef\CF_optstring{anchor=\ifnum\CF_lastaction=0 base\else\ifCF_in_cycle center\else\ifCF_macro_fixed_bond_length 180+#1\else center\fi\fi\fi,at=(CF_node),\CF_nodestyle}% premier atome de la molécule affiché
1789 \loop
1790 \unless\ifnum\CF_cnt_atom>\CF_cnt_atomgroup
1791 \CF_eexpafter{\futurelet\CF_toksa}{\expandafter\expandafter\expandafter\CF_gobtonil\csname atom_\number\CF_cnt_atom\endcsname\_nil}%
1792 \CF_ifx @\CF_toksa% l'atome courant commence par un "@"
1793 {%
1794 \CF_threeea\CF_gobblemovearg\csname atom_\number\CF_cnt_atom\endcsname\_nil\CF_moveatomname
1795 \CF_expafter{\node[}\CF_optstring,overlay](\CF_moveatomname){\phantom{\CF_nodecontent}};%
1796 \let\CF_moveatomname\empty
1797 }
1798 {}%
1799 \ifboolKV[chemfig]{debug}
1800 {%
1801 \CF_expafter{\node[}\CF_optstring,draw=gray](n\number\CF_cnt_group-\number\CF_cnt_atom){\CF_nodecontent};%
1802 \CF_show_debug_atom
1803 }
1804 {%
1805 \CF_expafter{\node[}\CF_optstring](n\number\CF_cnt_group-\number\CF_cnt_atom){\CF_nodecontent};%
1806 }%
1807 \let\CF_nodestrut\empty
1808 \advance\CF_cnt_atom1
1809 \edef\CF_optstring{anchor=base \ifnum\CF_flipstate=1 east\else west\fi,at=(n\number\CF_cnt_group-\number\numexpr\CF_cnt_atom-1.base \ifnum\CF_flipstate=1 west\else east\fi),\CF_nodestyle}%
1810 \repeat
1811 \CF_cnt_atom\CF_hookatomnumber
1812 \ifnum\CF_lastaction=2 % s'il faut tracer une liaison
1813 \gdef\CF_cycleanglecorrection{0}% alors c'est qu'un cycle ne peut pas commencer la molécule : annulation de la correction d'angle
1814 \CF_drawbond\CF_bondtype{\CF_bondoutnode}{n\number\CF_cnt_group-\number\CF_cnt_atom}\CF_previousatomgroup\CF_currentatomgroup
1815 \let\CF_previousbondtype\CF_bondtype
1816 \fi
1817 \def\CF_lastaction{1}% met la dernière action à 1 : affichage d'un noeud
1818 \loop
1819 \ifnum\CF_cnt_atom>1
1820 \advance\CF_cnt_atom-1
1821 \edef\CF_optstring{anchor=base \ifnum\CF_flipstate=1 west\else east\fi,at=(n\number\CF_cnt_group-\number\numexpr\CF_cnt_atom+1.base \ifnum\CF_flipstate=1 east\else west\fi),\CF_nodestyle}%
1822 \CF_eexpafter{\futurelet\CF_toksa}{\expandafter\expandafter\expandafter\CF_gobtonil\csname atom_\number\CF_cnt_atom\endcsname\_nil}%
1823 \CF_ifx @\CF_toksa% l'atome courant commence par un "@"
1824 {%
1825 \CF_threeea\CF_gobblemovearg\csname atom_\number\CF_cnt_atom\endcsname\_nil\CF_moveatomname
1826 \CF_expafter{\node[}\CF_optstring,overlay](\CF_moveatomname){\phantom{\CF_nodecontent}};%
1827 \let\CF_moveatomname\empty
1828 }
1829 {}%
1830 \ifboolKV[chemfig]{debug}
1831 {%
1832 \CF_expafter{\node[}\CF_optstring,draw=gray](n\number\CF_cnt_group-\number\CF_cnt_atom){\CF_nodecontent};%
1833 \CF_show_debug_atom
1834 }
1835 {%
1836 \CF_expafter{\node[}\CF_optstring](n\number\CF_cnt_group-\number\CF_cnt_atom){\CF_nodecontent};%
1837 }%
1838 \repeat
1839 \ifboolKV[chemfig]{debug}
1840 \CF_show_debug_atomgroup
1841 {}%
1842 \CF_drawallhooks
1843 \edef\CF_lastgroupnumber{\number\CF_cnt_group}%
1844 \let\CF_previousatomgroup\CF_currentatomgroup
1845 \CF_ifzerodistance{n\number\CF_cnt_group-1}{south west}{n\number\CF_cnt_group-\number\CF_cnt_atomgroup}{north west}% new v1.71
1846 {\def\CF_previousatomgroup_nodim{1}}
1847 {\def\CF_previousatomgroup_nodim{0}}%
1848 }
1849
1850 \def\CF_show_debug_atom{%
1851 \node[at=(n\number\CF_cnt_group-\number\CF_cnt_atom.south),anchor=north,outer sep=1pt,overlay]{$\scriptscriptstyle\color{gray}\number\CF_cnt_atom$};%
1852 }
1853
1854 \def\CF_show_debug_atomgroup{%
1855 \draw[red,overlay] ([xshift=-.5pt,yshift=.5pt]n\number\CF_cnt_group-1.north west) rectangle ([xshift=.5pt,yshift=-.5pt]n\number\CF_cnt_group-\number\CF_cnt_atomgroup.south east);%
1856 \path (n\number\CF_cnt_group-1.north west) -- (n\number\CF_cnt_group-\number\CF_cnt_atomgroup.north east)
1857 node [midway,yshift=1pt,overlay] {$\scriptscriptstyle\color{red}\number\CF_cnt_group$};% TODO : supprimer ce noeud qui ne donne aucune information utile ?
1858 }
1859
1860 \def\CF_savemovearg @#1#2\_nil{\def\CF_currentatom{@{#1}}}
1861
1862 \def\CF_drawatomgroupa#1{% transforme #1 en un groupe d'atomes
1863 \CF_ifempty{#1}
1864 {%
1865 \expandafter\let\csname atom_\number\CF_cnt_atomgroup\endcsname\CF_currentatom
1866 }
1867 {%
1868 \advance\CF_cnt_atomgroup1
1869 \futurelet\CF_toksa\CF_gobtonil#1\_nil
1870 \CF_ifx @\CF_toksa
1871 {%
1872 \CF_savemovearg#1\_nil
1873 \CF_removemovearga#1\_nil\CF_aftermovearg
1874 \CF_expsecond\CF_drawatomgroupb{\CF_aftermovearg}%
1875 }%
1876 {%
1877 \let\CF_currentatom\empty
1878 \CF_drawatomgroupb{#1}%
1879 }%
1880 }%
1881 }
1882
1883 \def\CF_drawatomgroupb#1{%
1884 \CF_ifempty{#1}
1885 {%
1886 \expandafter\let\csname atom_\number\CF_cnt_atomgroup\endcsname\CF_currentatom
1887 }
1888 {%
1889 \futurelet\CF_toksa\CF_gobtonil#1\_nil
1890 \CF_ifxcase\CF_toksa
1891 \bgroup
1892 {%
1893 \CF_eaddtomacro\CF_currentatom{\expandafter{\CF_firsttonil#1\_nil}}%
1894 \CF_expsecond\CF_drawatomgroupc{\CF_gobarg#1}%
1895 }%
1896 \CF_sptoken
1897 {%
1898 \CF_addtomacro\CF_currentatom{ }%
1899 \CF_expsecond\CF_drawatomgroupc{\CF_afterspace#1\_nil}%
1900 }%
1901 \CF_ifxcase_elseif
1902 \CF_eaddtomacro\CF_currentatom{\CF_firsttonil#1\_nil}%
1903 \CF_expsecond\CF_drawatomgroupc{\CF_gobarg#1}%
1904 \CF_ifxcase_endif
1905 }%
1906 }
1907
1908 % enlève tous les "@{nom}" de la sc #1
1909 \def\CF_removemovearg#1{%
1910 \CF_expsecond\CF_ifinstr{#1}@%
1911 {%
1912 \expandafter\CF_removemovearga#1\_nil#1%
1913 \CF_removemovearg#1%
1914 }%
1915 {}%
1916 }
1917
1918 % enlève le premier "@{<nom>}" de l'argument et l'assigne à #2
1919 \def\CF_removemovearga#1\_nil#2{%
1920 \def\CF_removemoveargb##1@{%
1921 \CF_expsecond{\def#2}{\CF_gobarg##1}% mange le \relax
1922 \CF_removemoveargc\relax
1923 }%
1924 \def\CF_removemoveargc##1\_nil{\CF_eaddtomacro#2{\CF_gobtwoargs##1}}% mange le \relax et le <nom>
1925 \CF_removemoveargb\relax#1\_nil
1926 }
1927
1928 \def\CF_drawatomgroupc#1{% transforme #1 en un groupe d'atomes
1929 \CF_ifempty{#1}
1930 {%
1931 \expandafter\let\csname atom_\number\CF_cnt_atomgroup\endcsname\CF_currentatom
1932 \let\CF_currentatom\empty
1933 }
1934 {%
1935 \futurelet\CF_toksa\CF_gobtonil#1\_nil
1936 \CF_ifx @\CF_toksa
1937 {%
1938 \expandafter\let\csname atom_\number\CF_cnt_atomgroup\endcsname\CF_currentatom
1939 \let\CF_currentatom\empty
1940 \CF_drawatomgroupa{#1}%
1941 }%
1942 {%
1943 \CF_ifx|\CF_toksa
1944 {%
1945 \expandafter\let\csname atom_\number\CF_cnt_atomgroup\endcsname\CF_currentatom
1946 \let\CF_currentatom\empty
1947 \CF_expsecond\CF_drawatomgroupa{\CF_gobarg#1}%
1948 }%
1949 {%
1950 \CF_ifx\CF_sptoken\CF_toksa
1951 {%
1952 \CF_addtomacro\CF_currentatom{ }%
1953 \CF_expsecond\CF_drawatomgroupc{\CF_afterspace#1\_nil}%
1954 }%
1955 {%
1956 \CF_ifx\bgroup\CF_toksa
1957 {%
1958 \CF_eaddtomacro\CF_currentatom{\expandafter{\CF_firsttonil#1\_nil}}%
1959 \CF_expsecond\CF_drawatomgroupc{\CF_gobarg#1}%
1960 }%
1961 {%
1962 \CF_expsecond\CF_ifcarisupperletter{\CF_firsttonil#1\_nil}%
1963 {%
1964 \expandafter\let\csname atom_\number\CF_cnt_atomgroup\endcsname\CF_currentatom
1965 \let\CF_currentatom\empty
1966 \CF_drawatomgroupa{#1}%
1967 }%
1968 {%
1969 \CF_ifx?\CF_toksa
1970 {%
1971 \CF_expsecond\CF_iffirsttokmatch{\CF_gobarg#1}[% un crochet après le "?"
1972 {%
1973 \expandafter\CF_graboptarg\CF_gobarg#1\_nil\CF_afterhook
1974 }%
1975 {%
1976 \CF_expafter{\CF_graboptarg[]}{\CF_gobarg#1}\_nil\CF_afterhook
1977 }%
1978 \CF_exptwomacroargs\CF_ifinstr{\CF_hooklist}{\expandafter(\CF_hookcurrentname)}% crochet déjà défini ?
1979 {%
1980 \CF_expsecond\CF_hookparselist{\CF_hookcurrentname}% chercher les caractéristiques du crochet sauvegardé
1981 \CF_edefaddtomacro\CF_hookdrawlist{%
1982 [\CF_hookcurrentname,\CF_hookcurrentlink,\CF_hookcurrenttikz]{\CF_hooksavedcoord}{n\number\CF_cnt_group-\number\CF_cnt_atomgroup}}%
1983 \CF_eaddtomacro\CF_hookdrawlist{\expandafter{\CF_hooksavedcontent}}%
1984 \CF_eaddtomacro\CF_hookdrawlist{\expandafter{\CF_currentatom}}% ajoute les 4 arguments à la liste des crochets à tracer
1985 \global\let\CF_hookdrawlist\CF_hookdrawlist
1986 }%
1987 {%
1988 \CF_edefaddtomacro\CF_hooklist{(\CF_hookcurrentname)|n\number\CF_cnt_group-\number\CF_cnt_atomgroup|}%
1989 \CF_eaddtomacro\CF_hooklist{\CF_currentatom|}%
1990 \global\let\CF_hooklist\CF_hooklist
1991 }%
1992 \CF_expsecond\CF_drawatomgroupc{\CF_afterhook}%
1993 }%
1994 {%
1995 \CF_eaddtomacro\CF_currentatom{\CF_firsttonil#1\_nil}%
1996 \CF_expsecond\CF_drawatomgroupc{\CF_gobarg#1}%
1997 }%
1998 }%
1999 }%
2000 }%
2001 }%
2002 }%
2003 }%
2004 }
2005
2006 \def\CF_kookdefaultname{a}
2007 \def\CF_hookdefaultlink{-}
2008 \def\CF_hookdefaulttikz{}
2009
2010 \def\CF_hookparseoptarg#1,#2,#3\_nil{%
2011 \CF_testemptyandassign\CF_hookcurrentname{#1}\CF_kookdefaultname
2012 \CF_testemptyandassign\CF_hookcurrentlink{#2}\CF_hookdefaultlink
2013 \CF_testemptyandassign\CF_hookcurrenttikz{#3}\CF_hookdefaulttikz
2014 }
2015
2016 \def\CF_graboptarg[#1]#2\_nil#3{%
2017 \CF_hookparseoptarg#1,,\_nil
2018 \def#3{#2}%
2019 }
2020
2021 \def\CF_hookparselist#1{% #1 est le nom du noeud à retrouver
2022 \def\CF_hookparselista##1(#1)|##2|##3|##4\_nil{%
2023 \def\CF_hooksavedcoord{##2}%
2024 \def\CF_hooksavedcontent{##3}%
2025 }%
2026 \expandafter\CF_hookparselista\CF_hooklist\_nil
2027 }
2028
2029 \def\CF_removehook#1{%
2030 \CF_expsecond\CF_ifinstr{#1}?%
2031 {%
2032 \CF_expafter{\CF_removehooka\relax}#1\_nil#1%
2033 \CF_removehook#1%
2034 }
2035 {}%
2036 }
2037
2038 \def\CF_removehooka#1?#2\_nil#3{%
2039 \CF_iffirsttokmatch{#2}[%
2040 {%
2041 \CF_removehookb#1?#2\_nil#3%
2042 }
2043 {%
2044 \CF_expsecond{\def#3}{\CF_gobarg#1#2}%
2045 }%
2046 }
2047
2048 \def\CF_removehookb#1?[#2]#3\_nil#4{\CF_expsecond{\def#4}{\CF_gobarg#1#3}}
2049
2050 \defKV[charge]{%
2051 .radius = \CF_defifempty\CF_dotradius {#1}{0.15ex},
2052 :sep = \CF_defifempty\CF_dotsep {#1}{0.3em},
2053 .style = \CF_defifempty\CF_dotstyle {#1}{fill=black},
2054 "length = \CF_defifempty\CF_rectlength{#1}{1.5ex},
2055 "width = \CF_defifempty\CF_rectwidth {#1}{.3ex}
2056 }
2057 \def\setcharge#{\setKV[charge]}
2058 \def\resetcharge{\restoreKV[charge]}
2059 \setKVdefault[charge]{%
2060 debug = false,% trace les contours des noeuds
2061 macro atom = \printatom,%macro qui prendra comme argument l'atome recevant la charge
2062 circle = false,% false => noeud atome = rectangle
2063 macro charge = ,% macro attendue (\printatom ou \ensuremath, par exemple) qui prendra comme argument la charge
2064 extra sep = 1.5pt,% séparation additionnelle entre le noeud (cercle ou rectangle) et la position des charges
2065 overlay = true,% charges en "surimpression"
2066 shortcuts = true,% raccourcis \. \: \| et \" actifs pour Lewis
2067 lewisautorot = true,% rotation auto charge Lewis
2068 .radius = 0.15ex,% rayon du point
2069 :sep = 0.3em,% séparation des deux points
2070 .style = {fill=black},% style des points
2071 "length = 1.5ex,% longueur rectangle
2072 "width = .3ex,% largeur rectangle
2073 "style = {black,line width=0.4pt},% style rectangle
2074 |style = {black,line width=0.4pt},% style ligne
2075 }%
2076 \def\chargedot{\CF_testopt\chargedot_a{}}
2077 \def\chargedot_a[#1]{%
2078 \begingroup
2079 \setKV[charge]{#1}%
2080 \CF_expafter{\tikz\draw[}{\CF_dotstyle}](0,0)circle(\CF_dotradius);%
2081 \endgroup
2082 }
2083 \def\chargeddot{\CF_testopt\chargeddot_a{}}
2084 \def\chargeddot_a[#1]{%
2085 \begingroup
2086 \setKV[charge]{#1}%
2087 \ifboolKV[charge]{lewisautorot}
2088 {%
2089 \pgfmathsetmacro\CF_lewisrot{90+\chargeangle}%
2090 }
2091 {%
2092 \def\CF_lewisrot{0}%
2093 }%
2094 \pgfmathsetmacro\CF_halfsep{\CF_dotsep/2}%
2095 \tikzpicture[anchor=center,rotate=\CF_lewisrot]
2096 \CF_expafter{\draw[}{\CF_dotstyle}](-\CF_halfsep pt,0)circle(\CF_dotradius)(\CF_halfsep pt,0)circle(\CF_dotradius);%
2097 \endtikzpicture
2098 \endgroup
2099 }
2100 \def\chargerect{\CF_testopt\chargerect_a{}}
2101 \def\chargerect_a[#1]{%
2102 \begingroup
2103 \setKV[charge]{#1}%
2104 \ifboolKV[charge]{lewisautorot}
2105 {%
2106 \pgfmathsetmacro\CF_lewisrot{90+\chargeangle}%
2107 }
2108 {%
2109 \def\CF_lewisrot{0}%
2110 }%
2111 \pgfmathsetmacro\CF_halfwidth{\CF_rectwidth/2}%
2112 \pgfmathsetmacro\CF_halflength{\CF_rectlength/2}%
2113 \tikzpicture[anchor=center,rotate=\CF_lewisrot]%
2114 \CF_eexpafter{\draw[}{\useKV[charge]{"style}}](-\CF_halflength pt,-\CF_halfwidth pt)rectangle(\CF_halflength pt,\CF_halfwidth pt);% bugfix 1.51
2115 \endtikzpicture
2116 \endgroup
2117 }
2118 \def\chargeline{\CF_testopt\chargeline_a{}}
2119 \def\chargeline_a[#1]{%
2120 \begingroup
2121 \setKV[charge]{#1}%
2122 \ifboolKV[charge]{lewisautorot}
2123 {%
2124 \pgfmathsetmacro\CF_lewisrot{90+\chargeangle}%
2125 }
2126 {%
2127 \def\CF_lewisrot{0}%
2128 }%
2129 \pgfmathsetmacro\CF_halflength{\CF_rectlength/2}%
2130 \tikzpicture[anchor=center,rotate=\CF_lewisrot]%
2131 \CF_eexpafter{\draw[}{\useKV[charge]{|style}}](-\CF_halflength pt,0)--(\CF_halflength pt,0);% bugfix 1.51
2132 \endtikzpicture
2133 \endgroup
2134 }
2135 \def\CF_enableshortcuts{%
2136 \let\CF_saveddot \.\let\.\chargedot
2137 \let\CF_savedddot\:\let\:\chargeddot
2138 \let\CF_savedrect\"\let\"\chargerect
2139 \let\CF_savedline\|\let\|\chargeline
2140 \let\enableshortcuts\relax
2141 \let\disableshortcuts\CF_disableshortcuts
2142 }
2143 \def\CF_disableshortcuts{%
2144 \let\.\CF_saveddot
2145 \let\:\CF_savedddot
2146 \let\"\CF_savedrect
2147 \let\|\CF_savedline
2148 \let\enableshortcuts\CF_enableshortcuts
2149 \let\disableshortcuts\relax
2150 }
2151 \def\charge{%
2152 \begingroup
2153 \catcode`\: 12
2154 \charge_a{true}%
2155 }
2156 \def\Charge{%
2157 \begingroup
2158 \catcode`\: 12
2159 \charge_a{false}%
2160 }
2161 \def\charge_a#1#2{% #1=TF #2=liste emplacements
2162 \CF_testopt{\charge_b{#1}}{}#2\_nil
2163 }
2164 \def\charge_b#1[#2]#3\_nil{%
2165 \charge_c{#1}[#2]{#3}%
2166 }
2167 \def\charge_c#1[#2]#3#4{% #1=TF pour overlay, #2= réglages, #3=liste d'emplacements, #4=atome
2168 \setcharge{overlay=#1,#2}%
2169 \setbox\CF_chargebox\hbox{\useKV[charge]{macro atom}{#4}}%
2170 \CF_ifinsidetikz
2171 {%
2172 \pgfinterruptpicture
2173 \let\CF_atendofcharge\endpgfinterruptpicture
2174 }
2175 {%
2176 \let\CF_atendofcharge\relax
2177 }%
2178 \expanded{\noexpand
2179 \tikzpicture[every node/.style={%
2180 \ifboolKV[charge]{debug}{draw=red,}{}%
2181 anchor=base,%
2182 inner sep=0pt,%
2183 outer sep=0pt,%
2184 minimum size=0pt},%
2185 baseline]}%
2186 \expanded{\noexpand
2187 \node[%
2188 \ifboolKV[charge]{circle}{circle,}{}%
2189 \ifboolKV[charge]{debug}{draw=green,}{}%
2190 anchor=base%
2191 ]}%
2192 (atombox)at(0,0)%
2193 {\copy\CF_chargebox};% noeud contenant l'atome
2194 \expanded{\noexpand
2195 \node[%
2196 \ifboolKV[charge]{circle}{circle,}{}%
2197 \ifboolKV[charge]{debug}{draw=blue,}{}%
2198 anchor=base,%
2199 inner sep=\useKV[charge]{extra sep},%
2200 overlay%
2201 ]}%
2202 (atom)at(0,0){%
2203 \vrule width0pt height\ht\CF_chargebox depth\dp\CF_chargebox
2204 \vrule width\wd\CF_chargebox height\CF_zero depth\CF_zero};% noeud pour placer les charges
2205 \let\enableshortcuts\relax
2206 \let\disableshortcuts\relax
2207 \ifboolKV[charge]{shortcuts}
2208 \CF_enableshortcuts
2209 {}% l'atome n'est _PAS_ concerné par les racourcis
2210 \charge_d#3,\CF_quark=%
2211 \endtikzpicture
2212 \CF_atendofcharge
2213 \endgroup
2214 }
2215 \def\charge_d#1={%
2216 \CF_ifx\CF_quark{#1}%
2217 {}
2218 {%
2219 \CF_striplastsp{#1}\charge_e=% bugfix 1.54
2220 }%
2221 }
2222 \def\charge_e#1={%
2223 \CF_ifinstr{#1}[
2224 {%
2225 \charge_f#1=%
2226 }
2227 {%
2228 \charge_f#1[]=%
2229 }%
2230 }
2231 \def\charge_f#1[#2]={%
2232 \CF_ifinstr{#1}:
2233 {%
2234 \charge_g#1[#2]=%
2235 }
2236 {%
2237 \charge_g#1:0pt[#2]=%
2238 }%
2239 }
2240 \def\charge_g#1:#2[#3]=#4,{% #1=angle, #2=offset, #3=code tikz charge, #4=charge
2241 \CF_stripsp{#1}\CF_ifinteger
2242 {%
2243 \pgfmathsetmacro\chargeangle{mod(#1,360)}%
2244 }
2245 {%
2246 \pgfmathanglebetweenpoints{\pgfpointanchor{atom}{center}}{\CF_stripsp{#1}{\pgfpointanchor{atom}}}%
2247 \let\chargeangle\pgfmathresult% incorrect si (atom.center==atom.#1) && (extra sep==0) TODO: mettre un warning ?
2248 }%
2249 \edef\CF_offset{\the\dimexpr#2+0pt}%
2250 \CF_stripsp{#1}{\CF_distancebetweenpoints{atom}{center}{atom}}\CF_chargedistance
2251 \CF_eexpafter{\node[anchor=center,}{\ifboolKV[charge]{overlay}{overlay,}{}}#3]%
2252 at([shift=(\chargeangle:\CF_chargedistance pt+\CF_offset)]atom.center){\useKV[charge]{macro charge}{#4}};%
2253 \charge_d
2254 }
2255
2256 \def\Chembelow{%
2257 \begingroup
2258 \let\CF_temp\CF_gobarg
2259 \CF_chembelowa
2260 }
2261
2262 \def\chembelow{%
2263 \begingroup
2264 \let\CF_temp\CF_id
2265 \CF_chembelowa
2266 }
2267
2268 \def\CF_chembelowa{\CF_testopt\CF_chembelowb\CF_stacksep}
2269
2270 \def\CF_chembelowb[#1]#2#3{%
2271 \setbox\CF_box\hbox{\printatom{#2}}%
2272 \expandafter\vtop\CF_temp{to\ht\CF_box}{%
2273 \offinterlineskip
2274 \hbox{\printatom{#2}}%
2275 \kern#1\relax
2276 \hbox to\wd\CF_box{\hss\printatom{#3}\hss}%
2277 \CF_temp\vss
2278 }%
2279 \endgroup
2280 }
2281
2282 \def\Chemabove{%
2283 \begingroup
2284 \let\CF_temp\CF_gobarg
2285 \CF_chemabovea
2286 }
2287
2288 \def\chemabove{%
2289 \begingroup
2290 \let\CF_temp\CF_id
2291 \CF_chemabovea
2292 }
2293
2294 \def\CF_chemabovea{\CF_testopt\CF_chemaboveb\CF_stacksep}
2295
2296 \def\CF_chemaboveb[#1]#2#3{%
2297 \setbox\CF_box\hbox{\printatom{#2}}%
2298 \expandafter\vbox\CF_temp{to\ht\CF_box}{%
2299 \offinterlineskip
2300 \CF_temp\vss
2301 \hbox to\wd\CF_box{\hss\printatom{#3}\hss}%
2302 \kern#1\relax
2303 \hbox{\printatom{#2}}%
2304 }%
2305 \endgroup
2306 }
2307
2308 \def\chemmove{\CF_testopt\CF_chemmove{}}
2309
2310 \def\CF_chemmove[#1]#2{%
2311 \CF_doifnotempty{#2}%
2312 {%
2313 \expandafter\tikzpicture\expanded{[overlay,remember picture,-CF\CF_ifempty{#1}{}{,\unexpanded{#1}}]}%
2314 #2%
2315 \endtikzpicture
2316 }%
2317 }
2318
2319 \def\chemnameinit#1{%
2320 \setbox\CF_boxstuff\hbox{#1}%
2321 \ifboolKV[chemfig]{gchemname}
2322 \xdef
2323 \edef
2324 \CF_dpmax{\the\dp\CF_boxstuff}%
2325 }
2326 \chemnameinit{}
2327
2328 \def\CF_parsemolname#1\\#2\_nil{%
2329 \hbox to\CF_wdstuffbox{\hss#1\hss}%
2330 \CF_doifnotempty{#2}{\CF_parsemolname#2\_nil}%
2331 }
2332
2333 \def\chemname{%
2334 \CF_ifstar
2335 {%
2336 \CF_adjust_name_dpfalse
2337 \CF_chemnamea
2338 }
2339 {%
2340 \CF_adjust_name_dptrue
2341 \CF_chemnamea
2342 }%
2343 }
2344
2345 \def\CF_chemnamea{\CF_testopt\CF_chemnameb{}}
2346
2347 \def\CF_chemnameb[#1]#2#3{%
2348 \CF_stripsp{#1}\CF_ifempty% v1.71 : mise en cohérence avec \name[dimension]{nom}
2349 {%
2350 \def\CF_current_name_sep{\useKV[chemfig]{name sep}}%
2351 }
2352 {%
2353 \def\CF_current_name_sep{#1}%
2354 }%
2355 \setbox\CF_boxstuff\hbox{#2}%
2356 \edef\CF_wdstuffbox{\the\wd\CF_boxstuff}%
2357 \edef\CF_dpstuffbox{\the\dp\CF_boxstuff}%
2358 \leavevmode
2359 \ifdim\CF_dpmax<\CF_dpstuffbox
2360 \ifboolKV[chemfig]{gchemname}\global{}\let\CF_dpmax\CF_dpstuffbox
2361 \fi
2362 \vtop{%
2363 \box\CF_boxstuff
2364 \nointerlineskip
2365 \kern\dimexpr\CF_current_name_sep\ifCF_adjust_name_dp+\CF_dpmax-\CF_dpstuffbox\fi\relax
2366 \CF_parsemolname#3\\\_nil
2367 }%
2368 }
2369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2370 %%% R É A C T I O N S H O R I Z O N T A L E S %%%
2371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2372 \newbox\CF_harrow_boxup
2373 \newbox\CF_harrow_boxdown
2374 \newcount\CF_hreact_cnt
2375
2376 \def\CF_harrowdisplaylabel#1#2#3#4#5#6#7#8{}
2377 \def\hreac{%
2378 \begingroup
2379 \CF_testopt\CF_hreac_a{}%
2380 }
2381 \def\CF_hreac_a[#1]{% #1=arg optionnel
2382 \CF_doifnotempty{#1}{\setKV[chemfig]{#1}}%
2383 \CF_hreact_cnt0 % compteur de composé
2384 \pgfmathsetmacro\CF_arrowdoublesep{\CF_arrowdoublesep/2}%
2385 \pgfmathsetmacro\CF_arrowdoubleposstart{(1-\CF_arrowdoubleposstart)/2}%
2386 \pgfmathsetmacro\CF_arrowdoubleposend{1-\CF_arrowdoubleposstart}%
2387 \let\CF_arrowshiftnodes\CF_gobarg % neutralisation des macros
2388 \let\CF_arrowdisplaylabel\CF_harrowdisplaylabel% inutiles de \CF_arrow
2389 \let\CF_hreac_name_list\empty
2390 \let\CF_hreac_current_name\empty
2391 \def\CF_hreac_max_depth{0pt}%
2392 \def\CF_current_shiftup{0pt}%
2393 \def\CF_current_shiftup_back{0pt}%
2394 \def\CF_current_shiftleft{0pt}%
2395 \edef\CF_current_node_name{c\number\CF_hreact_cnt}%
2396 \let\CF_hreac_current_compound\empty
2397 \let\chemname\CF_hreac_chemname % reprogrammation de \chemname
2398 \let\name\CF_hreac_name
2399 \CF_compound_is_chemfigfalse
2400 \ifboolKV[chemfig]{hreac debug}
2401 {%
2402 \tikzpicture[every node/.style={draw,anchor=base,inner sep=0pt,outer sep=0pt,minimum size=1pt},baseline]%
2403 }
2404 {%
2405 \tikzpicture[every node/.style={anchor=base,inner sep=0pt,outer sep=0pt,minimum size=0pt},baseline]%
2406 }%
2407 \node[anchor=\CF_hreac_init_anchor](\CF_current_node_name){\vphantom{A}};%
2408 \pgfextracty\CF_dim{\pgfpointanchor{\CF_current_node_name}{base}}%
2409 \edef\CF_hreac_posy_initnode{\the\CF_dim}%
2410 \CF_hreac_b
2411 }
2412 \def\CF_hreac_b{%
2413 \futurelet\CF_toksa\CF_hreac_c
2414 }
2415 \def\CF_hreac_c{%
2416 \CF_ifxcase\CF_toksa
2417 \endhreac {}% exécuter \endhreac
2418 \bgroup {%
2419 \ifCF_compound_is_chemfig
2420 \edef\CF_restore_hashcatcode{\catcode\number`\# =\number\catcode`\# \relax}%
2421 \catcode`\# 12
2422 \fi
2423 \CF_hreac_add_arg
2424 }%
2425 \CF_sptoken \CF_hreac_gob_space
2426 + \CF_hreac_next_plus
2427 > \CF_hreac_next_arrow
2428 \^ \CF_hreac_set_shiftup
2429 \> \CF_hreac_set_shiftleft
2430 \chemfig \CF_hreac_next_chemfig
2431 \chemname {}% exécuter \CF_hreac_name
2432 \name {}% exécuter \CF_hreac_name
2433 \hreac \CF_hreac_illegal_command
2434 \schemestart\CF_hreac_illegal_command
2435 \CF_ifxcase_elseif
2436 \CF_hreac_addtok
2437 \CF_ifxcase_endif
2438 }
2439 \def\CF_hreac_illegal_command#1{%
2440 \CF_error{Macro '\string#1' not allowed in \string\hreac...\string\endhreac}%
2441 }
2442 \def\CF_hreac_set_shiftup\^{%
2443 \CF_ifstar
2444 {%
2445 \CF_hreac_set_shiftup_a1%
2446 }
2447 {%
2448 \CF_hreac_set_shiftup_a0%
2449 }%
2450 }
2451 \def\CF_hreac_set_shiftup_a#1#2{% #1=1 ou 0 selon * #2=dimension
2452 \edef\CF_current_shiftup{\CF_current_shiftup+#2}%
2453 \edef\CF_current_shiftup_back{\ifnum#1=1 0pt\else-#2\fi}%
2454 \CF_hreac_b
2455 }
2456 \def\CF_hreac_set_shiftleft\>#1{%
2457 \def\CF_current_shiftleft{#1}%
2458 \CF_hreac_b
2459 }
2460 \def\CF_hreac_addtok#1{%
2461 \CF_addtomacro\CF_hreac_current_compound{#1}%
2462 \CF_hreac_b
2463 }
2464 \def\CF_hreac_add_arg#1{%
2465 \CF_addtomacro\CF_hreac_current_compound{{#1}}%
2466 \ifCF_compound_is_chemfig
2467 \CF_restore_hashcatcode
2468 \CF_compound_is_chemfigfalse
2469 \fi
2470 \CF_hreac_b
2471 }
2472 \def\endhreac{%
2473 \CF_expsecond\CF_hreac_compose\CF_hreac_current_compound
2474 \expandafter\CF_hreac_draw_names\CF_hreac_name_list[0={}{}{}]% placer les noms des composés
2475 \ifboolKV[chemfig]{hreac debug}
2476 {%
2477 \pgfextractx\CF_dim{\pgfpointanchor{\CF_current_node_name}{0}}%
2478 \edef\CF_current_width{\the\CF_dim}%
2479 \pgfextractx\CF_dim{\pgfpointanchor{c1}{180}}%
2480 \edef\CF_current_width{\the\dimexpr\CF_current_width-\CF_dim\relax}% largeur de la réaction
2481 \draw[dotted,red,line width=0.5pt](c1.west)--([xshift=\CF_current_width]c1.west);%
2482 }
2483 {}%
2484 \endtikzpicture
2485 \endgroup
2486 }
2487 \def\CF_hreac_draw_names[#1=#2#3#4]{%
2488 \CF_ifnum{#1=0 }
2489 {}
2490 {%
2491 \node[anchor=north,at=(c#1.south),yshift=-(\CF_hreac_max_depth-#3+\CF_hreac_name_sep)](name#1)%
2492 {\hbox to#2{\hss\vbox{\CF_compose_harrow_label#4\\\_nil}\hss}};%
2493 \ifboolKV[chemfig]{hreac debug}
2494 {%
2495 \node[anchor=north,at=(name#1.south),fill=purple!60,overlay,opacity=0.5]{\scriptsize\bfseries name#1};
2496 }%
2497 {}%
2498 \CF_hreac_draw_names
2499 }%
2500 }
2501 \expandafter\def\expandafter\CF_hreac_gob_space\space{%
2502 \CF_hreac_b
2503 }
2504 \def\CF_hreac_next_plus#1{%
2505 \CF_expsecond\CF_hreac_compose\CF_hreac_current_compound
2506 \CF_hreac_compose{#1}% #1= '+'
2507 \CF_hreac_b
2508 }
2509 \def\CF_hreac_next_arrow>{%
2510 \CF_expsecond\CF_hreac_compose\CF_hreac_current_compound
2511 \CF_harrow
2512 }
2513
2514 \def\CF_hreac_next_chemfig#1{% #1 est \chemfig
2515 \CF_testopt\CF_hreac_next_chemfig_a{}% bugfix v1.71
2516 }
2517 \def\CF_hreac_next_chemfig_a[#1]{%
2518 \CF_addtomacro\CF_hreac_current_compound{\chemfig[#1]}%
2519 \CF_compound_is_chemfigtrue
2520 \CF_hreac_b
2521 }
2522 \def\CF_hreac_chemname{%
2523 \CF_testopt\CF_hreac_chemname_a{}% fixme v1.71
2524 }
2525 \def\CF_hreac_chemname_a[#1]{%
2526 \CF_stripsp{#1}\CF_ifempty% v1.71
2527 {%
2528 \edef\CF_hreac_chemname_current_sep{\useKV[chemfig]{name sep}}%
2529 }
2530 {%
2531 \def\CF_hreac_chemname_current_sep{#1}%
2532 }%
2533 \begingroup
2534 \catcode`\# 12
2535 \CF_hreac_chemname_b
2536 }
2537 \def\CF_hreac_chemname_b#1{% #1=composé lu avec \catcode`\#=12
2538 \endgroup
2539 \CF_hreac_chemname_c{#1}%
2540 }
2541 \def\CF_hreac_chemname_c#1#2{% #1=composé #2=nom
2542 \endgroup
2543 \def\CF_hreac_current_name{#2}%
2544 \CF_hreac_b#1%
2545 }
2546 \def\CF_hreac_name{% si \name{nom} est rencontré
2547 \CF_testopt\CF_hreac_name_a{}% fixme v1.71
2548 }
2549 \def\CF_hreac_name_a[#1]#2{%
2550 \CF_stripsp{#1}\CF_ifempty% v1.71
2551 {%
2552 \edef\CF_hreac_chemname_current_sep{\useKV[chemfig]{name sep}}%
2553 }
2554 {%
2555 \def\CF_hreac_chemname_current_sep{#1}%
2556 }%
2557 \def\CF_hreac_current_name{#2}%
2558 \CF_hreac_b
2559 }
2560 \def\CF_harrow{%
2561 \CF_ifnextchar\bgroup
2562 {\CF_harrow_a}
2563 {\CF_harrow_b{->}}%
2564 }
2565 \def\CF_harrow_a#1{%
2566 \CF_stripsp{#1}\CF_harrow_b
2567 }
2568 \def\CF_harrow_b#1{%
2569 \CF_ifinstr{\relax->\relax<-\relax<->\relax<=>\relax<<->\relax<->>\relax}{\relax#1\relax}
2570 {%
2571 \def\CF_harrow_type{#1}%
2572 }
2573 {%
2574 \CF_ifempty{#1}
2575 {%
2576 \def\CF_harrow_type{->}%
2577 }
2578 {%
2579 \CF_error{'\detokenize{#1}' is not a valid arrow type in hreac}
2580 \def\CF_harrow_type{->}%
2581 }%
2582 }%
2583 \CF_harrow_c
2584 }
2585 \def\CF_harrow_c{%
2586 \CF_testopt\CF_harrow_d{}%
2587 }
2588 \def\CF_harrow_d[#1]{%
2589 \CF_testopt{\CF_harrow_e[#1]}{}%
2590 }
2591 \def\CF_harrow_e[#1][#2]{%
2592 \let\CF_harrow_length\CF_harrow_min_width
2593 \CF_doifnotempty{#1}
2594 {%
2595 \setbox\CF_harrow_boxup\hbox
2596 {%
2597 \vbox{\pgfinterruptpicture\CF_compose_harrow_label#1\\\_nil\endpgfinterruptpicture}%
2598 }%
2599 \ifdim\dimexpr\wd\CF_harrow_boxup+\CF_harrow_label_xsep*2\relax>\CF_harrow_length\relax
2600 \edef\CF_harrow_length{\the\dimexpr\wd\CF_harrow_boxup+\CF_harrow_label_xsep*2\relax}%
2601 \fi
2602 }%
2603 \CF_doifnotempty{#2}
2604 {%
2605 \setbox\CF_harrow_boxdown\hbox
2606 {%
2607 \vtop{\pgfinterruptpicture\CF_compose_harrow_label#2\\\_nil\endpgfinterruptpicture}%
2608 }%
2609 \ifdim\dimexpr\wd\CF_harrow_boxdown+\CF_harrow_label_xsep*2\relax>\CF_harrow_length\relax
2610 \edef\CF_harrow_length{\the\dimexpr\wd\CF_harrow_boxdown+\CF_harrow_label_xsep*2\relax}%
2611 \fi
2612 }%
2613 \CF_hreac_compose{\kern\CF_harrow_length}%
2614 \node[at=(\CF_current_node_name.180)](harrowstart){};%
2615 \node[at=(\CF_current_node_name.0)](harrowend){};%
2616 \CF_eexpsecond{\def\CF_arrowtip}{\expandafter\CF_gobarg\CF_arrowhead}%
2617 \edef\CF_arrowstartnode{harrowstart}%
2618 \edef\CF_arrowendnode {harrowend}%
2619 \def\CF_arrowcurrentstyle{-CF,line width=0.5pt}%
2620 \csname CF_arrow(\CF_harrow_type)\endcsname[][][][][][][][]\_nil
2621 \CF_doifnotempty{#1}
2622 {%
2623 \node[anchor=south,
2624 at=(\CF_current_node_name.north),
2625 yshift=\CF_arrowlabelsep]%
2626 (labelup\the\CF_hreact_cnt)%
2627 {\hbox to\dimexpr\CF_harrow_length-\CF_harrow_label_xsep*2\relax
2628 {\CF_harrow_label_align_left\box\CF_harrow_boxup\CF_harrow_label_align_right}%
2629 };%
2630 \ifboolKV[chemfig]{hreac debug}
2631 {%
2632 \node[anchor=south,
2633 at=(labelup\the\CF_hreact_cnt.north),
2634 fill=blue!60,
2635 overlay,
2636 opacity=0.5]%
2637 {\scriptsize\bfseries l-sup\the\CF_hreact_cnt};
2638 }
2639 {}%
2640 }%
2641 \CF_doifnotempty{#2}
2642 {%
2643 \node[%
2644 anchor=north,
2645 at=(\CF_current_node_name.south),
2646 yshift=-\CF_arrowlabelsep%
2647 ]%
2648 (labeldown\the\CF_hreact_cnt)%
2649 {%
2650 \hbox to\dimexpr\CF_harrow_length-\CF_harrow_label_xsep*2\relax
2651 {\CF_harrow_label_align_left\box\CF_harrow_boxdown\CF_harrow_label_align_right}%
2652 };%
2653 \ifboolKV[chemfig]{hreac debug}
2654 {%
2655 \node[%
2656 anchor=north,
2657 at=(labeldown\the\CF_hreact_cnt.south),
2658 fill=blue!60,
2659 overlay,
2660 opacity=0.5
2661 ]
2662 {\scriptsize\bfseries l-inf\the\CF_hreact_cnt};
2663 }
2664 {}%
2665 }%
2666 \CF_hreac_b
2667 }
2668 \def\CF_hreac_compose#1{%
2669 \advance\CF_hreact_cnt1
2670 \let\CF_previousnodename\CF_current_node_name
2671 \edef\CF_current_node_name{c\number\CF_hreact_cnt}%
2672 \edef\CF_hreac_current_compound_sep{\CF_ifnum{\CF_hreact_cnt=1 }{0pt}{\CF_hreac_sep}}%
2673 \node[%
2674 anchor=180,
2675 at=(\CF_previousnodename.0),
2676 xshift=\CF_hreac_current_compound_sep+\CF_current_shiftleft,
2677 yshift=\CF_current_shiftup%
2678 ]%
2679 (\CF_current_node_name){#1};%
2680 \ifboolKV[chemfig]{hreac debug}
2681 {%
2682 \node[%
2683 anchor=south,
2684 at=(\CF_current_node_name.north),
2685 fill=green!60,
2686 overlay,
2687 opacity=0.5%
2688 ]%
2689 {\scriptsize\bfseries \CF_current_node_name};%
2690 \node[at=(\CF_current_node_name.west),fill,red]{};
2691 }
2692 {}%
2693 \pgfextracty\CF_dim{\pgfpointanchor{\CF_current_node_name}{south}}%
2694 \edef\CF_current_depth{\the\dimexpr\CF_hreac_posy_initnode-\CF_dim\relax}%
2695 \CF_ifnum{0\ifx\CF_hreac_current_name\empty1\else\ifx\CF_hreac_chemname_current_sep\empty1\fi\fi>0 }
2696 {% si composé sans nom OU SINON [décalage] non précisé dans \chemname ou \name
2697 \ifdim\CF_current_depth>\CF_hreac_max_depth\relax
2698 \let\CF_hreac_max_depth\CF_current_depth
2699 \fi
2700 }
2701 {%
2702 \ifdim\dimexpr\CF_current_depth+\CF_hreac_chemname_current_sep\relax>\CF_hreac_max_depth\relax
2703 \edef\CF_hreac_max_depth{\the\dimexpr\CF_current_depth+\CF_hreac_chemname_current_sep-\CF_hreac_name_sep\relax}%
2704 \fi
2705 }%
2706 \CF_ifx\CF_hreac_current_name\empty
2707 {}
2708 {%
2709 \pgfextractx\CF_dim{\pgfpointanchor{\CF_current_node_name}{0}}%
2710 \edef\CF_current_width{\the\CF_dim}%
2711 \pgfextractx\CF_dim{\pgfpointanchor{\CF_current_node_name}{180}}%
2712 \edef\CF_current_width{\the\dimexpr\CF_current_width-\CF_dim\relax}% largeur du composé
2713 \CF_edefaddtomacro\CF_hreac_name_list{%
2714 [%
2715 \the\CF_hreact_cnt=%
2716 {\CF_current_width}%
2717 {\CF_current_depth}%
2718 {\unexpanded\expandafter{\CF_hreac_current_name}}%
2719 ]%
2720 }%
2721 \let\CF_hreac_current_name\empty
2722 }%
2723 \def\CF_hreac_current_compound{}%
2724 \def\CF_current_shiftleft{0pt}%
2725 \let\CF_current_shiftup\CF_current_shiftup_back
2726 \def\CF_current_shiftup_back{0pt}%
2727 }
2728 \def\CF_compose_harrow_label#1\\#2\_nil{%
2729 \hbox{#1}%
2730 \CF_doifnotempty{#2}{\CF_compose_harrow_label#2\_nil}%
2731 }
2732
2733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2734 %%% S C H É M A S R É A C T I O N N E L S %%%
2735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2736 \let\CF_schemenest\CF_zero
2737
2738 \def\CF_subscheme{\CF_testopt\CF_subschemea{}}
2739 \def\CF_subschemea[#1]{\CF_testopt{\CF_subschemeb[#1]}{text}}
2740 \def\CF_subschemeb[#1][#2]#3{\schemestart[#1][#2]#3\schemestop}
2741
2742 \def\chemleft#1#2\chemright#3{%
2743 \leavevmode
2744 \begingroup
2745 \setbox0\hbox{$\vcenter{\hbox{}}$}\edef\CF_delimmathht{\the\ht0}%
2746 \setbox0\hbox{#2}\edef\CF_delimdim{\the\dimexpr(\ht0+\dp0)/2}%
2747 \edef\CF_delimshift{\the\dimexpr(\ht0-\dp0)/2-\CF_delimmathht}%
2748 \raise\CF_delimshift\hbox{$\left#1\vrule height\CF_delimdim depth\CF_delimdim width0pt\right.$}\box0
2749 \raise\CF_delimshift\hbox{$\left.\vrule height\CF_delimdim depth\CF_delimdim width0pt\right#3$}%
2750 \endgroup
2751 }
2752
2753 \def\chemright#1{%
2754 \CF_warning{"\string\chemright\string#1" ignored! No \string\chemleft\space previously found.}%
2755 }
2756
2757 \def\chemup#1#2\chemdown#3{%
2758 \begingroup
2759 \setbox0\hbox{\printatom{#2}}\edef\CF_delimdim{\the\dimexpr\wd0/2}%
2760 \tikzpicture[every node/.style={inner sep=0pt,outer sep=0pt,minimum size=0pt},baseline]%
2761 \node[anchor=base west](chem@stuff){\box0};%
2762 \node[at=([email protected]),anchor=east,rotate=-90]{$\left#1\vrule height\CF_delimdim depth\CF_delimdim width0pt\right.$};%
2763 \node[at=([email protected]),anchor=west,rotate=-90]{$\left.\vrule height\CF_delimdim depth\CF_delimdim width0pt\right#3$};%
2764 \endtikzpicture
2765 \endgroup
2766 }
2767
2768 \def\chemdown#1{%
2769 \CF_warning{"\string\chemdown\string#1" ignored! No \string\chemup\space previously found.}%
2770 }
2771
2772 \def\CF_setstyle#1,#2,#3\_nil#4#5#6{%
2773 \def#4{#1}%
2774 \let#5\empty
2775 \let#6\empty
2776 \CF_iffirsttokmatch\CF_quark{#2\relax}
2777 {}%
2778 {%
2779 \def#5{#2}%
2780 \CF_iffirsttokmatch\CF_quark{#3\relax}
2781 {}%
2782 {%
2783 \CF_setstylea#3\_nil#6%
2784 }%
2785 }%
2786 }
2787 \def\CF_setstylea#1,\CF_quark#2\_nil#3{\def#3{#1}}
2788
2789 \def\CF_and{\futurelet\CF_toksa\CF_anda}
2790
2791 \def\CF_anda{%
2792 \CF_ifx\CF_toksa\bgroup
2793 {%
2794 \CF_andb
2795 }
2796 {%
2797 \CF_andb{}%
2798 }%
2799 }
2800
2801 \def\CF_andb#1{%
2802 \CF_setstyle#1,\CF_quark,\CF_quark\_nil\CF_signspaceante_\CF_signspacepost_\CF_signvshift_
2803 \CF_doifnotempty\CF_signspaceante_
2804 {%
2805 \let\CF_signspaceante\CF_signspaceante_
2806 }%
2807 \CF_doifnotempty\CF_signspacepost_
2808 {%
2809 \let\CF_signspacepost\CF_signspacepost_
2810 }%
2811 \CF_doifnotempty\CF_signvshift_
2812 {%
2813 \let\CF_signvshift\CF_signvshift_
2814 }%
2815 \raise\CF_signvshift\hbox{\kern\CF_signspaceante$+$\kern\CF_signspacepost}%
2816 }
2817
2818 \def\schemestart{%
2819 \begingroup
2820 \CF_ifnum{\CF_schemenest=0 }
2821 {%
2822 \useKV[chemfig]{schemestart code}%
2823 }%
2824 {}%
2825 \xdef\CF_schemenest{\number\numexpr\CF_schemenest+1}%
2826 \CF_testopt\CF_schemestarta{}%
2827 }
2828
2829 \def\CF_schemestarta[#1]{%
2830 \CF_ifempty{#1}
2831 {}
2832 {%
2833 \CF_warning{In a very soon version, the optional argument of \string\schemestart\space must contain keys=values.^^JUse preferable keys 'arrow angle', 'arrow coeff' and 'arrow style'.}% avertissement à partir de la v1.71
2834 }%
2835 \CF_setstyle#1,\CF_quark,\CF_quark\_nil\CF_arrowangle_\CF_arrowlength_\CF_arrowstyle_
2836 \CF_doifnotempty\CF_arrowangle_
2837 {%
2838 \let\CF_arrowangle\CF_arrowangle_
2839 }%
2840 \CF_doifnotempty\CF_arrowlength_
2841 {%
2842 \let\CF_arrowlength\CF_arrowlength_%
2843 }%
2844 \CF_eexpsecond{\def\CF_arrowtip}{\expandafter\CF_gobarg\CF_arrowhead}%
2845 \CF_expsecond{\CF_preaddtomacro\CF_defaultarrowstyle}{\CF_arrowhead,}%
2846 \let\CF_arrowstyle\CF_defaultarrowstyle
2847 \CF_doifnotempty\CF_arrowstyle_
2848 {%
2849 \CF_eaddtomacro\CF_arrowstyle{\expandafter,\CF_arrowstyle_}%
2850 }%
2851 \pgfmathsetmacro\CF_arrowdoublesep{\CF_arrowdoublesep/2}%
2852 \pgfmathsetmacro\CF_arrowdoubleposstart{(1-\CF_arrowdoubleposstart)/2}%
2853 \pgfmathsetmacro\CF_arrowdoubleposend{1-\CF_arrowdoubleposstart}%
2854 \ifboolKV[chemfig]{scheme debug}
2855 {%
2856 \tikzpicture[every node/.style={draw,anchor=base,inner sep=0pt,outer sep=0pt,minimum size=1.5pt},baseline,remember picture]%
2857 }
2858 {%
2859 \tikzpicture[every node/.style={anchor=base,inner sep=0pt,outer sep=0pt,minimum size=0pt},baseline,remember picture]%
2860 }%
2861 \let\merge\CF_merge
2862 \expandafter\let\csname+\endcsname\CF_and
2863 \let\arrow\CF_arrow
2864 \let\schemestop\CF_schemestop
2865 \let\subscheme\CF_subscheme
2866 \CF_testopt{\CF_schemestartb}{}%
2867 }
2868
2869 \def\CF_schemestartb[#1]{%
2870 \CF_ifempty{#1}
2871 {}
2872 {%
2873 \CF_warning{In a very soon version, the second optional argument of \string\schemestart\space will be removed.^^JUse the key 'init anchor' to set the starting anchor.}% avertissement à partir de la v1.71
2874 }%
2875 \ifnum\CF_schemenest=1 % la commande n'est pas imbriquée ?
2876 \CF_cnt_compound0
2877 \fi
2878 \edef\CF_currentnodename{c\number\CF_cnt_compound}%
2879 \let\CF_nextnodename\empty
2880 \let\CF_nextnodestyle\empty
2881 \let\CF_directarrowlist\empty
2882 \ifboolKV[chemfig]{scheme debug}
2883 {%
2884 \node[fill,green](\CF_currentnodename){};%
2885 }
2886 {%
2887 \node(\CF_currentnodename){};%
2888 }%
2889 \def\CF_nextnodeanchor{#1}%
2890 \CF_doifempty\CF_nextnodeanchor{\def\CF_nextnodeanchor{text}}%
2891 \let\CF_compound\empty
2892 \CF_schemestartc
2893 }
2894
2895 \def\CF_schemestartc{%
2896 \futurelet\CF_toksa\CF_schemestarte
2897 }
2898
2899 \expandafter\def\expandafter\CF_schemestartd\space{\futurelet\CF_toksa\CF_schemestarte}
2900
2901 \def\CF_schemestarte{% ... et l'examine :
2902 \CF_iffirsttokina{\arrow\schemestop\merge}%
2903 {}
2904 {%
2905 \CF_ifx\CF_toksa\bgroup
2906 {%
2907 \ifCF_compound_is_chemfig% bugfix 1.6
2908 \edef\CF_restore_hashcatcode{\catcode\number`\#=\number\catcode`\# \relax}%
2909 \catcode`\#12
2910 \fi
2911 \CF_addnextarg
2912 }
2913 {%
2914 \CF_ifx\CF_toksa\CF_sptoken
2915 {%
2916 \CF_addtomacro\CF_compound{ }%
2917 \CF_schemestartd
2918 }
2919 {%
2920 \CF_ifx\CF_toksa\chemfig
2921 \CF_compound_is_chemfigtrue% mettre le flag à vrai
2922 {}%
2923 \afterassignment\CF_schemestartc
2924 \CF_addtomacro\CF_compound
2925 }%
2926 }%
2927 }%
2928 }
2929
2930 \def\CF_addnextarg#1{%
2931 \CF_addtomacro\CF_compound{{#1}}%
2932 \ifCF_compound_is_chemfig% bugfix 1.6
2933 \CF_restore_hashcatcode
2934 \CF_compound_is_chemfigfalse% mettre le flag à faux
2935 \fi
2936 \CF_schemestartc
2937 }
2938
2939 \def\CF_displaycompound#1#2{% #1 = nom et #2 = style
2940 \CF_doifnotempty\CF_compound
2941 {%
2942 \global\advance\CF_cnt_compound1
2943 \CF_ifx\CF_defaultcompoundstyle\empty
2944 {%
2945 \let\CF_currentnodestyle\empty
2946 }
2947 {%
2948 \CF_expsecond{\def\CF_currentnodestyle}{\CF_defaultcompoundstyle,}%
2949 }%
2950 \CF_addtomacro\CF_currentnodestyle{anchor=\CF_nextnodeanchor,at=(\CF_currentnodename)}%
2951 \CF_ifempty{#2}%
2952 {%
2953 \CF_doifnotempty\CF_nextnodestyle
2954 {%
2955 \CF_eaddtomacro\CF_currentnodestyle{\expandafter,\CF_nextnodestyle}%
2956 }%
2957 }
2958 {%
2959 \CF_doifnotempty\CF_nextnodestyle
2960 {%
2961 \CF_warning{two styles for the same node, first style "\CF_nextnodestyle" ignored}%
2962 }%
2963 \CF_addtomacro\CF_currentnodestyle{,#2}%
2964 }%
2965 \CF_ifempty{#1}
2966 {%
2967 \edef\CF_temp{%
2968 \CF_ifempty\CF_nextnodename
2969 {%
2970 c\number\CF_cnt_compound
2971 }
2972 {%
2973 \CF_nextnodename
2974 }%
2975 }%
2976 }
2977 {%
2978 \CF_doifnotempty\CF_nextnodename
2979 {%
2980 \CF_warning{two names for the same node, first name "\CF_nextnodename" ignored}%
2981 }%
2982 \edef\CF_temp{#1}%
2983 }%
2984 \CF_expafter{\node[}\CF_currentnodestyle](\CF_temp){\CF_compound};%
2985 \ifboolKV[chemfig]{scheme debug}%
2986 {%
2987 \node[draw=none,anchor=270,at=(\CF_temp.90),fill=green!60,overlay,opacity=0.5]{\scriptsize\bfseries\CF_temp};%
2988 }
2989 {}%
2990 \let\CF_currentnodename\CF_temp
2991 }%
2992 }
2993
2994 \def\CF_schemestop{%
2995 \CF_displaycompound{}{}%
2996 \CF_directarrowlist
2997 \endtikzpicture
2998 \xdef\CF_schemenest{\number\numexpr\CF_schemenest-1}%
2999 \CF_ifnum{\CF_schemenest=0 }
3000 {%
3001 \useKV[chemfig]{schemestop code}%
3002 }%
3003 {}%
3004 \endgroup
3005 }
3006
3007 \def\CF_analysearrowarg#1{\CF_analysearrowarga#1[]\_nil}
3008
3009 \def\CF_analysearrowarga#1[#2]#3\_nil{%
3010 \CF_ifinstr{#1}.
3011 {%
3012 \CF_addtomacro\CF_temp{#1[#2]}%
3013 }
3014 {%
3015 \CF_addtomacro\CF_temp{#1.[#2]}%
3016 }%
3017 }
3018
3019 \def\CF_arrow{%
3020 \CF_ifnextchar(%
3021 {%
3022 \CF_arrowa
3023 }
3024 {%
3025 \CF_ifnextchar\bgroup
3026 {%
3027 \CF_arrowb(.[]--.[])%
3028 }
3029 {%
3030 \CF_arrowb(.[]--.[]){}%
3031 }%
3032 }%
3033 }
3034
3035 \def\CF_arrowa(#1--#2){%
3036 \def\CF_temp{(}%
3037 \CF_analysearrowarg{#1}%
3038 \CF_addtomacro\CF_temp{--}%
3039 \CF_analysearrowarg{#2}%
3040 \CF_addtomacro\CF_temp)%
3041 \CF_ifnextchar\bgroup
3042 {%
3043 \expandafter\CF_arrowb\CF_temp
3044 }
3045 {%
3046 \expandafter\CF_arrowb\CF_temp{}%
3047 }%
3048 }
3049
3050 \def\CF_arrowb(#1.#2[#3]--#4.#5[#6])#7{%
3051 \def\CF_currentarrowtype{#7}% nom de la flèche
3052 \CF_doifempty\CF_currentarrowtype
3053 {%
3054 \def\CF_currentarrowtype{->}%
3055 }%
3056 \CF_testopt{\CF_arrowc(#1.#2[#3]--#4.#5[#6])}{}%
3057 }
3058
3059 \def\CF_arrowc(#1.#2[#3]--#4.#5[#6])[#7]{%
3060 \def\CF_temp{\CF_arrowe(#1.#2[#3]--#4.#5[#6])}%
3061 \CF_arrowd#7,\empty,\empty\_nil
3062 }
3063
3064 \def\CF_arrowd#1,#2,#3\_nil{%
3065 \CF_addtomacro\CF_temp{{#1}}%
3066 \CF_eaddtomacro\CF_temp{\expandafter{#2}}%
3067 \expandafter\CF_eaddtomacro\expandafter\CF_temp\expandafter{\expandafter\expandafter\expandafter{\expandafter\CF_sanitizelastitem#3,\empty\_nil}}%
3068 \CF_temp
3069 }
3070
3071 % #1, #4 : nom des nodes #2, #5 : ancres des nodes #3, #6 : styles des nodes
3072 % #7 : angle flèche #8 : longueur flèche #9 : style tikz de la flèche
3073 \def\CF_arrowe(#1.#2[#3]--#4.#5[#6])#7#8#9{%
3074 \let\CF_arrowcurrentstyle\CF_arrowstyle
3075 \if @\expandafter\CF_firsttonil\detokenize{#1.}\_nil% si #1 commence par @
3076 \if @\expandafter\CF_firsttonil\detokenize{#4.}\_nil
3077 \CF_eaddtomacro\CF_directarrowlist{\expandafter\CF_directarrow\expandafter{\CF_currentarrowtype}{#1}{#2}{#4}{#5}{#9}}%
3078 \let\CF_nextaction\CF_schemestartc
3079 \else
3080 \CF_doifnotempty\CF_arrowcurrentstyle
3081 {%
3082 \CF_addtomacro\CF_arrowcurrentstyle,%
3083 }%
3084 \CF_doifnotempty{#9}
3085 {%
3086 \CF_addtomacro\CF_arrowcurrentstyle{#9,}%
3087 }%
3088 \CF_displaycompound{}{#3}%
3089 \def\CF_nextnodename{#4}%
3090 \CF_expsecond{\def\CF_currentnodename}{\CF_gobarg#1}%
3091 \let\CF_arrowstartname\CF_currentnodename
3092 \let\CF_arrowendname\CF_nextnodename
3093 \CF_arrowf{#7}{#8}{#2}{#5}%
3094 \def\CF_nextnodestyle{#6}%
3095 \fi
3096 \else
3097 \CF_doifnotempty\CF_arrowcurrentstyle
3098 {%
3099 \CF_addtomacro\CF_arrowcurrentstyle,%
3100 }%
3101 \CF_doifnotempty{#9}
3102 {%
3103 \CF_addtomacro\CF_arrowcurrentstyle{#9,}%
3104 }%
3105 \if @\expandafter\CF_firsttonil\detokenize{#2.}\_nil
3106 \CF_error{syntax "(<name>--@<name>)" is not allowed}%
3107 \else
3108 \CF_displaycompound{#1}{#3}%
3109 \edef\CF_arrowstartname{%
3110 \CF_ifempty{#1}
3111 \CF_currentnodename
3112 {#1}%
3113 \CF_doifnotempty{#2}{.#2}%
3114 }%
3115 \CF_arrowf{#7}{#8}{#2}{#5}%
3116 \def\CF_nextnodename{#4}%
3117 \def\CF_nextnodestyle{#6}%
3118 \fi
3119 \fi
3120 \CF_arrowgobspaces% mange les espaces puis exécute \CF_nextaction
3121 }
3122
3123 \def\CF_arrowgobspaces{\futurelet\CF_toksa\CF_arrowgobspacesa}
3124
3125 \def\CF_arrowgobspacesa{%
3126 \CF_ifx\CF_sptoken\CF_toksa
3127 \CF_arrowgobspacesb
3128 \CF_nextaction
3129 }
3130
3131 \expandafter\def\expandafter\CF_arrowgobspacesb\space{\futurelet\CF_toksa\CF_arrowgobspacesa}
3132
3133 \def\CF_arrowf#1#2#3#4{% #1=angle #2=longueur #3=ancre départ #4=ancre arrivée
3134 \def\CF_nextaction{\let\CF_compound\empty\CF_schemestartc}%
3135 \def\CF_arrowcurrentangle{#1}\CF_doifempty\CF_arrowcurrentangle{\let\CF_arrowcurrentangle\CF_arrowangle}%
3136 \def\CF_currentarrowlength{#2}\CF_doifempty\CF_currentarrowlength{\let\CF_currentarrowlength\CF_arrowlength}%
3137 \node[at=(\CF_currentnodename.\CF_ifempty{#3}\CF_arrowcurrentangle{#3}),shift=(\CF_arrowcurrentangle:\CF_currentarrowlength*\CF_compoundsep),cyan,fill](end@arrow@i@\number\CF_schemenest){};%
3138 \edef\CF_arrowendname{end@arrow@i@\number\CF_schemenest\CF_doifnotempty{#4}{.#4}}%
3139 \ifboolKV[chemfig]{scheme debug}
3140 {%
3141 \node[at=(\CF_currentnodename.\CF_ifempty{#3}\CF_arrowcurrentangle{#3}),shift=(\CF_arrowcurrentangle:\CF_arrowoffset),red,fill](start@arrow){};%
3142 \node[at=(\CF_currentnodename.\CF_ifempty{#3}\CF_arrowcurrentangle{#3}),shift=(\CF_arrowcurrentangle:\CF_currentarrowlength*\CF_compoundsep-\CF_arrowoffset),red,fill](end@arrow){};%
3143 }
3144 {%
3145 \node[at=(\CF_currentnodename.\CF_ifempty{#3}\CF_arrowcurrentangle{#3}),shift=(\CF_arrowcurrentangle:\CF_arrowoffset)](start@arrow){};%
3146 \node[at=(\CF_currentnodename.\CF_ifempty{#3}\CF_arrowcurrentangle{#3}),shift=(\CF_arrowcurrentangle:\CF_currentarrowlength*\CF_compoundsep-\CF_arrowoffset)](end@arrow){};%
3147 }%
3148 \def\CF_arrowstartnode{start@arrow}\def\CF_arrowendnode{end@arrow}%
3149 \csname\expandafter\CF_grabarrowname\CF_currentarrowtype[\_nil\CF_threeea\endcsname
3150 \expandafter\CF_grabarrowargs\CF_currentarrowtype[]\_nil[][][][][][][][]\_nil
3151 \def\CF_currentnodename{end@arrow@i@\number\CF_schemenest}%
3152 \edef\CF_nextnodeanchor{\CF_ifempty{#4}{180+\CF_arrowcurrentangle}{#4}}%
3153 }
3154
3155 % trace un flèche initiée par (@nom--@nom)
3156 % #1=type de flèche #2=nom depart #3=ancre départ #4=nom arrivée #5=ancre arrivée #6=style flèche
3157 \def\CF_directarrow#1#2#3#4#5#6{%
3158 \edef\CF_arrowstartname{\CF_gobarg#2\ifx\empty#3\empty\else.#3\fi}% BUGFIX 1.6d
3159 \edef\CF_arrowendname{\CF_gobarg#4\ifx\empty#5\empty\else.#5\fi}% BUGFIX 1.6d
3160 \path[sloped,allow upside down](\CF_gobarg#2\ifx\empty#3\empty\else.#3\fi)--(\CF_gobarg#4\ifx\empty#5\empty\else.#5\fi)%
3161 coordinate[pos=0,xshift=\CF_arrowoffset](start@direct@arrow)%
3162 coordinate[pos=1,xshift=-\CF_arrowoffset](end@direct@arrow);%
3163 \def\CF_arrowstartnode{start@direct@arrow}%
3164 \def\CF_arrowendnode{end@direct@arrow}%
3165 \pgfmathanglebetweenpoints
3166 {\pgfpointanchor{\CF_gobarg#2}{\ifx\empty#3\empty center\else#3\fi}}% Ne pas utiliser \CF_ifempty ici !!!
3167 {\pgfpointanchor{\CF_gobarg#4}{\ifx\empty#5\empty center\else#5\fi}}%
3168 \let\CF_arrowcurrentangle\pgfmathresult
3169 \CF_doifnotempty{#6}{\CF_addtomacro\CF_arrowcurrentstyle{#6,}}%
3170 \csname\CF_grabarrowname#1[]\_nil\expandafter\endcsname\CF_grabarrowargs#1[]\_nil[][][][][][][][]\_nil
3171 }
3172
3173 \def\CF_mergegrabchardir#1[#2][#3]#4\_nil{%
3174 \CF_expafter{\futurelet\CF_toksa\CF_gobtonil}{\CF_firsttonil#1>\_nil}\_nil
3175 \ifx>\CF_toksa
3176 \def\CF_mergeangle{0}\def\CF_mergeextreme{xmax}\def\CF_mergesign{+}%
3177 \else
3178 \ifx<\CF_toksa
3179 \def\CF_mergeangle{180}\def\CF_mergeextreme{xmin}\def\CF_mergesign{-}%
3180 \else
3181 \ifx^\CF_toksa
3182 \def\CF_mergeangle{90}\def\CF_mergeextreme{ymax}\def\CF_mergesign{+}%
3183 \else
3184 \ifx v\CF_toksa
3185 \def\CF_mergeangle{-90}\def\CF_mergeextreme{ymin}\def\CF_mergesign{-}%
3186 \fi\fi\fi\fi
3187 \def\CF_mergelabelup{#2}\def\CF_mergelabeldo{#3}%
3188 }
3189
3190 \def\CF_merge#1({%
3191 \CF_mergegrabchardir#1[][]\_nil
3192 \CF_mergea(%
3193 }
3194
3195 \def\CF_mergea#1--(#2){\CF_testopt{\CF_mergeb#1--(#2)}{}}
3196
3197 \def\CF_mergeb#1--(#2)[#3]{%
3198 \CF_displaycompound{}{}%
3199 \CF_parsemergeopt#3,\CF_quark,\CF_quark,\CF_quark\_nil
3200 \def\CF_mergexmax{-16383.99999pt}\let\CF_mergeymax\CF_mergexmax
3201 \def\CF_mergexmin{16383.99999pt}\let\CF_mergeymin\CF_mergexmin
3202 \CF_mergeparsenodelist#1(\relax)% calcule les maxi des positions
3203 \pgfmathsetmacro\CF_mergeextremeresult{\csname CF_merge\CF_mergeextreme\endcsname\CF_mergesign\CF_mergefromcoeff*\CF_compoundsep}%
3204 \CF_mergec#1(\relax)% trace les lignes entre les noeuds précédents et la ligne de jonction
3205 \CF_expsecond{\def\CF_temp}{\expandafter[\CF_mergestyle,shorten <=0,shorten >=0,-]}%
3206 \if x\expandafter\CF_firsttonil\CF_mergeextreme\_nil
3207 \CF_addtomacro\CF_temp{(\CF_mergeextremeresult pt,\CF_mergeymax)--(\CF_mergeextremeresult pt,\CF_mergeymin)}%
3208 \else
3209 \CF_addtomacro\CF_temp{(\CF_mergexmin,\CF_mergeextremeresult pt)--(\CF_mergexmax,\CF_mergeextremeresult pt)}%
3210 \fi
3211 \expandafter\draw\CF_temp node[pos=\CF_mergesplitcoeff](merge@point){}% trace la ligne de jonction
3212 node[at=(merge@point),shift=(\CF_mergeangle:\CF_compoundsep*\CF_mergetocoeff-\CF_arrowoffset)](end@merge){}%
3213 node[at=(merge@point),shift=(\CF_mergeangle:\CF_compoundsep*\CF_mergetocoeff)](end@merge@i){};%
3214 \let\CF_arrowcurrentangle\CF_mergeangle
3215 \CF_expafter{\draw[}\CF_mergestyle,shorten <=0](merge@point)--(end@merge)%
3216 \expandafter\CF_arrowdisplaylabela\expandafter{\CF_mergelabelup}{.5}+\expandafter\CF_arrowdisplaylabela\expandafter{\CF_mergelabeldo}{.5}-;%
3217 \def\CF_currentnodename{end@merge@i}%
3218 \let\CF_temp\empty
3219 \CF_analysearrowarg{#2}%
3220 \expandafter\CF_merged\CF_temp\_nil
3221 }
3222
3223 \def\CF_mergec(#1){%
3224 \if\relax\expandafter\noexpand\CF_firsttonil#1\_nil
3225 \else
3226 \CF_ifdot{#1}%
3227 {%
3228 \edef\merge_currentnodename{\CF_beforedot#1\_nil}%
3229 \edef\merge_currentanchor{\CF_afterdot#1\_nil}%
3230 }%
3231 {%
3232 \def\merge_currentnodename{#1}%
3233 \let\merge_currentanchor\CF_mergeangle
3234 }%
3235 \if x\expandafter\CF_firsttonil\CF_mergeextreme\_nil
3236 \pgfextracty\CF_dim{\pgfpointanchor\merge_currentnodename\merge_currentanchor}%
3237 \CF_expafter{\draw[}\CF_mergestyle,shorten >=0,-]([shift=(\CF_mergeangle:\CF_arrowoffset)]\merge_currentnodename.\merge_currentanchor)--(\CF_mergeextremeresult pt,\CF_dim);%
3238 \else
3239 \pgfextractx\CF_dim{\pgfpointanchor\merge_currentnodename\merge_currentanchor}%
3240 \CF_expafter{\draw[}\CF_mergestyle,shorten >=0,-]([shift=(\CF_mergeangle:\CF_arrowoffset)]\merge_currentnodename.\merge_currentanchor)--(\CF_dim,\CF_mergeextremeresult pt);%
3241 \fi
3242 \expandafter\CF_mergec
3243 \fi
3244 }
3245
3246 \def\CF_merged#1.#2[#3]\_nil{%
3247 \def\CF_nextnodename{#1}%
3248 \edef\CF_nextnodeanchor{%
3249 \CF_ifempty{#2}
3250 {%
3251 180+\CF_mergeangle
3252 }
3253 {%
3254 #2%
3255 }%
3256 }%
3257 \def\CF_nextnodestyle{#3}%
3258 \let\CF_compound\empty
3259 \CF_schemestartc
3260 }
3261
3262 \def\CF_parsemergeopt#1,#2,#3,#4\_nil{%
3263 \CF_ifempty{#1}
3264 {%
3265 \def\CF_mergefromcoeff{0.5}%
3266 }
3267 {%
3268 \def\CF_mergefromcoeff{#1}%
3269 }%
3270 \def\CF_mergetocoeff{0.5}%
3271 \def\CF_mergesplitcoeff{0.5}%
3272 \CF_expsecond{\def\CF_mergestyle}{\CF_arrowhead}%
3273 \CF_iffirsttokmatch\CF_quark{#2\relax}
3274 {}
3275 {%
3276 \CF_ifempty{#2}
3277 {%
3278 \def\CF_mergetocoeff{0.5}%
3279 }
3280 {%
3281 \def\CF_mergetocoeff{#2}%
3282 }%
3283 \CF_iffirsttokmatch\CF_quark{#3\relax}
3284 {}
3285 {%
3286 \CF_ifempty{#3}
3287 {%
3288 \def\CF_mergesplitcoeff{0.5}%
3289 }
3290 {%
3291 \def\CF_mergesplitcoeff{#3}%
3292 }%
3293 \CF_iffirsttokmatch\CF_quark{#4\relax}
3294 {}
3295 {%
3296 \CF_parsemergeopta#4\_nil
3297 }%
3298 }%
3299 }%
3300 }
3301
3302 \def\CF_parsemergeopta#1,\CF_quark#2\_nil{%
3303 \CF_ifempty{#1}
3304 {}
3305 {%
3306 \CF_addtomacro\CF_mergestyle{,#1}%
3307 }%
3308 }
3309
3310 \def\CF_mergeparsenodelist(#1){%
3311 \if\relax\expandafter\noexpand\CF_firsttonil#1\_nil
3312 \else
3313 \CF_ifdot{#1}%
3314 {%
3315 \edef\merge_currentnodename{\CF_beforedot#1\_nil}%
3316 \edef\merge_currentanchor{\CF_afterdot#1\_nil}%
3317 }%
3318 {%
3319 \def\merge_currentnodename{#1}%
3320 \let\merge_currentanchor\CF_mergeangle
3321 }%
3322 \pgfextractx\CF_dim{\pgfpointanchor\merge_currentnodename\merge_currentanchor}%
3323 \ifdim\CF_dim>\CF_mergexmax
3324 \edef\CF_mergexmax{\the\CF_dim}%
3325 \fi
3326 \ifdim\CF_dim<\CF_mergexmin
3327 \edef\CF_mergexmin{\the\CF_dim}%
3328 \fi
3329 \pgfextracty\CF_dim{\pgfpointanchor\merge_currentnodename\merge_currentanchor}%
3330 \ifdim\CF_dim>\CF_mergeymax
3331 \edef\CF_mergeymax{\the\CF_dim}%
3332 \fi
3333 \ifdim\CF_dim<\CF_mergeymin
3334 \edef\CF_mergeymin{\the\CF_dim}%
3335 \fi
3336 \expandafter\CF_mergeparsenodelist
3337 \fi
3338 }
3339
3340 \def\CF_grabarrowname#1[#2\_nil{\detokenize{CF_arrow(#1)}}
3341 \def\CF_grabarrowargs#1[#2\_nil{[#2}
3342
3343 \def\CF_makeparametertext#1{%
3344 \toks0{}%
3345 \CF_cnt_group#1\relax
3346 \CF_makeparametertexta1%
3347 }
3348
3349 \def\CF_makeparametertexta#1{%
3350 \unless\ifnum#1>\CF_cnt_group
3351 \toks0\expandafter{\the\toks0[###1]}%
3352 \expandafter\CF_makeparametertexta\expandafter{\number\numexpr#1+1\expandafter}%
3353 \fi
3354 }
3355
3356 % #1 est le nombre d'arguments optionnels, #2 est le nom et #3 le code
3357 \def\definearrow#1#2#3{%
3358 \begingroup
3359 \CF_makeparametertext{#1}%
3360 \expandafter\endgroup
3361 \expandafter\def\csname\detokenize{CF_arrow(#2)}\expandafter\endcsname\the\toks0{#3\CF_gobtonil}%
3362 }
3363
3364 \def\CF_ifdot#1{\CF_ifdota#1.\_nil}
3365 \def\CF_ifdota#1.#2\_nil{\ifx\empty#2\empty\expandafter\CF_execsecond\else\expandafter\CF_execfirst\fi}
3366 \def\CF_beforedot#1.#2\_nil{#1}
3367 \def\CF_afterdot#1.#2\_nil{#2}
3368
3369 \def\CF_rotatenode*#1#2\_nil{%
3370 \CF_ifdot{#1}
3371 {%
3372 \CF_beforedot#1\_nil
3373 }
3374 {%
3375 #1%
3376 }%
3377 }
3378 \def\CF_anchornode*#1#2\_nil#3{%
3379 \CF_ifdot{#1}
3380 {%
3381 \CF_afterdot#1\_nil
3382 }
3383 {%
3384 \CF_arrowcurrentangle-#390-#1%
3385 }%
3386 }
3387
3388 % #1 = label #2 = position #3 = + ou - (au dessus ou au dessous) #4 : nom du noeud de départ
3389 % #5 = label #6 = position #7 = + ou - (au dessus ou au dessous) #8 : nom du noeud de fin
3390 \def\CF_arrowdisplaylabel#1#2#3#4#5#6#7#8{%
3391 \CF_doifnotempty{#1#5}
3392 {\path(#4)--(#8)\CF_arrowdisplaylabela{#1}{#2}{#3}\CF_arrowdisplaylabela{#5}{#6}{#7};}%
3393 }
3394
3395 \def\CF_arrowdisplaylabela#1#2#3{%
3396 \CF_doifnotempty{#1}
3397 {%
3398 \if*\expandafter\CF_firsttonil\detokenize{#1}\_nil
3399 \ifboolKV[chemfig]{scheme debug}
3400 {%
3401 node[pos=#2,sloped,yshift=#3\CF_arrowlabelsep,draw,fill,cyan](shifted@node){}%
3402 node[draw,rotate=\CF_rotatenode#1\_nil,anchor=\CF_anchornode#1\_nil#3,at=(shifted@node)]{\expandafter\CF_gobarg\CF_gobarg#1}%
3403 }
3404 {%
3405 node[pos=#2,sloped,yshift=#3\CF_arrowlabelsep](shifted@node){}%
3406 node[rotate=\CF_rotatenode#1\_nil,anchor=\CF_anchornode#1\_nil#3,at=(shifted@node)]{\expandafter\CF_gobarg\CF_gobarg#1}%
3407 }%
3408 \else
3409 \ifboolKV[chemfig]{scheme debug}
3410 {%
3411 node[pos=#2,sloped,yshift=#3\CF_arrowlabelsep,draw,fill,cyan](shifted@node){}%
3412 node[draw,pos=#2,anchor=-#390,sloped,yshift=#3\CF_arrowlabelsep]{#1}%
3413 }
3414 {%
3415 node[pos=#2,anchor=-#390,sloped,yshift=#3\CF_arrowlabelsep]{#1}%
3416 }%
3417 \fi
3418 }%
3419 }
3420
3421 % pose des noeuds décalés de la dimension #1 à (\CF_arrowstartnode) et (\CF_arrowendnode)
3422 \def\CF_arrowshiftnodes#1{%
3423 \unless\ifdim\CF_ifempty{#1}\CF_zero{#1}=0pt
3424 \expanded{%
3425 \noexpand\path(\CF_arrowstartnode)--(\CF_arrowendnode)%
3426 node[pos=0,sloped,yshift=#1](\CF_arrowstartnode1){}node[pos=1,sloped,yshift=#1](\CF_arrowendnode1){};}%
3427 \edef\CF_arrowstartnode{\CF_arrowstartnode1}\edef\CF_arrowendnode{\CF_arrowendnode1}%
3428 \fi
3429 }
3430
3431 \definearrow3{->}{%
3432 \CF_arrowshiftnodes{#3}%
3433 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowstartnode)--(\CF_arrowendnode);%
3434 \CF_arrowdisplaylabel{#1}{0.5}+\CF_arrowstartnode{#2}{0.5}-\CF_arrowendnode
3435 }
3436
3437 \definearrow3{<-}{%
3438 \CF_arrowshiftnodes{#3}%
3439 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowendnode)--(\CF_arrowstartnode);%
3440 \CF_arrowdisplaylabel{#1}{0.5}+\CF_arrowstartnode{#2}{0.5}-\CF_arrowendnode
3441 }
3442
3443 \definearrow5{-/>}{%
3444 \CF_arrowshiftnodes{#3}%
3445 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowstartnode)--(\CF_arrowendnode)%
3446 coordinate[midway,shift=(\CF_arrowcurrentangle:-1pt)](midway@i)%
3447 coordinate[midway,shift=(\CF_arrowcurrentangle:1pt)](midway@ii)%
3448 coordinate[at=(midway@i),shift=(\CF_ifempty{#4}{225}{#4+180}+\CF_arrowcurrentangle:\CF_ifempty{#5}{5pt}{#5})](line@start)%
3449 coordinate[at=(midway@i),shift=(\CF_ifempty{#4}{45}{#4}+\CF_arrowcurrentangle:\CF_ifempty{#5}{5pt}{#5})](line@end)%
3450 coordinate[at=(midway@ii),shift=(\CF_ifempty{#4}{225}{#4+180}+\CF_arrowcurrentangle:\CF_ifempty{#5}{5pt}{#5})](line@start@i)%
3451 coordinate[at=(midway@ii),shift=(\CF_ifempty{#4}{45}{#4}+\CF_arrowcurrentangle:\CF_ifempty{#5}{5pt}{#5})](line@end@i);
3452 \draw(line@start)--(line@end);%
3453 \draw(line@start@i)--(line@end@i);%
3454 \CF_arrowdisplaylabel{#1}{0.5}+\CF_arrowstartnode{#2}{0.5}-\CF_arrowendnode
3455 }
3456
3457 \definearrow3{<->}{%
3458 \CF_arrowshiftnodes{#3}%
3459 \CF_expafter{\draw[}\CF_arrowcurrentstyle,\CF_arrowtip-\CF_arrowtip](\CF_arrowstartnode)--(\CF_arrowendnode);%
3460 \CF_arrowdisplaylabel{#1}{0.5}+\CF_arrowstartnode{#2}{0.5}-\CF_arrowendnode
3461 }
3462
3463 \definearrow3{<=>}{%
3464 \CF_arrowshiftnodes{#3}%
3465 \path[allow upside down](\CF_arrowstartnode)--(\CF_arrowendnode)%
3466 node[pos=0,sloped,yshift=\CF_arrowdoublesep](\CF_arrowstartnode @u0){}%
3467 node[pos=0,sloped,yshift=-\CF_arrowdoublesep](\CF_arrowstartnode @d0){}%
3468 node[pos=1,sloped,yshift=\CF_arrowdoublesep](\CF_arrowstartnode @u1){}%
3469 node[pos=1,sloped,yshift=-\CF_arrowdoublesep](\CF_arrowstartnode @d1){};%
3470 \begingroup
3471 \ifboolKV[chemfig]{arrow double harpoon}
3472 \pgfarrowharpoontrue
3473 {}%
3474 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowstartnode @u0)--(\CF_arrowstartnode @u1);%
3475 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowstartnode @d1)--(\CF_arrowstartnode @d0);%
3476 \endgroup
3477 \CF_arrowdisplaylabel{#1}{0.5}+\CF_arrowstartnode{#2}{0.5}-\CF_arrowendnode%
3478 }
3479
3480 \definearrow3{<->>}{%
3481 \CF_arrowshiftnodes{#3}%
3482 \path[allow upside down](\CF_arrowstartnode)--(\CF_arrowendnode)%
3483 node[pos=0,sloped,yshift=1pt](\CF_arrowstartnode @u0){}%
3484 node[pos=\CF_arrowdoubleposstart,sloped,yshift=-1pt](\CF_arrowstartnode @d0){}%
3485 node[pos=1,sloped,yshift=1pt](\CF_arrowstartnode @u1){}%
3486 node[pos=\CF_arrowdoubleposend,sloped,yshift=-1pt](\CF_arrowstartnode @d1){};%
3487 \begingroup
3488 \ifboolKV[chemfig]{arrow double harpoon}
3489 \pgfarrowharpoontrue
3490 {}%
3491 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowstartnode @u0)--(\CF_arrowstartnode @u1);%
3492 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowstartnode @d1)--(\CF_arrowstartnode @d0);%
3493 \endgroup
3494 \CF_arrowdisplaylabel{#1}{0.5}+\CF_arrowstartnode{#2}{0.5}-\CF_arrowendnode%
3495 }
3496
3497 \definearrow3{<<->}{%
3498 \path[allow upside down](\CF_arrowstartnode)--(\CF_arrowendnode)%
3499 node[pos=\CF_arrowdoubleposstart,sloped,yshift=1pt](\CF_arrowstartnode @u0){}%
3500 node[pos=0,sloped,yshift=-1pt](\CF_arrowstartnode @d0){}%
3501 node[pos=\CF_arrowdoubleposend,sloped,yshift=1pt](\CF_arrowstartnode @u1){}%
3502 node[pos=1,sloped,yshift=-1pt](\CF_arrowstartnode @d1){};%
3503 \begingroup
3504 \ifboolKV[chemfig]{arrow double harpoon}
3505 \pgfarrowharpoontrue
3506 {}%
3507 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowstartnode @u0)--(\CF_arrowstartnode @u1);%
3508 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowstartnode @d1)--(\CF_arrowstartnode @d0);%
3509 \endgroup
3510 \CF_arrowdisplaylabel{#1}{0.5}+\CF_arrowstartnode{#2}{0.5}-\CF_arrowendnode
3511 }
3512
3513 \definearrow30{%
3514 \CF_arrowshiftnodes{#3}%
3515 \CF_arrowdisplaylabel{#1}{0.5}+\CF_arrowstartnode{#2}{0.5}-\CF_arrowendnode
3516 }
3517
3518 \definearrow5{-U>}{%
3519 \CF_arrowshiftnodes{#3}%
3520 \CF_expafter{\draw[}\CF_arrowcurrentstyle](\CF_arrowstartnode)--(\CF_arrowendnode)node[midway](Uarrow@arctangent){};%
3521 \CF_ifempty{#4}
3522 {%
3523 \def\CF_Uarrowradius{0.333}%
3524 }
3525 {%
3526 \def\CF_Uarrowradius{#4}%
3527 }%
3528 \CF_ifempty{#5}%
3529 {%
3530 \def\CF_Uarrowabsangle{60}%
3531 }
3532 {%
3533 \pgfmathsetmacro\CF_Uarrowabsangle{abs(#5)}% ne prendre en compte que la valeur absolue de l'angle
3534 }%
3535 \expandafter\draw\expanded{[\CF_ifempty{#1}{draw=none}{\unexpanded\expandafter{\CF_arrowcurrentstyle}},-]}(Uarrow@arctangent)%
3536 arc[radius=\CF_compoundsep*\CF_currentarrowlength*\CF_Uarrowradius,start angle=\CF_arrowcurrentangle-90,delta angle=-\CF_Uarrowabsangle]node(Uarrow@start){};
3537 \expandafter\draw\expanded{[\CF_ifempty{#2}{draw=none}{\unexpanded\expandafter{\CF_arrowcurrentstyle}}]}(Uarrow@arctangent)%
3538 arc[radius=\CF_compoundsep*\CF_currentarrowlength*\CF_Uarrowradius,start angle=\CF_arrowcurrentangle-90,delta angle=\CF_Uarrowabsangle]node(Uarrow@end){};
3539 \pgfmathsetmacro\CF_temp{\CF_Uarrowradius*cos(\CF_arrowcurrentangle)<0?"-":"+"}%
3540 \ifdim\CF_Uarrowradius pt>0pt
3541 \CF_arrowdisplaylabel{#1}{0}\CF_temp{Uarrow@start}{#2}{1}\CF_temp{Uarrow@end}%
3542 \else
3543 \CF_arrowdisplaylabel{#2}{0}\CF_temp{Uarrow@start}{#1}{1}\CF_temp{Uarrow@end}%
3544 \fi
3545 }
3546
3547 \def\CF_grabdelim#1#2#3\_CFnil{\def\CF_leftdelim{#1}\def\CF_rightdelim{#2}}
3548 \defKV[CFdelimiters]{%
3549 delimiters = \CF_grabdelim#1()\_CFnil,
3550 height = \def\CF_delimheight{#1},
3551 depth = \CF_expsecond{\CF_defifempty\CF_delimdepth{#1}}{\CF_delimheight},
3552 open xshift = \edef\CF_leftdelimxshift{\the\dimexpr#1},
3553 close xshift = \edef\CF_rightdelimxshift{\CF_ifempty{#1}{-\CF_leftdelimxshift}{-\the\dimexpr#1}}
3554 }
3555 \setKVdefault[CFdelimiters]{%
3556 delimiters = (),
3557 height = 10pt,
3558 depth = ,
3559 open xshift = 0pt,
3560 close xshift = ,
3561 h align = true,
3562 auto rotate = false,
3563 rotate = 0,
3564 indice = n
3565 }%
3566 \def\polymerdelim{\CF_ifnextchar[{\CF_polymerdelima}{\CF_polymerdelima[]}}
3567 \def\CF_polymerdelima[#1]#2#3{%
3568 \restoreKV[CFdelimiters]%
3569 \CF_doifnotempty{#1}
3570 {%
3571 \setKV[CFdelimiters]{#1}%
3572 }%
3573 \edef\CF_delimhalfdim{\the\dimexpr(\CF_delimheight+\CF_delimdepth)/2}%
3574 \edef\CF_delimvshift {\the\dimexpr(\CF_delimheight-\CF_delimdepth)/2}%
3575 \chemmove{%
3576 \nulldelimiterspace0pt
3577 \pgfextractx\CF_dim{\pgfpointanchor{#2}{center}}\edef\CF_leftdelimx{\the\CF_dim}%
3578 \pgfextracty\CF_dim{\pgfpointanchor{#2}{center}}\edef\CF_leftdelimy{\the\CF_dim}%
3579 \pgfextractx\CF_dim{\pgfpointanchor{#3}{center}}\edef\CF_rightdelimx{\the\CF_dim}%
3580 \pgfextracty\CF_dim{\pgfpointanchor{#3}{center}}\edef\CF_rightdelimy{\the\CF_dim}%
3581 \def\CF_autorotate{0}%
3582 \ifboolKV[CFdelimiters]{h align}
3583 {%
3584 \let\CF_rightdelimy\CF_leftdelimy
3585 }
3586 {%
3587 \ifboolKV[CFdelimiters]{auto rotate}
3588 {%
3589 \pgfmathatantwo{\CF_rightdelimy-\CF_leftdelimy}{\CF_rightdelimx-\CF_leftdelimx}%
3590 \let\CF_autorotate\pgfmathresult
3591 }
3592 {%
3593 \CF_eexpsecond\CF_ifempty{\useKV[CFdelimiters]{rotate}}
3594 {}
3595 {%
3596 \edef\CF_autorotate{\useKV[CFdelimiters]{rotate}}%
3597 }%
3598 }%
3599 }%
3600 \node[at={(\CF_leftdelimx+\CF_leftdelimxshift,\CF_leftdelimy+\CF_delimvshift)},rotate=\CF_autorotate]
3601 {$\left\CF_leftdelim\vrule height\CF_delimhalfdim depth\CF_delimhalfdim width0pt\right.$};%
3602 \node[at={(\CF_rightdelimx+\CF_rightdelimxshift,\CF_rightdelimy+\CF_delimvshift)},rotate=\CF_autorotate]
3603 {$\left.\vrule height\CF_delimhalfdim depth\CF_delimhalfdim width0pt\right\CF_rightdelim
3604 \CF_eexpsecond\CF_doifnotempty{\useKV[CFdelimiters]{indice}}
3605 {\CF_underscore{\rlap{$\scriptstyle\useKV[CFdelimiters]{indice}$}}}
3606 $};
3607 }%
3608 }
3609
3610 \catcode`\@11
3611 \pgfdeclarearrow{%
3612 name = CF,%
3613 defaults = {%
3614 length = 3pt 5 1,%
3615 width' = 0pt .8,%
3616 inset' = 0pt .5,%
3617 line width = 0pt 1 1,%
3618 round%
3619 },%
3620 setup code = {%
3621 % Cap the line width at 1/4th distance from inset to tip
3622 \pgf@x\pgfarrowlength
3623 \advance\pgf@x by-\pgfarrowinset
3624 \[email protected]\pgf@x
3625 \ifdim\pgf@x<\pgfarrowlinewidth\pgfarrowlinewidth\pgf@x\fi
3626 % Compute front miter length:
3627 \pgfmathdivide@{\pgf@sys@tonumber\pgfarrowlength}{\pgf@sys@tonumber\pgfarrowwidth}%
3628 \let\pgf@temp@quot\pgfmathresult%
3629 \pgf@x\pgfmathresult pt%
3630 \pgf@x\pgfmathresult\pgf@x%
3631 \pgf@x4\pgf@x%
3632 \advance\pgf@x by1pt%
3633 \pgfmathsqrt@{\pgf@sys@tonumber\pgf@x}%
3634 \pgf@xc\pgfmathresult\pgfarrowlinewidth% xc is front miter
3635 \[email protected]\pgf@xc
3636 \pgf@xa\pgf@temp@quot\pgfarrowlinewidth% xa is extra harpoon miter
3637 % Compute back miter length:
3638 \[email protected]\pgfarrowwidth%
3639 \csname pgfmathatan2@\endcsname{\pgfmath@tonumber\pgfarrowlength}{\pgfmath@tonumber\pgf@ya}%
3640 \pgf@yb\pgfmathresult pt%
3641 \csname pgfmathatan2@\endcsname{\pgfmath@tonumber\pgfarrowinset}{\pgfmath@tonumber\pgf@ya}%
3642 \pgf@ya\pgfmathresult pt%
3643 \advance\pgf@yb by-\pgf@ya%
3644 \[email protected]\pgf@yb% half angle in yb
3645 \pgfmathtan@{\pgf@sys@tonumber\pgf@yb}%
3646 \pgfmathreciprocal@{\pgfmathresult}%
3647 \pgf@yc\pgfmathresult\pgfarrowlinewidth%
3648 \[email protected]\pgf@yc%
3649 \advance\pgf@ya by\pgf@yb%
3650 \pgfmathsincos@{\pgf@sys@tonumber\pgf@ya}%
3651 \pgf@ya\pgfmathresulty\pgf@yc% ya is the back miter
3652 \pgf@yb\pgfmathresultx\pgf@yc% yb is the top miter
3653 \ifdim\pgfarrowinset=0pt
3654 \[email protected]\pgfarrowlinewidth% easy: back miter is half linewidth
3655 \fi
3656 % Compute inset miter length:
3657 \pgfmathdivide@{\pgf@sys@tonumber\pgfarrowinset}{\pgf@sys@tonumber\pgfarrowwidth}%
3658 \let\pgf@temp@quot\pgfmathresult%
3659 \pgf@x\pgfmathresult pt%
3660 \pgf@x\pgfmathresult\pgf@x%
3661 \pgf@x4\pgf@x%\pgf@ya
3662 \advance\pgf@x by1pt%
3663 \pgfmathsqrt@{\pgf@sys@tonumber\pgf@x}%
3664 \pgf@yc\pgfmathresult\pgfarrowlinewidth% yc is inset miter
3665 \[email protected]\pgf@yc%
3666 % Inner length (pgfutil@tempdima) is now arrowlength - front miter - back miter
3667 \pgfutil@tempdima\pgfarrowlength%
3668 \advance\pgfutil@tempdima by-\pgf@xc%
3669 \advance\pgfutil@tempdima by-\pgf@ya%
3670 \[email protected]\pgfarrowwidth%
3671 \advance\pgfutil@tempdimb by-\pgf@yb%
3672 % harpoon miter correction
3673 \ifpgfarrowroundjoin
3674 \pgfarrowssetbackend{\pgf@ya\advance\pgf@x by-.5\pgfarrowlinewidth}%
3675 \else
3676 \pgfarrowssetbackend{0pt}
3677 \fi
3678 \ifpgfarrowharpoon
3679 \pgfarrowssetlineend{\pgfarrowinset\advance\pgf@x by\pgf@yc\advance\pgf@x by.5\pgfarrowlinewidth}%
3680 \else
3681 \pgfarrowssetlineend{\pgfarrowinset\advance\pgf@x by\pgf@yc\advance\pgf@x by-.25\pgfarrowlinewidth}%
3682 \ifpgfarrowreversed
3683 \ifdim\pgfinnerlinewidth>0pt
3684 \pgfarrowssetlineend{\pgfarrowinset}%
3685 \else
3686 \pgfarrowssetlineend{\pgfutil@tempdima\advance\pgf@x by\pgf@ya\advance\pgf@x by-.25\pgfarrowlinewidth}%
3687 \fi
3688 \fi
3689 \fi
3690 \ifpgfarrowroundjoin
3691 \pgfarrowssettipend{\pgfutil@tempdima\advance\pgf@x by\pgf@ya\advance\pgf@x by.5\pgfarrowlinewidth}%
3692 \else
3693 \pgfarrowssettipend{\pgfarrowlength\ifpgfarrowharpoon\advance\pgf@x by\pgf@xa\fi}%
3694 \fi
3695 % The hull:
3696 \pgfarrowshullpoint{\pgfarrowlength\ifpgfarrowroundjoin\else\ifpgfarrowharpoon\advance\pgf@x by\pgf@xa\fi\fi}{\ifpgfarrowharpoon-.5\pgfarrowlinewidth\else0pt\fi}%
3697 \pgfarrowsupperhullpoint{0pt}{.5\pgfarrowwidth}%
3698 \pgfarrowshullpoint{\pgfarrowinset}{\ifpgfarrowharpoon-.5\pgfarrowlinewidth\else 0pt\fi}%
3699 % Adjust inset
3700 \pgfarrowssetvisualbackend{\pgfarrowinset}%
3701 \advance\pgfarrowinset by\pgf@yc%
3702 % The following are needed in the code:
3703 \pgfarrowssavethe\pgfutil@tempdima
3704 \pgfarrowssavethe\pgfutil@tempdimb
3705 \pgfarrowssavethe\pgfarrowlinewidth
3706 \pgfarrowssavethe\pgf@ya
3707 \pgfarrowssavethe\pgfarrowinset
3708 },%
3709 drawing code = {%
3710 \pgfsetdash{}{0pt}%
3711 \ifpgfarrowroundjoin\pgfsetroundjoin\else\pgfsetmiterjoin\fi
3712 \ifdim\pgfarrowlinewidth=\pgflinewidth\else\pgfsetlinewidth{\pgfarrowlinewidth}\fi
3713 \pgfpathmoveto{\pgfqpoint{\pgfutil@tempdima\advance\pgf@x by\pgf@ya}{0pt}}%
3714 \pgfpathlineto{\pgfqpoint{\pgf@ya}{\pgfutil@tempdimb}}%
3715 \pgfpathlineto{\pgfqpoint{\pgfarrowinset}{0pt}}%
3716 \ifpgfarrowharpoon \else
3717 \pgfpathlineto{\pgfqpoint{\pgf@ya}{-\pgfutil@tempdimb}}%
3718 \fi
3719 \pgfpathclose
3720 \ifpgfarrowopen\pgfusepathqstroke\else\ifdim\pgfarrowlinewidth>0pt \pgfusepathqfillstroke\else\pgfusepathqfill\fi\fi
3721 },%
3722 parameters = {%
3723 \the\pgfarrowlinewidth,%
3724 \the\pgfarrowlength,%
3725 \the\pgfarrowwidth,%
3726 \the\pgfarrowinset,%
3727 \ifpgfarrowharpoon h\fi%
3728 \ifpgfarrowopen o\fi%
3729 \ifpgfarrowroundjoin j\fi%
3730 }%
3731 }
3732 \CFrestorecatcode
3733 \endinput