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
|
% --------------------------------------------------------------------------
%
% the CHEMMACROS package -- module: `newman'
%
% --------------------------------------------------------------------------
% Clemens Niederberger
% --------------------------------------------------------------------------
% https://github.org/cgnieder/chemmacros/
% contact@mychemistry.eu
% --------------------------------------------------------------------------
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% --------------------------------------------------------------------------
% Copyright 2011-2016 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clemens Niederberger.
% --------------------------------------------------------------------------
\ChemModule{newman}{2016/04/23 newman projections}
\chemmacros_load_module:n {tikz}
% Newman projections
\fp_new:N \l__chemmacros_newman_rel_angle_fp
\fp_zero:N \l__chemmacros_newman_rel_angle_fp
\fp_new:N \l__chemmacros_newman_tmp_angle_fp
\fp_new:N \l__chemmacros_newman_abs_angle_fp
\fp_zero:N \l__chemmacros_newman_abs_angle_fp
\fp_new:N \l__chemmacros_newman_scale_fp
\fp_set:Nn \l__chemmacros_newman_scale_fp {1}
\fp_new:N \l__chemmacros_newman_x_fp
\fp_new:N \l__chemmacros_newman_y_fp
\tl_new:N \l__chemmacros_newman_tikz_ring_tl
\tl_new:N \l__chemmacros_newman_tikz_front_tl
\tl_new:N \l__chemmacros_newman_tikz_back_tl
\bool_new:N \l__chemmacros_newman_tikz_back_bool
\chemmacros_define_keys:nn {newman}
{
ring .tl_set:N = \l__chemmacros_newman_tikz_ring_tl ,
atoms .tl_set:N = \l__chemmacros_newman_tikz_front_tl ,
back-atoms .code:n =
{
\bool_set_true:N \l__chemmacros_newman_tikz_back_bool
\tl_set:Nn \l__chemmacros_newman_tikz_back_tl { #1 }
} ,
scale .fp_set:N = \l__chemmacros_newman_scale_fp ,
scale .default:n = 1 ,
angle .fp_set:N = \l__chemmacros_newman_abs_angle_fp ,
angle .default:n = 0
}
% \newman[<keyval>](<angle>){<1>,<2>,<3>,<4>,<5>,<6>}
\NewDocumentCommand \newman {od()m}
{
\group_begin:
\IfNoValueF {#1} { \chemmacros_set_keys:nn {newman} {#1} }
\IfNoValueTF {#2}
{ \chemmacros_newman:nn { } {#3} }
{ \chemmacros_newman:nn {#2} {#3} }
\group_end:
}
% #1: angle
% #2: csv list of atoms
\cs_new_protected:Npn \chemmacros_newman:nn #1#2
{ \__chemmacros_newman_feed_atoms:nw {#1}#2 ,,,,,, \q_stop }
\cs_new_protected:Npn \__chemmacros_newman_feed_atoms:nw #1#2,#3,#4,#5,#6,#7,#8 \q_stop
{ \chemmacros_newman_atoms:nnnnnnn {#1} {#2} {#3} {#4} {#5} {#6} {#7} }
% place atoms:
% #1: angle
% #2 - #7: atoms
\cs_new_protected:Npn \chemmacros_newman_atoms:nnnnnnn #1#2#3#4#5#6#7
{
\tl_if_blank:nTF {#1}
{
\fp_set_eq:NN
\l__chemmacros_newman_rel_angle_fp
\l__chemmacros_newman_abs_angle_fp
}
{ \fp_set:Nn \l__chemmacros_newman_rel_angle_fp {#1} }
\chemmacros_tikz_picture:xn
{
scale = \fp_to_decimal:N \l__chemmacros_newman_scale_fp ,
chemmacros_newman_atom_front / .style =
{
inner~sep = 0pt ,
outer~sep = 0pt ,
\exp_not:V \l__chemmacros_newman_tikz_front_tl
},
chemmacros_newman_atom_back / .style =
{
inner~sep = 0pt ,
outer~sep = 0pt ,
\bool_if:NTF \l__chemmacros_newman_tikz_back_bool
{ \exp_not:V \l__chemmacros_newman_tikz_back_tl }
{ \exp_not:V \l__chemmacros_newman_tikz_front_tl }
}
}
{
\chemmacros_tikz_draw:x
{ \exp_not:V \l__chemmacros_newman_tikz_ring_tl }
(0pt,0pt) circle (\fp_to_dim:N \l__chemmacros_newman_scale_fp * 15) ;
\chemmacros_newman_back_node:nn {30} {#6}
\chemmacros_newman_back_node:nn {150} {#7}
\chemmacros_newman_back_node:nn {270} {#5}
\chemmacros_newman_front_node:nn {90} {#2}
\chemmacros_newman_front_node:nn {210} {#3}
\chemmacros_newman_front_node:nn {330} {#4}
}
}
% provide cartesian coordiantes from polar coordinates
% #1: fp variable for x
% #2: fp variable for y
% #3: angle
% #4: radius
\cs_new_protected:Npn \chemmacros_polar_to_cartesian:NNnn #1#2#3#4
{
\fp_set:Nn #1 { #4 * cos( #3 / 180 * pi ) }% x
\fp_set:Nn #2 { #4 * sin( #3 / 180 * pi ) }% y
}
% place back nodes
\cs_new_protected:Npn \chemmacros_newman_back_node:nn #1#2
{
\group_begin:
\fp_add:Nn \l__chemmacros_newman_rel_angle_fp { #1 }
\chemmacros_polar_to_cartesian:NNnn
\l__chemmacros_newman_x_fp
\l__chemmacros_newman_y_fp
{ \l__chemmacros_newman_rel_angle_fp }
{ \l__chemmacros_newman_scale_fp }
\chemmacros_tikz_draw:x
{ \exp_not:V \l__chemmacros_newman_tikz_ring_tl }
(
15 * \fp_to_dim:N \l__chemmacros_newman_x_fp ,
15 * \fp_to_dim:N \l__chemmacros_newman_y_fp
)
--
(
30 * \fp_to_dim:N \l__chemmacros_newman_x_fp ,
30 * \fp_to_dim:N \l__chemmacros_newman_y_fp
) ;
\chemmacros_polar_to_cartesian:NNnn
\l__chemmacros_newman_x_fp
\l__chemmacros_newman_y_fp
{ \l__chemmacros_newman_rel_angle_fp }
{ \l__chemmacros_newman_scale_fp }
\chemmacros_tikz_node:x
{
chemmacros_newman_atom_back,
anchor = -180 + \fp_to_int:N \l__chemmacros_newman_rel_angle_fp
}
at
(
31 * \fp_to_dim:N \l__chemmacros_newman_x_fp ,
31 * \fp_to_dim:N \l__chemmacros_newman_y_fp
)
{ #2 } ;
\group_end:
}
\cs_generate_variant:Nn \chemmacros_newman_back_node:nn { nf }
% place front nodes:
\cs_new_protected:Npn \chemmacros_newman_front_node:nn #1#2
{
\chemmacros_polar_to_cartesian:NNnn
\l__chemmacros_newman_x_fp
\l__chemmacros_newman_y_fp
{ #1 }
{ \l__chemmacros_newman_scale_fp }
\chemmacros_tikz_draw:x
{ \exp_not:V \l__chemmacros_newman_tikz_ring_tl }
(0pt,0pt) -- ++
(
30 * \fp_to_dim:N \l__chemmacros_newman_x_fp ,
30 * \fp_to_dim:N \l__chemmacros_newman_y_fp
) ;
\chemmacros_polar_to_cartesian:NNnn
\l__chemmacros_newman_x_fp
\l__chemmacros_newman_y_fp
{ #1 }
{ \l__chemmacros_newman_scale_fp }
\chemmacros_tikz_node:x
{ chemmacros_newman_atom_front, anchor = -180 + #1 }
at
(
31 * \fp_to_dim:N \l__chemmacros_newman_x_fp ,
31 * \fp_to_dim:N \l__chemmacros_newman_y_fp
)
{ #2 } ;
}
\cs_generate_variant:Nn \chemmacros_newman_front_node:nn { nf }
% --------------------------------------------------------------------------
\tex_endinput:D
2016/04/23 - some changes on how \newman is processed internally
|