-
Notifications
You must be signed in to change notification settings - Fork 0
/
ladder.sty
executable file
·127 lines (100 loc) · 4.44 KB
/
ladder.sty
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LADDER %%
%% Aurélien CADIOU %%
%% contact@aureliencadiou.fr %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Licence : MIT licence
%% Repository : https://github.com/AurelienC/tex-ladder
\NeedsTeXFormat{LaTeX2e}[1999/01/01]
\ProvidesPackage{ladder}[2017/05/17]
% Packages required
\RequirePackage{tikz}
\RequirePackage{ifthen}
\RequirePackage{calc}
\newcounter{nextY}%
\newcounter{nextYPar}%
\newcounter{nextX}%
\newcounter{currentY}%
\newcounter{currentX}%
\newcounter{tempCurrentY}%
\newcounter{startPar}%
\newcounter{stopPar}%
\newcounter{memCurrentX}%
\newcounter{memCurrentY}%
%%% NEW LINE %%%
\newcommand{\ladderLine}[0]{
% Updating variables
\setcounter{currentX}{0}
\setcounter{nextX}{0}
\setcounter{currentY}{\value{nextY}}
}
%%% TEXT %%%
\newcommand{\ladderText}[3][]{
\draw[text centered](\value{currentX}+1,\value{currentY}+1) node {\textbf{#2}};
\draw[text centered](\value{currentX}+1,\value{currentY}+0.5) node {\textit{#3}};
\draw[text centered](\value{currentX}+1,\value{currentY}) node {\texttt{\LARGE{#1}}};
}
%%% NO CONTACT %%%
\newcommand{\ladderNO}[3][]{
% Updating variables
\setcounter{currentX}{\value{nextX}}
\setcounter{tempCurrentY}{\value{currentY}-2}
\ifthenelse{\value{nextY}>\value{tempCurrentY}}{\setcounter{nextY}{\value{tempCurrentY}}}{}
\ifthenelse{\value{nextYPar}>\value{tempCurrentY}}{\setcounter{nextYPar}{\value{tempCurrentY}}}{}
\addtocounter{nextX}{2}
% Drawing
\draw(\value{currentX}+0.75,\value{currentY}+0.25) -- (\value{currentX}+0.75,\value{currentY}-0.25); % First bar of NO contact
\draw(\value{currentX}+1.25,\value{currentY}+0.25) -- (\value{currentX}+1.25,\value{currentY}-0.25); % Second bar of NO contact
\draw(\value{currentX},\value{currentY}) -- (\value{currentX}+0.75,\value{currentY}); % Connection
\draw(\value{currentX}+1.25,\value{currentY}) -- (\value{nextX},\value{currentY}); % Connection
\ladderText[#1]{#2}{#3}
}
%%% NC CONTACT %%%
\newcommand{\ladderNC}[3][]{
% Updating variables
\setcounter{currentX}{\value{nextX}}
\setcounter{tempCurrentY}{\value{currentY}-2}
\ifthenelse{\value{nextY}>\value{tempCurrentY}}{\setcounter{nextY}{\value{tempCurrentY}}}{}
\ifthenelse{\value{nextYPar}>\value{tempCurrentY}}{\setcounter{nextYPar}{\value{tempCurrentY}}}{}
\addtocounter{nextX}{2}
% Drawing
\draw(\value{currentX}+0.75,\value{currentY}+0.25) -- (\value{currentX}+0.75,\value{currentY}-0.25) -- (\value{currentX}+1.25,\value{currentY}+0.25) -- (\value{currentX}+1.25,\value{currentY}-0.25); % NC contact
\draw(\value{currentX},\value{currentY}) -- (\value{currentX}+0.75,\value{currentY}); % Connection
\draw(\value{currentX}+1.25,\value{currentY}) -- (\value{nextX},\value{currentY}); % Connection
\ladderText[#1]{#2}{#3}
}
%%% COILS %%%
\newcommand{\ladderC}[3][]{
% Updating variables
\setcounter{currentX}{\value{nextX}}
\setcounter{tempCurrentY}{\value{currentY}-2}
\ifthenelse{\value{nextY}>\value{tempCurrentY}}{\setcounter{nextY}{\value{tempCurrentY}}}{}
\ifthenelse{\value{nextYPar}>\value{tempCurrentY}}{\setcounter{nextYPar}{\value{tempCurrentY}}}{}
\addtocounter{nextX}{2}
% Drawing
\draw (\value{currentX}+1,\value{currentY}) circle (0.3);
\draw(\value{currentX},\value{currentY}) -- (\value{currentX}+0.7,\value{currentY}); % Connection
\draw(\value{currentX}+1.3,\value{currentY}) -- (\value{nextX},\value{currentY}); % Connection
\ladderText[#1]{#2}{#3}
}
%%% START OF PARALLEL SECTION %%%
\newcommand{\startParallel}[0]{
\setcounter{startPar}{\value{nextX}} % Store the X of beginning
}
%%% DEBUT PARALLELE %%%
\newcommand{\setParallel}[0]{
\setcounter{stopPar}{\value{nextX}}%
\draw(\value{startPar},\value{currentY}) -- (\value{startPar},\value{nextYPar}); % Vertical bar
\setcounter{memCurrentX}{\value{nextX}}%
\setcounter{memCurrentY}{\value{currentY}}%
\setcounter{nextX}{\value{startPar}}%
\setcounter{currentY}{\value{nextYPar}}%
}
%%% END OF PARALLEL SECTION %%%
\newcommand{\unsetParallel}[0]{
% Parallel section is more larger than "normal" section test
\ifthenelse{\value{nextX}>\value{memCurrentX}}{}{\draw(\value{nextX},\value{currentY}) -- (\value{stopPar},\value{currentY}) -- (\value{stopPar},\value{memCurrentY});}
\ifthenelse{\value{nextX}>\value{memCurrentX}}{\draw (\value{nextX},\value{currentY}) -- (\value{nextX},\value{memCurrentY}) -- (\value{memCurrentX},\value{memCurrentY});}{\setcounter{nextX}{\value{memCurrentX}}}
\setcounter{currentY}{\value{memCurrentY}}
\setcounter{nextYPar}{0}
}