summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/chemmacros/chemmacros.module.polymers.code.tex
blob: 8c93ff002cc99726acb80ca91c4e4c5841518f73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
% --------------------------------------------------------------------------
%
% the CHEMMACROS package -- module: `polymers'
%
% --------------------------------------------------------------------------
% 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-2017 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{polymers}{2016/03/08 polymers}

\chemmacros_load_modules:n {nomenclature,tikz}

% --------------------------------------------------------------------------
% copolymers
\NewChemIUPAC \copolymer { \textit {co} }
\LetChemIUPAC \co \copolymer

\NewChemIUPAC \statistical { \textit {stat} }
\LetChemIUPAC \stat \statistical

\NewChemIUPAC \random { \textit {ran} }
\LetChemIUPAC \ran \random

\NewChemIUPAC \alternating { \textit {alt} }
\LetChemIUPAC \alt \alternating

\NewChemIUPAC \periodic { \textit {per} }
\LetChemIUPAC \per \periodic

\NewChemIUPAC \block { \textit {block} }
\NewChemIUPAC \graft { \textit {graft} }

% --------------------------------------------------------------------------
% non-linear (co)polymers
\NewChemIUPAC \blend { \textit {blend} }
\NewChemIUPAC \comb { \textit {comb} }

\NewChemIUPAC \complex { \textit {compl} }
\LetChemIUPAC \compl \complex

\NewChemIUPAC \cyclic { \textit {cyclo} }
\LetChemIUPAC \cyclo \cyclic

\NewChemIUPAC \branch { \textit {branch} }
\NewChemIUPAC \network { \textit {net} }
\LetChemIUPAC \net \network

\NewChemIUPAC \ipnetwork { \textit {ipn} }
\LetChemIUPAC \ipn \ipnetwork

\NewChemIUPAC \sipnetwork { \textit {sipn} }
\LetChemIUPAC \sipn \sipnetwork

\NewChemIUPAC \star { \textit {star} }

% --------------------------------------------------------------------------

\tl_new:N \l__chemmacros_polymer_delimiter_left_tl
\tl_new:N \l__chemmacros_polymer_delimiter_right_tl

\tl_new:N \l__chemmacros_polymer_subscript_tl
\tl_new:N \l__chemmacros_polymer_superscript_tl

\dim_new:N \l__chemmacros_polymer_delimiter_height_dim
\dim_new:N \l__chemmacros_polymer_delimiter_depth_dim

\cs_new_protected:Npn \__chemmacros_set_polymer_delimiters:NN #1#2
  {
    \tl_set:Nn \l__chemmacros_polymer_delimiter_left_tl  {#1}
    \tl_set:Nn \l__chemmacros_polymer_delimiter_right_tl {#2}
  }

% #1: height
% #2: depth
% #3: opening node
% #4: closing node
% #5: subscript
% #6: superscript 
\cs_new_protected:Npn \chemmacros_make_polymer_braces:nnnnnn #1#2#3#4#5#6
  {
    \dim_set:Nn \l__chemmacros_polymer_delimiter_height_dim { (#1+#2)/2 }
    \dim_set:Nn \l__chemmacros_polymer_delimiter_depth_dim  { (#1-#2)/2 }
    \chemmacros_tikz_picture:nn {remember~ picture, overlay }
      {
        \chemmacros_tikz_node:n
          { at = (#3) , yshift = \l__chemmacros_polymer_delimiter_depth_dim }
          {
            \c_math_toggle_token
              \tex_left:D \l__chemmacros_polymer_delimiter_left_tl
              \tex_vrule:D
                height \l__chemmacros_polymer_delimiter_height_dim
                depth \l__chemmacros_polymer_delimiter_height_dim
                width \c_zero_dim
              \tex_right:D .
            \c_math_toggle_token
          } ;
        \chemmacros_tikz_node:n
          { at = (#4) , yshift = \l__chemmacros_polymer_delimiter_depth_dim }
          {
            \c_math_toggle_token
              \tex_left:D .
              \tex_vrule:D
                height \l__chemmacros_polymer_delimiter_height_dim
                depth \l__chemmacros_polymer_delimiter_height_dim
                width \c_zero_dim
              \tex_right:D \l__chemmacros_polymer_delimiter_right_tl
              \c_math_subscript_token   { \hbox_overlap_right:n {#5} }
              \c_math_superscript_token { \hbox_overlap_right:n {#6} }
            \c_math_toggle_token
          } ;
      }
  }
\cs_generate_variant:Nn \chemmacros_make_polymer_braces:nnnnnn {nnnnVV}

\chemmacros_define_keys:nn {polymers}
  {
    delimiters  .code:n = \__chemmacros_set_polymer_delimiters:NN #1 ,
    delimiters  .initial:n = [] ,
    superscript .tl_set:N = \l__chemmacros_polymer_superscript_tl ,
    subscript   .tl_set:N = \l__chemmacros_polymer_subscript_tl ,
    subscript   .initial:n = $n$
  }

\NewDocumentCommand \makepolymerdelims {O{}momm}
  {
    \group_begin:
      \chemmacros_set_keys:nn {polymers} {#1}
      \IfNoValueTF {#3}
        {
          \chemmacros_make_polymer_braces:nnnnVV {#2} {#2} {#4} {#5}
            \l__chemmacros_polymer_subscript_tl
            \l__chemmacros_polymer_superscript_tl
        }
        {
          \chemmacros_make_polymer_braces:nnnnVV {#2} {#3} {#4} {#5}
            \l__chemmacros_polymer_subscript_tl
            \l__chemmacros_polymer_superscript_tl
        }
    \group_end:
  }
  
% --------------------------------------------------------------------------
\tex_endinput:D

2016/03/07 - first version
2016/03/08 - \makepolymerdelims