-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchemfig.tex
3066 lines (2895 loc) · 116 KB
/
chemfig.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% !TeX encoding = ISO-8859-1
% Ce fichier contient le code de l'extension "chemfig"
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
\def\CFname {chemfig} %
\def\CFver {1.5} %
% %
\def\CFdate {2020/03/05} %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%____________________________________________________________________
% Author : Christian Tellechea |
% Status : Maintained |
% Email : [email protected] |
% Package URL: https://www.ctan.org/pkg/chemfig |
% Bug tracker: https://framagit.org/unbonpetit/chemfig/issues |
% Repository : https://framagit.org/unbonpetit/chemfig/tree/master |
% Copyright : Christian Tellechea 2010-2020 |
% Licence : Released under the LaTeX Project Public License v1.3c |
% or later, see http://www.latex-project.org/lppl.txt |
% Files : 1) chemfig.tex |
% 2) chemfig.sty |
% 3) t-chemfig.tex |
% 4) README |
% 5) chemfig_doc_fr.tex |
% 6) chemfig_doc_fr.pdf |
% 7) chemfig_doc_en.tex |
% 8) chemfig_doc_fr.pdf |
%--------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% P R É A L A B L E %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-------------------------- Annonce package --------------------------
\ifdefined\ProvidesPackage\else
\immediate\write -1 {%
Package: \CFname\space\CFdate\space\space v\CFver\space\space
Draw molecule with an easy syntax (CT)}%
\fi
%-------------------------- Régime catcodes --------------------------
\begingroup
\def\X#1{\catcode\number`#1=\number\catcode`#1\relax}
\xdef\CFrestorecatcode{\X\[\X\]\X\:\X\(\X\)\X\,\X\-\X\=\X\~\X\!\X\?\X\<\X\>\X\;\X\*\X\|\X\@\X\ \X\_}%
\endgroup
\catcode`\[12 \catcode`\]12 \catcode`\:12 \catcode`\(12
\catcode`\)12 \catcode`\,12 \catcode`\-12 \catcode`\=12
\catcode`\~12 \catcode`\!12 \catcode`\?12 \catcode`\<12
\catcode`\>12 \catcode`\;12 \catcode`\*12 \catcode`\|12
\catcode`\@12 \catcode`\#6 \catcode`\ 10 \catcode`\_11
%-------------------- Vérification des prérequis ---------------------
\def\CF_error#1{\errmessage{Package \CFname\space Error: #1.}}
\def\CF_warning#1{\immediate\write-1{Package \CFname\space Warning: #1^^J}}
\def\CF_checkprimitive#1#2#3{% Vérifie que #1 est une primitive et sinon, émet le message #2 et exécute #3
\begingroup
\edef\__tempa{\meaning#1}\edef\__tempb{\string#1}\expandafter
\endgroup
\ifx\__tempa\__tempb\else
\CF_error{#2}%
\def\CF_temp{#3}%
\CFrestorecatcode\expandafter\CF_temp
\fi
}
\CF_checkprimitive\eTeXversion
{You are not using an eTeX engine, \CFname\space cannot work.}
{\endinput}%
\CF_checkprimitive\expanded
{the \string\expanded\space primitive is not provided by your TeX engine, \CFname\space v\CFver\space cannot work: loading \CFname\space v1.4}
{\input chemfigold.tex\relax\endinput}%
%------------------------ Chargement simplekv ------------------------
\unless\ifdefined\skvname
\begingroup\def\CFtemp{\endgroup\input simplekv.tex\relax}%
\expandafter\CFtemp
\fi
%-------------------------- Chargement tikz --------------------------
\unless\ifdefined\tikzpicture
\begingroup\def\CFtemp{\endgroup\input tikz.tex\relax}%
\expandafter\CFtemp
\fi
\usetikzlibrary{arrows.meta}
%--------------------------- Allocations -----------------------------
\newcount\CF_cntatomgroup
\newcount\CF_cntgroup
\newcount\CF_cntatom
\newcount\CF_cntcycle
\newcount\CF_cntcompound
\newif\ifCF_incycle
\newif\ifCF_cyclearc
\newif\ifCF_definesubmol
\newif\ifCF_adjustnamedp
\newif\ifCF_macrofixedbondlength
\newif\ifCF_lewisoverlay
\newdimen\CF_dim
\newdimen\CF_arrowsize
\newdimen\CF_zero \CF_zero=0pt
\newbox\CF_boxlewis
\newbox\CF_box
\newbox\CF_boxstuff
\newbox\CF_testbox
\newbox\CF_chargebox
\newtoks\CF_substtoks
%-------------------------- Petites macros ---------------------------
\let\CF_begintikzpicture\tikzpicture
\let\CF_endtikzpicture \endtikzpicture
\def\CF_quark{\CF_quark}
\def\CF_execfirst#1#2{#1}
\def\CF_execsecond#1#2{#2}
\def\CF_id#1{#1}
\def\CF_gobarg#1{}
\def\CF_gobtwoargs#1#2{}
\def\CF_firsttonil#1#2\_nil{#1}
\def\CF_sanitizelastitem#1,\empty#2\_nil{#1}
\def\CF_gobtikzinstruction#1;{}
\def\CF_makeother#1{\catcode`#1=12\relax}
\def\CF_lettoken#1#2{\let#1= #2}\CF_lettoken\CF_sptoken{ }
\def\CF_ifx#1#2{\ifx#1#2\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi}
\def\CF_ifempty#1{\ifx\empty#1\empty\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi}
\def\CF_ifnum#1{\ifnum#1\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi}
\def\CF_ifinsidetikz{\ifdefined\pgfpictureid\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi}
\def\CF_ifzerodim#1{%
\setbox\CF_testbox\hbox{\printatom{#1}}%
\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 }
}
\def\CF_doifempty#1{\ifx\empty#1\empty\expandafter\CF_id\else\expandafter\CF_gobarg\fi}
\def\CF_doifnotempty#1{\ifx\empty#1\empty\expandafter\CF_gobarg\else\expandafter\CF_id\fi}
\def\CF_gobtonil#1\_nil{}
\edef\CFhash{\string#}
\begingroup
\catcode`\_8
\expandafter\gdef\csname CF\string_underscore\endcsname{_}
\endgroup
\def\CF_threeea{\expandafter\expandafter\expandafter}
\def\CF_exptwomacroargs#1#2#3{\CF_expsecond{\CF_expsecond#1{#2}}{#3}}
\def\CF_expthreemacroargs#1#2#3#4{\CF_expsecond{\CF_exptwomacroargs#1{#2}{#3}}{#4}}
\def\CF_swaparg#1#2{#2{#1}}
\def\CF_expsecond#1#2{\expandafter\CF_swaparg\expandafter{#2}{#1}}% \CF_expsecond<{arg1>}{<arg2>} donne "<arg1>{*<arg2>}"
\def\CF_eexpsecond#1#2{\expandafter\expandafter\expandafter\CF_swaparg\expandafter\expandafter\expandafter{#2}{#1}}% \CF_eexpsecond{<arg1>}{<arg2>} donne "<arg1>{**<arg2>}"
\def\CF_swapunbrace#1#2{#2#1}
\def\CF_expafter#1#2{\expandafter\CF_swapunbrace\expandafter{#2}{#1}}% \CF_expafter{<arg1>}{<arg2>} donne "<arg1>*<arg2>"
\def\CF_eexpafter#1#2{\expandafter\expandafter\expandafter\CF_swapunbrace\expandafter\expandafter\expandafter{#2}{#1}}% \CF_eexpafter{<arg1>}{<arg2>} donne "<arg1>**<arg2>"
\def\CF_addtomacro#1#2{\CF_expsecond{\def#1}{#1#2}}
\def\CF_eaddtomacro#1#2{\CF_expsecond{\CF_addtomacro#1}{#2}}
\def\CF_preaddtomacro#1#2{\CF_expsecond{\CF_preaddtomacroa#1{#2}}#1}
\def\CF_preaddtomacroa#1#2#3{\def#1{#2#3}}
\def\CF_addtotoks#1#2{#1\expandafter{\the#1#2}}
\def\CF_eaddtotoks#1#2{\expandafter\CF_addtotoks\expandafter#1\expandafter{#2}}
\def\CF_assigntonil#1#2\_nil{\def#1{#2}}
\def\CF_edefaddtomacro#1#2{\CF_expsecond{\CF_addtomacro#1}{\expanded{#2}}}
\def\CF_ifnextchar#1#2#3{%
\let\CF_ifnextchartok=#1% <- espace indésirable, bugfix v1.31
\def\CF_ifnextcharcodetrue{#2}%
\def\CF_ifnextcharcodefalse{#3}%
\futurelet\CF_temptok\CF_ifnextchara
}
\def\CF_ifnextchara{%
\CF_ifx\CF_temptok\CF_sptoken
{\CF_ifnextcharb
}
{\CF_ifx\CF_temptok\CF_ifnextchartok
\CF_ifnextcharcodetrue
\CF_ifnextcharcodefalse
}%
}
\expandafter\def\expandafter\CF_ifnextcharb\space{\futurelet\CF_temptok\CF_ifnextchara}
\def\CF_ifstar#1{\CF_ifnextchar*{\CF_execfirst{#1}}}
\def\CF_testopt#1#2{\CF_ifnextchar[{#1}{#1[{#2}]}}
\def\CF_ifinteger#1{%
\begingroup
\afterassignment\CF_afterinteger
\CF_cntcycle0#1\relax
}
\def\CF_afterinteger#1\relax{%
\endgroup
\CF_ifempty{#1}%
}
\def\CF_iffirsttokmatch#1#2{% est ce que #1 et #2 commencent par les mêmes tokens ?
\futurelet\CF_toksa\CF_gobtonil#1\relax\_nil
\futurelet\CF_toksb\CF_gobtonil#2\relax\_nil
\CF_ifx\CF_toksa\CF_toksb
}
\def\CF_iffirsttokin#1{% teste si le token qui commence #1 appartient aux tokens mis dans #2
\futurelet\CF_toksa\CF_gobtonil#1\relax\_nil
\CF_iffirsttokina
}
\def\CF_iffirsttokina#1{%
\CF_ifempty{#1}
{\CF_execsecond
}
{\futurelet\CF_toksb\CF_gobtonil#1\relax\_nil
\CF_ifx\CF_toksa\CF_toksb
{\CF_execfirst}
{\CF_expsecond\CF_iffirsttokina{\CF_gobarg#1}}%
}%
}
\def\CF_ifinstr#1#2{%
\def\CF_ifinstra##1#2##2\_nil{%
\ifx\empty##2\empty
\expandafter\CF_execsecond
\else
\expandafter\CF_execfirst
\fi}%
\CF_ifinstra#1\__nil#2\_nil
}
\def\CF_afterspace#1 #2\_nil{#2}
\def\CF_valuetomacro[#1]#2[#3]#4{% #1=trousseau #2= macro #3=valeur défaut #4=clé
\CF_eexpsecond{\def#2}{\useKV[#1]{#4}}%
\CF_ifx#2\empty
{\def#2{#3}}
{}%
}
%--------------------------- Substitution ----------------------------
\def\CF_ifstartwith#1#2{% #1=<texte> #2=<motif>
\CF_ifempty{#1}%
{\CF_execsecond
}
{\def\CF_startwithcode{#1}%
\def\CF_startwithpattern{#2}%
\CF_ifstartwitha
}%
}
\def\CF_ifstartwitha{%
\CF_grabfirstarg\CF_startwithcode\CF_firstargcode
\CF_grabfirstarg\CF_startwithpattern\CF_firstargpattern
\CF_ifx\CF_firstargcode\CF_firstargpattern
{\CF_expsecond\CF_ifempty\CF_startwithpattern
{\CF_execfirst
}
{\CF_expsecond\CF_ifempty\CF_startwithcode
\CF_execsecond
\CF_ifstartwitha
}%
}
{\CF_execsecond
}%
}
\def\CF_grabfirstarg#1#2{%
\CF_ifx#1\empty
{\let#2\empty
}
{\def\CF_grabmacro{#2}%
\CF_expsecond\CF_ifbracefirst#1%
{\expandafter\CF_grabbracearg#1\_nil#1}
{\CF_expafter{\futurelet\CF_nexttok\CF_grabfirstarga}#1\_nil#1}%
}%
}
\def\CF_grabfirstarga{%
\CF_ifx\CF_nexttok\CF_sptoken
\CF_grabspacearg
\CF_grabnormalarg
}
\def\CF_grabbracearg#1{%
\expandafter\def\CF_grabmacro{{#1}}%
\CF_grabargassigntonil\relax
}
\expandafter\def\expandafter\CF_grabspacearg\space{%
\expandafter\def\CF_grabmacro{ }%
\CF_grabargassigntonil\relax
}
\def\CF_grabnormalarg#1{%
\expandafter\def\CF_grabmacro{#1}%
\CF_grabargassigntonil\relax
}
\def\CF_grabargassigntonil#1\_nil#2{\CF_expsecond{\def#2}{\CF_gobarg#1}}
\def\CF_ifbracefirst#1{\CF_ifnum{\catcode\CF_threeea`\expandafter\CF_firsttonil\detokenize{#1.}\_nil=1 }}
\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
\def\CF_atendsubstitute{\edef#2{\the\CF_substtoks}}% macro exécutée à la fin
\let\CF_substnogroups\CF_substnogrouponly
\CF_ifnum{#1>0 }
{\let\CF_testifx\empty
\foreach\CF_x in {1,...,#1}{\xdef\CF_testifx{\unexpanded\expandafter{\CF_testifx}\unexpanded\expandafter{\expandafter\ifx\CF_x\CF_nexttok1\fi}}}%
\let\CF_testif\empty
\foreach\CF_x in {1,...,#1}{\xdef\CF_testif{\unexpanded\expandafter{\CF_testif}\unexpanded\expandafter{\expandafter\if\CF_x\CF_nexttok1\fi}}}%
\CF_expsecond\CF_substi#2%
}
{\CF_substall#2%
}%
}
\def\CF_substnogrouponly{%
\CF_exptwomacroargs\CF_ifstartwith\CF_substcode\CF_substsubst
{\CF_grabfirstarg\CF_substcode\CF_temp
\CF_expafter{\futurelet\CF_nexttok\CF_gobtonil}\CF_substcode\relax\_nil
\CF_ifnum{0\CF_testifx=1 }% si le prochain token est \let-égal à 1...#1
{\edef\CF_nexttok{\CF_threeea\CF_firsttonil\expandafter\string\CF_substcode\_nil}% le détokéniser
\CF_ifnum{0\CF_testif=1 }
{\CF_eaddtotoks\CF_substtoks\CF_temp
\CF_grabfirstarg\CF_substcode\CF_temp
\CF_eaddtotoks\CF_substtoks\CF_temp
}
{\CF_eaddtotoks\CF_substtoks\CF_substpattern
}%
}
{\CF_eaddtotoks\CF_substtoks\CF_substpattern
}%
\CF_substgroups
}
{\CF_expsecond\CF_ifempty\CF_substcode
{\CF_atendsubstitute
}
{\CF_grabfirstarg\CF_substcode\CF_substauxarg
\CF_eaddtotoks\CF_substtoks\CF_substauxarg
\CF_substgroups
}%
}%
}
\def\CF_substall#1{% #1=macro
\def\CF_atendsubstitute{\edef#1{\the\CF_substtoks}}% macro exécutée à la fin
\let\CF_substnogroups\CF_substnogroupall
\CF_expsecond\CF_substi#1%
}
\def\CF_substnogroupall{%
\CF_exptwomacroargs\CF_ifstartwith\CF_substcode\CF_substsubst
{\CF_eaddtotoks\CF_substtoks\CF_substpattern
\CF_grabfirstarg\CF_substcode\CF_temp
\CF_substgroups
}
{\CF_expsecond\CF_ifempty\CF_substcode
{\CF_atendsubstitute
}
{\CF_grabfirstarg\CF_substcode\CF_substauxarg
\CF_eaddtotoks\CF_substtoks\CF_substauxarg
\CF_substgroups
}%
}%
}
\def\CF_substi#1#2#3{% #1=<texte> #2=<motif> #3=<motif de substi>
\def\CF_substcode{#1}\def\CF_substsubst{#2}\def\CF_substpattern{#3}%
\CF_substtoks={}%
\CF_substgroups
}
\def\CF_substgroups{%
\CF_expsecond\CF_ifbracefirst\CF_substcode
{\CF_grabfirstarg\CF_substcode\CF_substauxarg
\begingroup
\def\CF_atendsubstitute{%
\expandafter\endgroup\expandafter\CF_addtotoks\expandafter\CF_substtoks\expandafter{\expandafter{\the\CF_substtoks}}%
\CF_substgroups
}%
\CF_substtoks{}% initialiser à vide
\expandafter\def\expandafter\CF_substcode\CF_substauxarg
\CF_substgroups
}%
{\CF_substnogroups
}%
}
%---------------------------- Paramètres -----------------------------
\def\setchemfig{\setKV[chemfig]}
\def\resetchemfig{%
\setKVdefault[chemfig]{%
atom style ={},% code tikz mis à la fin de every node/.style
chemfig style ={},% code tikz mis à la fin de l'arugment optionnel de \tikzpicture
bond join =false,
fixed length =false,
cram rectangle =false,
cram width =1.5ex,
cram dash width =1pt,
cram dash sep =2pt,
atom sep =3em,
bond offset =2pt,
double bond sep =2pt,
angle increment =45,
node style ={},
bond style ={},
lewis | width =0.3ex,
lewis sep =0.4ex,
lewis length =1.5ex,
lewis style ={},
lewis dist =0.3em,
lewis radius =0.15ex,
lewis diag coeff =1,
cycle radius coeff =0.75,
stack sep =1.5pt,
scheme debug =false,
compound style ={},
compound sep =5em,
arrow offset =4pt,
arrow angle =0,
arrow coeff =1,
arrow style ={},
arrow double sep =2pt,
arrow double coeff =0.6,
arrow double harpoon=true,
arrow label sep =3pt,
arrow head =-CF,
+ sep left =0.5em,
+ sep right =0.5em,
+ vshift =0pt,
}%
}
\resetchemfig
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% D E S S I N M O L É C U L E S %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\CF_sanitizecatcode{%
\CF_makeother\[\CF_makeother\]\CF_makeother\:\CF_makeother\(\CF_makeother\)%
\CF_makeother\,\CF_makeother\-\CF_makeother\=\CF_makeother\~\CF_makeother\!%
\CF_makeother\?\CF_makeother\<\CF_makeother\>\CF_makeother\;\CF_makeother\*%
\CF_makeother\|\CF_makeother\#\CF_makeother\@%
}
\def\printatom#1{\ifmmode\rm#1\else$\rm#1$\fi}
\def\CF_nodecontent{\CF_expsecond\printatom{\csname atom_\number\CF_cntatom\endcsname\CF_nodestrut}}
\def\chemskipalign{%
\CF_doifempty\CF_bondoutcontentsaved% sauf si un \chemskipalign a été fait à l'atome précédent
{\global\let\CF_bondoutcontentsaved\CF_bondoutcontent}% sauvegarder l'atome d'où vient la liaison
\let\CF_nodestrut\empty
}
\def\definesubmol{\CF_definesubmoltrue\def_submol}
\def\redefinesubmol{\CF_definesubmolfalse\def_submol}
\def\def_submol#1{%
\CF_cntatomgroup=0 % nombre d'arguments supposé
\def\CF_temp{#1}% nom
\futurelet\CF_toksa\CF_submoltestnxttok
}
\def\CF_submoltestnxttok{%
\if[\noexpand\CF_toksa\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi
{\begingroup\CF_sanitizecatcode\CF_expsecond\CF_submolgrabopt{\CF_temp}%
}
{\afterassignment\CF_submoltestnxttoka% pas d'argument entre crochet
\CF_cntatomgroup=0% cherche le nombre d'arguments éventuels
}%
}
\def\CF_submoltestnxttoka{\futurelet\CF_toksa\CF_submoltestnxttokb}
\def\CF_submoltestnxttokb{%
\if[\noexpand\CF_toksa\expandafter\CF_execfirst\else\expandafter\CF_execsecond\fi
{\begingroup\CF_sanitizecatcode\CF_expsecond\CF_submolgrabopt{\CF_temp}}
{\CF_expsecond{\def_submola}\CF_temp{}}%
}
\def\CF_submolgrabopt#1[#2]#{\endgroup\def_submola{#1}{#2}}
\def\def_submola#1{% #1 nom
\CF_ifnum{0\CF_ifnum{\CF_cntatomgroup<0 }1{\CF_ifnum{\CF_cntatomgroup>9 }10}>0 }
{\CF_error{Invalid number of arguments in submol \detokenize\expandafter{\string#1}. Defining it with 0 argument}%
\CF_cntatomgroup=0
}
{}%
\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
{\expandafter\ifdefined\CF_firsttonil#1\_nil
\ifCF_definesubmol
\CF_warning{the submol \expandafter\string\CF_firsttonil#1\_nil\space is already defined, the previous definition is lost}%
\fi
\fi
\begingroup
\CF_sanitizecatcode
\def_submolb{#1}%
}
{\ifcsname CF__#1\endcsname
\ifCF_definesubmol
\CF_warning{the submol "#1" is already defined, the previous definition is lost}%
\fi
\fi
\begingroup
\CF_sanitizecatcode
\expandafter\def_submolb\csname CF__#1\endcsname
}%
}
\def\def_submolb#1#2#3{% #1 nom sous forme de macro, #2 = code si liaison arrive de droite , #3 = code si liaison arrive de gauche, \CF_cntatomgroup = nombre d'arguments
\def\CF_tempa{#2}\CF_doifnotempty{#2}{\CF_expsecond{\CF_expsecond\CF_substonly{\number\CF_cntatomgroup}\CF_tempa}{\CFhash}{\CFhash}}%
\def\CF_tempb{#3}\CF_expsecond{\CF_expsecond\CF_substonly{\number\CF_cntatomgroup}\CF_tempb}{\CFhash}{\CFhash}%
\CF_expsecond{\CF_expsecond{\def_submolc{#1}}\CF_tempa}\CF_tempb
}
\def\def_submolc#1#2#3{% #1 nom sous forme de macro, #2 = code si liaison arrive de droite , #3 = code si liaison arrive de gauche, \CF_cntatomgroup = nombre d'arguments
\endgroup
\begingroup
\global\toks0{\gdef\CFthesubmol}%
\CF_ifnum{\CF_cntatomgroup>0 }
{\foreach\CF_x in {1,...,\CF_cntatomgroup}{%
\global\toks0\expandafter{\expanded{\the\toks0\CFhash\CF_x}}%
}%
}
{}%
\CF_sanitizecatcode \catcode`\#6 \endlinechar-1 \everyeof{\noexpand}%
\CF_ifempty{#2}%
{\scantokens\expandafter{\the\toks0{\empty#3}}%
}%
{\scantokens\expandafter{%
\the\toks0{%
\csname CF_exec%
\ifdim\csname CF_currentangle\endcsname pt>90pt
\ifdim\csname CF_currentangle\endcsname pt<270pt
first%
\else
second%
\fi
\else
second%
\fi
\endcsname
{#2}{#3}%
}%
}%
}%
\endgroup
\let#1\CFthesubmol
}
\def\CF_seeknode#1#2#3{% cherche un noeud au début de #1 l'assigne dans la sc #2 et met le reste dans #3
\let#2\empty
\def#3{#1}%
\CF_iffirsttokmatch{#1}{ }%
{\CF_expsecond\CF_seeknodea{\romannumeral-`\.\noexpand#1}#2#3}% ignore les espaces au début du groupe d'atome
{\CF_seeknodea{#1}#2#3}%
}
\def\CF_seeknodea#1#2#3{%
\CF_ifempty{#1}%
{\let#3\empty
}
{\futurelet\CF_toksa\CF_gobtonil#1\relax\_nil
\CF_ifx\CF_toksa\CF_sptoken
{\CF_addtomacro#2{ }%
\CF_expsecond\CF_seeknodea{\CF_afterspace#1\_nil}#2#3%
}%
{\CF_ifx\CF_toksa\bgroup
{\CF_eaddtomacro#2{\expandafter{\CF_firsttonil#1\_nil}}%
\CF_expsecond\CF_seeknodea{\CF_gobarg#1}#2#3%
}%
{\CF_ifx!\CF_toksa% Bugfix v1.5
{\def\CF_seeksubmloltemp{#1}%
\CF_seeksubmola
\CF_expsecond\CF_seeknodea\CF_seeksubmloltemp#2#3%
}
{\CF_iffirsttokina{-=(*<>~}%
{\def#3{#1}%
}%
{\CF_eaddtomacro#2{\CF_firsttonil#1\_nil}%
\CF_expsecond\CF_seeknodea{\CF_gobarg#1}#2#3%
}%
}
}%
}%
}%
}
% on sait que #1 commence par -,=,~,<,>. On analyse cette liaison
% #2 reçoit le type de liaisons (1 pour -, 2 pour =, 3 pour ~)
\def\CF_assignbondcode#1#2{%
\futurelet\CF_toksa\CF_gobtonil#1\_nil
\edef#2{%
\ifx-\CF_toksa1\else
\ifx=\CF_toksa2\else
\ifx~\CF_toksa3\else
\ifx>\CF_toksa4\else
\ifx<\CF_toksa5\else0% si 0 --> il y a une erreur non due à l'utilisateur
\fi\fi\fi\fi\fi}%
\ifnum#2>3 % si c'est une liaison de Cram
\CF_expafter{\futurelet\CF_toksa\CF_gobtonil}{\CF_gobarg#1\_nil}% chope le caractère suivant
\CF_ifx:\CF_toksa
{\edef#2{\number\numexpr#2+2}% si c 'est un ":", signe du pointillé, ajoute 2
}%
{\CF_ifx|\CF_toksa% si c 'est un "|", signe du triangle évidé, ajouter 4
{\edef#2{\number\numexpr#2+4}}
{}%
}%
\fi
}
\def\CF_grabbondoffseta#1,#2\_nil{%
\def\CF_startoffset{#1}\def\CF_endoffset{#2}%
}
\def\CF_grabbondoffset#1(#2)#3\_nil{%
\CF_doifnotempty{#2}%
{\CF_ifinstr{#2},%
{\CF_grabbondoffseta#2\_nil}%
{\def\CF_startoffset{#2}}%
}%
\def\CF_remainafterbond{#3}%
}
\def\CF_analysebond#1#2{%
\CF_assignbondcode{#1}#2%
\CF_expsecond{\def\CF_remainafterbond}{\CF_gobarg#1}%mange le premier signe de la liaison
\let\CF_doublebondtype\CF_zero
\ifnum#2=2 % si c'est une double liaison, regarde s'il y a un + ou - derrière
\CF_expafter{\futurelet\CF_toksa\CF_gobtonil}{\CF_gobarg#1\_nil}%
\CF_ifx^\CF_toksa
{\def\CF_doublebondtype{1}%
\CF_expsecond{\def\CF_remainafterbond}{\CF_gobtwoargs#1}% mange le "^"
}
{\expandafter\ifx\CF_underscore\CF_toksa
\def\CF_doublebondtype{2}%
\CF_expsecond{\def\CF_remainafterbond}{\CF_gobtwoargs#1}% mange le "_"
\fi
}%
\else
\ifnum#2>5 % si c'est une laision de Cram pointillée ou triangle évidé
\CF_expsecond{\def\CF_remainafterbond}{\CF_gobtwoargs#1}% mange un caractère de plus
\fi
\fi
\CF_expsecond\CF_iffirsttokmatch\CF_remainafterbond\CFhash
{\CF_eexpsecond\CF_iffirsttokmatch{\expandafter\CF_gobarg\CF_remainafterbond.}(%si parenthèse juste après
{\expandafter\CF_grabbondoffset\CF_remainafterbond\_nil}
{}%
}%
{}%
\CF_expsecond\CF_iffirsttokmatch\CF_remainafterbond @%
{\expandafter\CF_grabmovearg\CF_remainafterbond\_nil}%
{}%
\CF_expsecond\CF_iffirsttokmatch{\CF_remainafterbond}[%
{\expandafter\CF_analyseoptarg\CF_remainafterbond\_nil\CF_remainafterbond
}%
{\let\CF_currentstringangle\CF_defaultstringangle
\let\CF_currentlength\CF_defaultlength
\let\CF_currentfromatom\CF_defaultfromatom
\let\CF_currenttoatom\CF_defaulttoatom
\let\CF_currenttikz\CF_defaulttikz
\let\CF_movebondname\empty
}%
\ifCF_incycle
\pgfmathsetmacro\CF_cycleincrementangle{360/\CF_cyclenum+\CF_initcycleangle}%
\edef\CF_currentstringangle{::+\CF_cycleincrementangle}%
\def\CF_initcycleangle{0}%
\let\CF_currentlength\CF_defaultlength% et on ignore la longueur de liaison spécifiée
\fi
\CF_expsecond\CF_setbondangle{\CF_currentstringangle}\CF_currentangle
}
\def\CF_setbondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
\CF_ifempty{#1}%
{\let#2\CF_defaultangle
}
{\if:\expandafter\noexpand\CF_firsttonil#1\_nil
\if:\CF_threeea\noexpand\expandafter\CF_firsttonil\CF_gobarg#1\_nil
\pgfmathsetmacro#2{\CF_previousangle+\expandafter\CF_gobarg\CF_gobarg#1}%
\else
\pgfmathsetmacro#2{\CF_gobarg#1}%
\fi
\else
\pgfmathsetmacro#2{#1*\CF_angleincrement}%
\fi% puis normalise l'angle entre 0 et 360
\ifdim\ifdim#2pt<0pt -\fi#2pt>360pt
\pgfmathsetmacro#2{#2-360*floor(#2/360)}%
\fi% si |#2|>360
\ifdim#2pt<0pt
\pgfmathsetmacro#2{#2+360}%
\fi
}%
}
\def\CF_analysemovearg#1,#2\_nil#3{%
\def#3{#1}\def\CF_movebondcoeff{#2}%
}
% 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.
\def\CF_grabmovearg @#1#2\_nil{%
\CF_ifinstr{#1},%
{\CF_analysemovearg#1\_nil\CF_movebondname}%
{\def\CF_movebondname{#1}\def\CF_movebondcoeff{0.5}}%
\def\CF_remainoptarg{#2}%
}
\def\CF_testemptyandassign#1#2#3{%
\CF_ifempty{#2}
{\let#1#3}
{\def#1{#2}}%
}
\def\CF_parseoptlist#1,#2,#3,#4,#5\_nil{%
\CF_testemptyandassign\CF_currentstringangle{#1}\CF_defaultstringangle
\CF_testemptyandassign\CF_currentlength {#2}\CF_defaultlength
\CF_testemptyandassign\CF_currentfromatom {#3}\CF_defaultfromatom
\CF_testemptyandassign\CF_currenttoatom {#4}\CF_defaulttoatom
\CF_expsecond{\CF_testemptyandassign\CF_currenttikz}{\CF_sanitizelastitem#5,\empty\_nil}\CF_defaulttikz
}%
\def\CF_analyseoptarg[#1]{%
\CF_doifnotempty{#1}%
{\CF_iffirsttokmatch{#1}{@}%
{\CF_grabmovearg#1\_nil
}
{\let\CF_movebondname\empty
\def\CF_remainoptarg{#1}%
}%
\expandafter\CF_parseoptlist\CF_remainoptarg,\empty,\empty,\empty,\empty\_nil
}%
\CF_analyseoptarga\relax
}
\def\CF_analyseoptarga#1\_nil#2{%
\CF_expsecond{\def#2}{\CF_gobarg#1}%
}
\def\CF_seeksubmol#1#2{% cherche et remplace ! au début de #1. #1=code #2=macro recevant le résultat
\def\CF_seeksubmloltemp{#1}%
\CF_seeksubmola
\let#2\CF_seeksubmloltemp
}
\def\CF_seeksubmola{%
\CF_expsecond{\def\CF_seeksubmloltemp}{\romannumeral-`\.\expandafter\noexpand\CF_seeksubmloltemp}%
\CF_expsecond\CF_iffirsttokmatch{\CF_seeksubmloltemp}!%
{\CF_eexpsecond{\def\CF_seeksubmloltemp}{\expandafter\CF_gobarg\CF_seeksubmloltemp}% enlève le "!"
\CF_ifx\empty\CF_seeksubmloltemp
{\CF_error{no submol name found after "!"}}
{}%
\ifcat\relax\CF_threeea\noexpand\expandafter\CF_firsttonil\CF_seeksubmloltemp*\_nil
\expandafter\CF_seeksubmolb\CF_seeksubmloltemp\_nil
\else
\expandafter\CF_seeksubmolc\CF_seeksubmloltemp\_nil
\fi
\CF_seeksubmola
}%
{}%
}
\def\CF_seeksubmolb#1{\CF_seeksubmold#1\relax}
\def\CF_seeksubmolc#1{\expandafter\CF_seeksubmold\csname CF__#1\endcsname\relax}% nom de la sous molécule
\def\CF_seeksubmold#1#2\_nil{%#1=macro de la sous molécule #2=reste du code commençant par \relax
\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
}
\def\CF_insertemptygroup#1{% insère {} au début de la sc #1
\CF_expsecond{\def#1}{\expandafter{\expandafter}#1}%
}
\def\chemfig{\CF_testopt\CF_chemfiga{}}
\def\CF_chemfiga[#1]{%
\begingroup
\CF_sanitizecatcode
\CF_exptwomacroargs\CF_chemfigb\CF_begintikzpicture\CF_endtikzpicture[#1]%
}
\def\CF_chemfigb#1#2[#3]#4{%
\endgroup
\begingroup
\setchemfig{#3}%
\CF_ifinsidetikz
{\pgfinterruptpicture
\let\CF_atendofchemfig\endpgfinterruptpicture
}
{\let\CF_atendofchemfig\relax
}%
\expanded{% début du tikzpicture
\unexpanded{#1}[%
remember picture,%
every node/.style={%
anchor=base,%
inner sep=0pt,%
outer sep=0pt,%
minimum size=0pt,%
\unexpanded\CF_threeea{\useKV[chemfig]{atom style}}%
},%
baseline,%
\unexpanded\CF_threeea{\useKV[chemfig]{chemfig style}}%
]%
}%
\begingroup% \endgroup rajouté en sortie de tracé par \CF_chemfigd
\let\CF_hooklist\empty
\ifboolKV[chemfig]{fixed length}
{\CF_macrofixedbondlengthtrue}
{\CF_macrofixedbondlengthfalse}%
\ifboolKV[chemfig]{bond join}
{\let\CF_drawaxisbond\CF_drawaxisbondjoin}
{\let\CF_drawaxisbond\CF_drawaxisbondnojoin}%
\ifboolKV[chemfig]{cram rectangle}
{\let\CF_clipcramornot\CF_gobtikzinstruction}
{\let\CF_clipcramornot\clip}%
\CF_valuetomacro[chemfig]\CF_crambasewidth [1.5ex]{cram width}%
\CF_valuetomacro[chemfig]\CF_cramdashlength [1pt]{cram dash width}%
\CF_valuetomacro[chemfig]\CF_cramdashsep [2pt]{cram dash sep}%
\CF_valuetomacro[chemfig]\CF_atomsep [3em]{atom sep}% espacement des atomes liés
\CF_valuetomacro[chemfig]\CF_bondoffset [2pt]{bond offset}%
\CF_valuetomacro[chemfig]\CF_doublesep [2pt]{double bond sep}%
\CF_valuetomacro[chemfig]\CF_angleincrement [45]{angle increment}%
\CF_valuetomacro[chemfig]\CF_nodestyle []{node style}%
\CF_valuetomacro[chemfig]\CF_bondstyle []{bond style}%
\CF_valuetomacro[chemfig]\CF_stacksep [1.5pt]{stack sep}%
\CF_valuetomacro[chemfig]\CF_cycleradiuscoeff[0.75]{cycle radius coeff}% coeff multiplicateur du rayon des arcs dans les cycles
\CF_incyclefalse
\CF_cntgroup0
\let\CF_lastaction\CF_zero% 0=début du dessin 1=tracé d'un noeud 2=tracé d'une liaison
\let\CF_startoffset\empty
\let\CF_endoffset\empty
\let\CF_bondoutcontentsaved\empty
\def\CF_cycleanglecorrection{180/\CF_cyclenum}%
\def\CF_defaultangle{0}%
\def\CF_defaultstringangle{:0}% angle pris par défaut si le champ est vide
\def\CF_defaultlength{1}%
\let\CF_defaultfromatom\empty% numero de l'atome d'où partent les liaisons par défaut
\let\CF_defaulttoatom\empty% numéro de l'atome où arrivent les laisons par défaut
\let\CF_defaulttikz\empty
\let\CF_previousbondangle\empty
\let\CF_joinbond\CF_zero
\let\CF_previoustikz\empty
\everyeof{\_nil}\endlinechar-1
\CF_sanitizecatcode
\expandafter\CF_assigntonil\expandafter\CF_molecule\scantokens{#4}%
\CF_expsecond{\CF_substall\CF_molecule}\CFhash\CFhash
\CF_expsecond\CF_chemfigc{\CF_molecule}%
%\endgroup <-- rajouté par \CF_chemfigd
#2% fin du tikzpicture
\CF_atendofchemfig
\endgroup
\let\CF_flipstate\CF_zero
}
\def\CF_chemfigc#1{% #1 est le code de la molécule
\ifnum\CF_lastaction=3
\ifCF_incycle
\def\CF_defaultangle{0}%
\else
\ifnum\CF_cntcycle=0 % si c'est le début d'un cycle
\pgfmathsetmacro\CF_defaultangle{\CF_previousangle+180+\CF_cycleanglecorrection}% on met la liaison à +180° + correction
\else
\pgfmathsetmacro\CF_defaultangle{\CF_previousangle-90+180/\CF_cyclenum}% sinon à la bissectrice du sommet du cycle
\fi
\fi
\let\CF_defaultstringangle\empty
\fi
\let\CF_currentangle\CF_defaultangle
\def\CF_molecule{#1}%
\CF_expsecond\CF_seeksubmol\CF_molecule\CF_molecule% alias en premier ?
\if[\CF_threeea\noexpand\expandafter\CF_firsttonil\CF_molecule\_nil
\expandafter\CF_analyseoptarg\CF_molecule\_nil\CF_molecule
\CF_expsecond\CF_setbondangle{\CF_currentstringangle}\CF_currentangle
\let\CF_defaultangle\CF_currentangle
\let\CF_previousangle\CF_currentangle
\CF_doifnotempty\CF_currentstringangle{\let\CF_defaultangle\CF_currentangle}%
\CF_doifnotempty\CF_currentlength {\let\CF_defaultlength\CF_currentlength}%
\CF_doifnotempty\CF_currentfromatom {\let\CF_defaultfromatom\CF_currentfromatom}%
\CF_doifnotempty\CF_currenttoatom {\let\CF_defaulttoatom\CF_currenttoatom}%
\CF_doifnotempty\CF_currenttikz {\let\CF_defaulttikz\CF_currenttikz}%
\CF_expsecond\CF_seeksubmol\CF_molecule\CF_molecule
\fi
\edef\CF_defaultstringangle{:\CF_defaultangle}%
\let\CF_currentlength\CF_defaultlength
\let\CF_currentfromatom\CF_defaultfromatom
\let\CF_currenttoatom\CF_defaulttoatom
\let\CF_currenttikz\CF_defaulttikz
\ifCF_incycle% si on commence un cycle
\let\CF_currentangle\CF_previousangle
\ifCF_cyclearc% on doit tracer l'arc de cercle dans le cycle ?
\pgfmathsetmacro\CF_cyclearcradius{\CF_cycleradiuscoeff*\CF_currentlength*\CF_atomsep/(2*tan(180/\CF_cyclenum))}%
\pgfmathsetmacro\CF_cyclearcinitangle{\CF_currentangle+\CF_initcycleangle+180/\CF_cyclenum+90}
\pgfmathparse{\CF_currentlength*\CF_atomsep/(2*sin(180/\CF_cyclenum))}%
\node[at=(\CF_bondoutnode),shift=(\CF_cyclearcinitangle:\pgfmathresult pt)](arccenter){};% le centre de l'arc
\node[at=(arccenter),shift=(\CF_cyclearcstartangle:\CF_cyclearcradius pt)](initarc){};% le début de l'arc
\CF_expafter{\draw[}\CF_cyclearcdirecttikz](initarc) arc (\CF_cyclearcstartangle:\CF_cyclearcendangle:\CF_cyclearcradius pt);
\fi
\else
\let\CF_currentangle\CF_defaultangle
\fi
\ifnum\CF_lastaction=0
\let\CF_previousangle\CF_defaultangle
\node(CF_node){};
\CF_expsecond\CF_iffirsttokin{\CF_molecule}{-=(*~?<>}%
{\CF_insertemptygroup\CF_molecule}%
{}%
\fi
\CF_chemfigd
}
\def\CF_chemfigd{%
\let\CF_nextaction\CF_chemfigd% à priori, on reboucle
\CF_ifx\CF_molecule\empty
{\let\CF_nextaction\endgroup
}
{\CF_expsecond\CF_seeknode{\CF_molecule}\CF_currentatomgroup\CF_molecule
\CF_ifx\empty\CF_currentatomgroup% pas de noeud pour commencer ?
{\def\CF_bondoutnode{%
n\CF_lastgroupnumber-%
\ifx\CF_currentfromatom\empty
\ifdim\CF_currentangle pt<90pt
\number\CF_cntatomgroup
\else
\ifdim\CF_currentangle pt>270pt
\number\CF_cntatomgroup
\else
1%
\fi
\fi
\else
\CF_currentfromatom
\fi}%
\CF_expafter{\futurelet\CF_toksa\CF_gobtonil}{\CF_molecule\relax\_nil}%
\CF_iffirsttokina{-=<>~}% la suite est une liaison
{\ifnum\CF_lastaction=2 % c'est la deuxième liaison consécutive ?
\CF_insertemptygroup\CF_molecule% insère un groupe vide
\edef\CF_bondoutnode{\CF_bondoutnode}%
\else
\ifCF_incycle
\advance\CF_cntcycle1
\fi
\CF_expsecond\CF_analysebond{\CF_molecule}\CF_bondtype
\edef\CF_bondoutnode{\CF_bondoutnode}%
\let\CF_molecule\CF_remainafterbond
\ifCF_incycle
\ifnum\CF_cntcycle=\CF_cyclenum\relax
\CF_threeea\CF_execfirst
\else
\ifnum\CF_cntcycle=1
\let\CF_cyclefirsttikz\CF_currenttikz
\CF_doifnotempty\CF_startoffset{\let\CF_cyclejoinlast\CF_zero}%
\fi
\CF_threeea\CF_execsecond
\fi
\else
\expandafter\CF_execsecond
\fi
{\let\CF_nextaction\endgroup
\CF_drawbond\CF_bondtype{\CF_bondoutnode}{\CF_hookcycle}\CF_previousatomgroup\CF_hookatomgroup
}%
{\node[at=(\CF_bondoutnode\ifCF_incycle\else\ifCF_macrofixedbondlength.\CF_currentangle\fi\fi),shift=(\ifcase\CF_flipstate\or180-\or-\fi\CF_currentangle:\CF_currentlength*\CF_atomsep)](CF_node){};
\let\CF_previousangle\CF_currentangle
\def\CF_lastaction{2}%
}%
\fi
\ifcat\relax\detokenize\expandafter{\romannumeral-`\.\expandafter\noexpand\CF_molecule}\relax
% s'il ne reste plus rien après la liaison (sans tenir compte de l'espace devant)-> insère un groupe vide
\CF_insertemptygroup\CF_molecule
\fi
}%
{\edef\CF_bondoutnode{\CF_bondoutnode}% évalue le l'atome de départ de liaison
\CF_ifx(\CF_toksa% une parenthèse pour commencer ?
{\ifnum\CF_lastaction=2 % il y avait une liaison juste avant ?
\CF_insertemptygroup\CF_molecule
\else
\CF_expsecond\CF_grabsubmol{\CF_molecule}%
\begingroup
\ifCF_incycle\def\CF_lastaction{3}\fi% on était dans un cycle
\CF_incyclefalse
\aftergroup\CF_chemfigd
\def\CF_nextaction{\CF_expsecond\CF_chemfigc{\CF_molinparen}}%
\fi
}%
{\CF_ifx\CF_molecule\empty
{\let\CF_nextaction\endgroup
}
{% ce qui reste après le noeud courant n'est pas vide, ne commence pas par "-=~", ni par une parenthèse
\CF_ifx*\CF_toksa% un cycle ?
{\ifnum\CF_lastaction=2
\CF_insertemptygroup\CF_molecule% insère un groupe vide
\else
\ifCF_incycle
\def\CF_lastaction{3}%
\fi% on était dans un cycle
\ifnum\CF_lastaction=3
\let\CF_lastcyclenum\CF_cyclenum
\fi
\CF_eexpsecond\CF_iffirsttokmatch{\expandafter\CF_gobarg\CF_molecule}*%
{\CF_eexpsecond{\def\CF_molecule}{\expandafter\CF_gobarg\CF_molecule}% enlève la 1er étoile
\CF_eexpsecond\CF_iffirsttokmatch{\expandafter\CF_gobarg\CF_molecule}[% un crochet ensuite ?
{\expandafter\CF_cycleparsepreamblewithoptarg\CF_molecule\_nil% \begingroup inclus
}%
{\def\CF_cyclearcstartangle{0}\def\CF_cyclearcendangle{360}%
\let\CF_cyclearcdirecttikz\empty
\expandafter\CF_cycleparsepreamble\CF_molecule\_nil% \begingroup inclus
}%
\CF_cyclearctrue
}%
{\expandafter\CF_cycleparsepreamble\CF_molecule\_nil% \begingroup inclus
\CF_cyclearcfalse
}%
\CF_cntcycle0
\edef\CF_hookcycle{\CF_bondoutnode}%
\let\CF_hookatomgroup\CF_previousatomgroup
\CF_ifzerodim\CF_hookatomgroup
{\def\CF_cyclejoinlast{1}}% joindre le dernier
{\def\CF_cyclejoinlast{0}}%
\CF_incycletrue
\ifnum\CF_lastaction=3
\pgfmathsetmacro\CF_initcycleangle{360/\CF_lastcyclenum-180}% c'est un cycle dans un cycle
\else
\pgfmathsetmacro\CF_initcycleangle{-180/\CF_cyclenum-90+\CF_cycleanglecorrection}%
\fi
\aftergroup\CF_chemfigd
\def\CF_nextaction{\CF_expsecond\CF_chemfigc{\CF_molinparen}}%
\fi
}%
{\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}%
}%