Debian Codegraph @

texmf-dist/tex/latex/ecgdraw/ecgdraw.sty

raw
1 %%
2 %% This is file `ecgdraw.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% ecgdraw.dtx (with options: `package')
8 %% ________________________________________
9 %% A package to draw ECG.
10 %% Copyright (C) 2016 Marco Scavino and Ezio Aimé
11 %% All rights reserved
12 %% License information appended
13 \NeedsTeXFormat{LaTeX2e}[2009/01/01]
14 \ProvidesPackage{ecgdraw}[2016/06/29 v.1.0 Draw ECG]
15 \RequirePackage{tikz}
16 \RequirePackage{xparse}
17
18 \usetikzlibrary{calc}
19
20 \pgfdeclarelayer{sk@back}
21 \pgfsetlayers{sk@back,main}
22 \ExplSyntaxOn
23
24 \bool_new:N \sk_ECG_breaklines_bool
25 \bool_new:N \sk_ECG_breaklines_arrow_bool
26
27 \tikzset {
28 breakindent / .store ~ in = \sk_ECG_breakindent_tl ,
29 breakindent = 1cm,
30 breaklines / .is ~ choice,
31 breaklines / true / .code = \bool_set_true:N \sk_ECG_breaklines_bool ,
32 breaklines / false / .code = \bool_set_false:N \sk_ECG_breaklines_bool ,
33 breaklines / arrow / .code =
34 \bool_set_true:N \sk_ECG_breaklines_bool
35 \bool_set_true:N \sk_ECG_breaklines_arrow_bool ,
36 breaklines / no ~ indent /.code =
37 \bool_set_true:N \sk_ECG_breaklines_bool
38 \tl_set:Nn \sk_ECG_breakindent_tl { 0 } ,
39 breaklines / .default = true,
40 breaklines = false,
41 ECG ~ title / .store ~ in = \sk_ECG_title_tl,
42 ECG ~ title = {},
43 ECG ~ title ~ align / .is~choice ,
44 ECG ~ title ~ align / center / .code = \tl_set:Nn \sk_ECG_title_align_tl { north } \tl_set:Nn \sk_ECG_title_anchor_tl { south } ,
45 ECG ~ title ~ align / right / .code = \tl_set:Nn \sk_ECG_title_align_tl { north ~ east } \tl_set:Nn \sk_ECG_title_anchor_tl { south ~ east } ,
46 ECG ~ title ~ align / left / .code = \tl_set:Nn \sk_ECG_title_align_tl { north ~ west } \tl_set:Nn \sk_ECG_title_anchor_tl { south ~ west } ,
47 ECG ~ title ~ align = left ,
48 grid ~ border / .code =
49 \tl_set:Nn \sk_ECG_gridtp_tl { #1 }
50 \tl_set:Nn \sk_ECG_gridlf_tl { #1 }
51 \tl_set:Nn \sk_ECG_gridrg_tl { #1 }
52 \tl_set:Nn \sk_ECG_gridbt_tl { #1 },
53 grid ~ top / .store ~ in = \sk_ECG_gridtp_tl,
54 grid ~ bottom / .store ~ in = \sk_ECG_gridbt_tl,
55 grid ~ left / .store ~ in = \sk_ECG_gridlf_tl,
56 grid ~ right / .store ~ in = \sk_ECG_gridrg_tl,
57 grid ~ border = .2cm,
58 }
59
60 \bool_new:N \sk_ECG_start_bool
61
62 \DeclareDocumentCommand \ECG { O{} m }
63 {
64 \begin{tikzpicture}
65 \coordinate(sk_end) at (0,0);
66 \sk_ECG:nn { #1 } { #2 }
67 \end{tikzpicture}
68 }
69
70 \cs_set_nopar:Npn \sk_ECG_env:nnn #1 #2 #3
71 {
72 \tl_if_empty:nTF { #2 }
73 { \coordinate(sk_end) at (0,\sk_ECG_yshift_dim); }
74 { \coordinate(sk_end) at (#2); }
75 \sk_ECG:nn { #1 } { #3 }
76 \dim_set:Nn \sk_ECG_yshift_dim { \sk_ECG_yshift_dim - 2.5cm }
77 }
78
79 \dim_new:N \sk_ECG_yshift_dim
80 \dim_new:N \sk_ECG_x_dim
81 \int_new:N \sk_ECG_row_int
82 \int_new:N \sk_ECG_wave_int
83
84 \DeclareDocumentEnvironment { ecg } { O{} }
85 {
86 \int_zero:N \sk_ECG_row_int
87 \int_zero:N \sk_ECG_wave_int
88 \dim_zero:N \sk_ECG_yshift_dim
89 \DeclareDocumentCommand \ECG { O{} D(){} m }
90 {
91 \dim_zero:N \sk_ECG_x_dim
92 \int_incr:N \sk_ECG_row_int
93 \sk_ECG_env:nnn { ##1 } { ##2 } { ##3 }
94 }
95 \begin{center}
96 \begin{tikzpicture}[#1]
97 }
98
99 {
100 \tl_if_empty:NF \sk_ECG_title_tl
101 { \node at (current ~ bounding ~ box.\sk_ECG_title_align_tl) [inner ~ sep=\c_zero_dim,anchor=\sk_ECG_title_anchor_tl] {\sk_ECG_title_tl}; }
102 \begin{pgfonlayer}{sk@back}
103 \coordinate(grid_start) at ([xshift=-\sk_ECG_gridlf_tl,
104 yshift=-\sk_ECG_gridbt_tl] current ~ bounding ~ box. south ~ west);
105 \coordinate(grid_stop) at ([xshift=\sk_ECG_gridrg_tl,
106 yshift=\sk_ECG_gridtp_tl] current ~ bounding ~ box.north ~ east);
107 \draw[color=red!20,step=0.1cm,very ~ thin]
108 (grid_start) grid (grid_stop);
109 \draw [color=red!50,step=.5cm](grid_start)grid(grid_stop);
110 \end{pgfonlayer}
111 \end{tikzpicture}
112 \end{center}
113 }
114
115 \DeclareDocumentEnvironment { ecg* } { O{} }
116 {
117 \int_zero:N \sk:ECG_row_int
118 \int_zero:N \sk:ECG_wave_int
119 \dim_zero:N \sk_ECG_yshift_dim
120 \DeclareDocumentCommand \ECG { O{} D(){} m }
121 {
122 \dim_zero:N \sk_ECG_x_dim
123 \int_incr:N \sk_ECG_row_int
124 \sk_ECG_env:nnn { ##1 } { ##2 } { ##3 }
125 }
126 \begin{tikzpicture}[#1]
127 }
128 {
129 \tl_if_empty:NF \sk_ECG_title_tl
130 { \node at (current ~ bounding ~ box.\sk_ECG_title_align_tl) {\sk_ECG_title_tl}; }
131 \begin{pgfonlayer}{sk@back}
132 \coordinate(grid_start) at ([xshift=-\sk_ECG_gridlf_tl,
133 yshift=-\sk_ECG_gridbt_tl] current ~ bounding ~ box. south ~ west);
134 \coordinate(grid_stop) at ([xshift=\sk_ECG_gridrg_tl,
135 yshift=\sk_ECG_gridtp_tl] current ~ bounding ~ box.north ~ east);
136 \draw[color=red!20,step=0.1cm,very ~ thin]
137 (grid_start) grid (grid_stop);
138 \draw [color=red!50,step=.5cm](grid_start)grid(grid_stop);
139 \end{pgfonlayer}
140 \end{tikzpicture}
141 }
142
143 \seq_new:N \sk_ECG_seq
144
145 \cs_set_nopar:Npn \sk_ECG:nn #1 #2
146 {
147 \tl_clear:N \sk_ECG_onda_tl
148 \seq_clear:N \sk_ECG_seq
149 \bool_set_true:N \sk_ECG_start_bool
150 \seq_set_split:Nnn \sk_ECG_seq { , } { #2 }
151 \seq_map_inline:Nn \sk_ECG_seq { \sk_ECG_use:w ##1 \q_nil { #1 } }
152 }
153
154 \DeclareDocumentCommand \sk_ECG_use:w { O{} m u\q_nil m }
155 {
156 \int_incr:N \sk_ECG_wave_int
157 \tl_set:Nn \sk_ECG_onda_tl
158 { \draw[thick,rounded ~ corners=0.25mm,line ~ cap=round, shift=(sk_end),
159 #4,#1] }
160 \str_case:nn { #2 }
161 {
162 { ! } { \tl_put_right:Nx \sk_ECG_onda_tl
163 {
164 \cs_if_exist_use:cF { sk_ECG_ #3 } { (0,0) }
165 } }
166 { ? } { \sk_ECG_onda_label:w #3 \q_nil }
167 { i } { \sk_ECG_onda_iso:w #3 \q_nil }
168 { p } { \sk_ECG_onda_p:nnnw #3 \q_nil }
169 { q } { \sk_ECG_onda_q:nw #3 \q_nil }
170 { r } { \sk_ECG_onda_r:nw #3 \q_nil }
171 { s } { \sk_ECG_onda_s:nw #3 \q_nil }
172 { t } { \sk_ECG_onda_t:nw #3 \q_nil }
173 { T } { \tl_put_right:Nx \sk_ECG_onda_tl
174 { (0,0) -- (.1cm,0) -- (.1cm,#3*1cm) -- (.5cm,#3*1cm) -- (.5,0)
175 -- (1,0) } }
176 { * } { \int_decr:N \sk_ECG_wave_int \sk_ECG_onda_ripeti:nw #3 \q_nil { #4 } \tracingmacros=0}
177 }
178 \tl_put_right:Nn \sk_ECG_onda_tl { coordinate (sk_end)
179 let \p1=(current ~ path ~ bounding ~ box.south ~ west),
180 \p2=(current ~ path ~ bounding ~ box.north ~ east)
181 in ~
182 node (ecg-\int_use:N \sk_ECG_row_int-\int_use:N \sk_ECG_wave_int)
183 [at=(current ~ path ~ bounding ~ box),text ~ width=\x2-\x1,text ~ height=\y2-\y1]{}
184 ; }
185
186 \str_if_eq:nnF { #2 } { * } { \sk_ECG_onda_tl }
187 \bool_if:NT \sk_ECG_breaklines_bool
188 { \pgfgetlastxy{\sk_ECG_lastx_tl}{\sk_ECG_lasty_tl}
189 \dim_set:Nn \l_tmpa_dim
190 { \textwidth - \sk_ECG_gridlf_tl - \sk_ECG_gridrg_tl - \sk_ECG_lastx_tl }
191 \dim_compare:nT { \l_tmpa_dim < 1.5cm }
192 {
193 \dim_zero:N \sk_ECG_x_dim
194 \dim_set:Nn \sk_ECG_yshift_dim { \sk_ECG_yshift_dim - 2.5cm }
195 \coordinate(sk_end) at (\sk_ECG_breakindent_tl,\sk_ECG_yshift_dim);
196 \bool_if:NT \sk_ECG_breaklines_arrow_bool {
197 \draw[thick,<-,rounded ~ corners]([xshift=-.25cm]sk_end) -| ++ (-.5cm,1.5cm); }
198 } }
199 \bool_if:NT \sk_ECG_start_bool { \bool_set_false:N \sk_ECG_start_bool }
200 }
201
202 \cs_set_nopar:Npn \sk_ECG_onda_ripeti:nw #1 #2 \q_nil #3
203 {
204 \group_begin:
205 \prg_replicate:nn { #1 } { \sk_ECG:nn { #3 } { #2 } }
206 \group_end:
207 }
208
209 \DeclareDocumentCommand \sk_ECG_onda_label:w { O{.5cm} u\q_nil }
210 {
211 \tl_put_right:Nx \sk_ECG_onda_tl { (#1,0) node [
212 \bool_if:NTF \sk_ECG_start_bool
213 { left }
214 { right }
215 ,name=sk_deriv]
216 { \str_case:nnF { #2 }
217 {
218 { d1 } { I }
219 { d2 } { II }
220 { d3 } { III }
221 { vr } { aVR }
222 { vl } { aVL }
223 { vf } { aVF }
224 { v1 } { V1 }
225 { v2 } { V2 }
226 { v3 } { V3 }
227 { v4 } { V4 }
228 { v5 } { V5 }
229 { v6 } { V6 }
230 } { #2 } } ; \exp_not:N \path(sk_deriv.east) }
231 }
232
233 \cs_set_nopar:Npn \sk_ECG_onda_iso:w #1 \q_nil
234 {
235 \tl_put_right:Nx \sk_ECG_onda_tl
236 { (0,0) -- ( 0.025 mm *
237 \str_if_eq:nnTF { k } { #1 }
238 { 1000 }
239 { #1 }
240 ,0) }
241 }
242
243 \cs_set_nopar:Npn \sk_ECG_onda_q:nw #1 #2 \q_nil
244 {
245 \tl_put_right:Nn \sk_ECG_onda_tl {
246 (0,0)--(#1*.0125cm,-#2*.1cm)--(#1*.025cm,0) }
247 }
248
249 \cs_set_nopar:Npn \sk_ECG_onda_r:nw #1 #2 \q_nil
250 {
251 \tl_put_right:Nn \sk_ECG_onda_tl
252 { (0,0) -- (#1*.0125cm,#2*.1) -- (#1*.025cm,0) }
253 }
254
255 \cs_set_nopar:Npn \sk_ECG_onda_s:nw #1 #2 \q_nil
256 {
257 \tl_put_right:Nn \sk_ECG_onda_tl
258 { (0,0)--(#1*0.0125cm-0.005cm,-#2*.1cm)--(#1*0.025cm,0) }
259 }
260
261 \cs_set_nopar:Npn \sk_ECG_onda_t:nw #1 #2 #3\q_nil
262 {
263 \str_case:nn { #1 }
264 {
265 { p }
266 { \tl_put_right:Nn \sk_ECG_onda_tl
267 { (0,0) .. controls (#2*.0625cm,.05cm) and (#2*.075cm,#3*.065cm)
268 .. (#2*.112cm,#3*.1cm) -- (#2*.138cm,#3*.09cm) .. controls
269 (#2*.175cm,#3*.065cm) and (#2*.188cm,.05) .. (#2*.25cm,0) }
270 }
271 { n }
272 { \tl_put_right:Nn \sk_ECG_onda_tl
273 { (0,0) .. controls (#2*.0625cm,-.05cm) and (#2*.075cm,-#3*.065cm) ..
274 (#2*.112cm,-#3*.1cm) -- (#2*.138cm,-#3*.09cm) ..
275 controls (#2*.175cm,-#3*.065cm) and (#2*.188cm,-.05) .. (#2*.25cm,0) }
276 }
277 }
278 }
279
280 \cs_set_nopar:Npn \sk_ECG_onda_p:nnnw #1 #2 #3 #4 \q_nil
281 {
282 \tl_put_right:Nx \sk_ECG_onda_tl { \str_case:nn { #1 }
283 {
284 { p } { (0,0) -- (.0005*#4,#2#3*.06) -- (.0011*#4,#2#3*.1) --
285 (.002*#4,#2#3*.06) -- (.0025*#4,.0) }
286 { n } { (0,0) -- (.0005*#4,-#2#3*.06) -- (.0011*#4,-#2#3*.1) --
287 (.002*#4,-#2#3*.06) -- (.0025*#4,.0) }
288 { d } { (0,0) -- (.01cm,.005cm)
289 -- (#4*0.3333-.01cm,#2*.1cm-.008cm)
290 -- (#4*0.3333+.01cm,#2*.1cm-.008cm)
291 -- (#4*0.6667-.01cm,-#3*.1cm+.008cm)
292 -- (#4*0.6667+.01cm,-#3*.1cm+.008cm)
293 -- (#4-.01cm,.005cm)
294 -- (#4,0) }
295 { b } { (0,0) -- (.01cm,.005cm)
296 -- (#4*1/3-.01cm,#2*0.045cm+.105cm)
297 -- (#4*1/3+.01cm,#2*0.045cm+.105cm)
298 -- (#4*1/2-.01cm,.1cm)
299 -- (#4*1/2+.01cm,.1cm)
300 -- (#4*2/3-.01cm,#3*0.045cm+.105cm)
301 -- (#4*2/3+.01cm,#3*0.045cm+.105cm)
302 -- (#4-.01cm,.005cm)
303 -- (#4,0) }
304 } }
305 }
306
307 \msg_new:nnn { ECG } { wave ~ defined }
308 { wave ~ "#1" ~ already ~ defined. ~ Change ~ name. }
309
310 \cs_set_nopar:Npn \sk_ECG_new:nn #1 #2 #3
311 {
312 \cs_if_exist:cTF { sk_ECG_ #1 }
313 { \msg_warning:nnn { ECG } { wave ~ defined } { #1 } }
314 { \cs_set_nopar:cpn { sk_ECG_ #1 } { #3 } }
315 }
316
317 \DeclareDocumentCommand \nuovoECG { m O{} m }
318 {
319 \sk_ECG_new:nn { #1 } { #2 } { #3 }
320 }
321
322 \msg_new:nnn { ECG } { fnotf }
323 { File ~ “#1” ~ not ~ found. ~ Please ~ check ~ your ~ installation.}
324
325 \file_if_exist:nTF { archivio }
326 { \file_input:n { archivio } }
327 { \msg_warning:nnn { ECG } { fnotf } { archivio } }
328
329 \ExplSyntaxOff
330 %% \Finale
331 %% Copyright 2016
332 %%
333 %% Distributable under the LaTeX Project Public License,
334 %% version 1.3c or higher (your choice). The latest version of
335 %% this license is at: http://www.latex-project.org/lppl.txt
336 %% This work is "author-maintained"
337 %% This work consists of this file ECG.dtx,
338 %% and the derived files ECG.sty, archivio.tex and ECG.pdf.
339 %%
340 %% End of file `ecgdraw.sty'.