| 1 |
% Copyright 2019 by Till Tantau and Mark Wibrow |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Free Documentation License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
|
| 11 |
\section{Circuit Libraries} |
| 12 |
\label{section-library-circuits} |
| 13 |
|
| 14 |
\emph{Written and documented by Till Tantau, and Mark Wibrow. Inspired |
| 15 |
by the work of Massimo Redaelli.} |
| 16 |
|
| 17 |
|
| 18 |
\subsection{Introduction} |
| 19 |
|
| 20 |
The circuit libraries can be used to draw different kinds of electrical or |
| 21 |
logical circuits. There is not a single library for this, but a whole hierarchy |
| 22 |
of libraries that work in concert. The main design goal was to create a balance |
| 23 |
between ease-of-use and ease-of-extending, while creating high-quality |
| 24 |
graphical representations of circuits. |
| 25 |
% |
| 26 |
\begin{codeexample}[setup code,hidden] |
| 27 |
\tikzset{ |
| 28 |
% from `shape` library |
| 29 |
shape example/.style= {color = black!30, |
| 30 |
draw, |
| 31 |
fill = yellow!30, |
| 32 |
line width = .5cm, |
| 33 |
inner xsep = 2.5cm, |
| 34 |
inner ysep = 0.5cm} |
| 35 |
} |
| 36 |
\end{codeexample} |
| 37 |
|
| 38 |
|
| 39 |
\subsubsection{A First Example} |
| 40 |
|
| 41 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 42 |
\begin{tikzpicture}[circuit ee IEC,x=3cm,y=2cm,semithick, |
| 43 |
every info/.style={font=\footnotesize}, |
| 44 |
small circuit symbols, |
| 45 |
set resistor graphic=var resistor IEC graphic, |
| 46 |
set diode graphic=var diode IEC graphic, |
| 47 |
set make contact graphic= var make contact IEC graphic] |
| 48 |
% Let us start with some contacts: |
| 49 |
\foreach \contact/\y in {1/1,2/2,3/3.5,4/4.5,5/5.5} |
| 50 |
{ |
| 51 |
\node [contact] (left contact \contact) at (0,\y) {}; |
| 52 |
\node [contact] (right contact \contact) at (1,\y) {}; |
| 53 |
} |
| 54 |
\draw (right contact 1) -- (right contact 2) -- (right contact 3) |
| 55 |
-- (right contact 4) -- (right contact 5); |
| 56 |
|
| 57 |
\draw (left contact 1) to [diode] ++(down:1) |
| 58 |
to [voltage source={near start, |
| 59 |
direction info={volt=3}}, |
| 60 |
resistor={near end,ohm=3}] ++(right:1) |
| 61 |
to (right contact 1); |
| 62 |
\draw (left contact 1) to [resistor={ohm=4}] (right contact 1); |
| 63 |
\draw (left contact 1) to [resistor={ohm=3}] (left contact 2); |
| 64 |
\draw (left contact 2) to [voltage source={near start, |
| 65 |
direction info={<-,volt=8}}, |
| 66 |
resistor={ohm=2,near end}] (right contact 2); |
| 67 |
\draw (left contact 2) to [resistor={near start,ohm=1}, |
| 68 |
make contact={near end,info'={[red]$S_1$}}] |
| 69 |
(left contact 3); |
| 70 |
\draw (left contact 3) to [current direction'={near start,info=$\iota$}, |
| 71 |
resistor={near end,info={$R=4\Omega$}}] |
| 72 |
(right contact 3); |
| 73 |
\draw (left contact 4) to [voltage source={near start, |
| 74 |
direction info={<-,volt=8}}, |
| 75 |
resistor={ohm=2,near end}] (right contact 4); |
| 76 |
\draw (left contact 3) to [resistor={ohm=1}] (left contact 4); |
| 77 |
\draw (left contact 4) to [resistor={ohm=3}] (left contact 5); |
| 78 |
\draw (left contact 5) to [resistor={ohm=4}] (right contact 5); |
| 79 |
\draw (left contact 5) to [diode] ++(up:1) |
| 80 |
to [voltage source={near start, |
| 81 |
direction info={volt=3}}, |
| 82 |
resistor={near end,ohm=3}] ++(right:1) |
| 83 |
to (right contact 5); |
| 84 |
\end{tikzpicture} |
| 85 |
\end{codeexample} |
| 86 |
|
| 87 |
An important feature of the |circuits| library is that the appearance of a |
| 88 |
circuit can be configured in general ways and that the labels are placed |
| 89 |
automatically by default. Here is the graphic once more, generated from |
| 90 |
\emph{exactly the same source code}, with only the options of the |
| 91 |
|{tikzpicture}| environment replaced by |
| 92 |
|[rotate=-90,circuit ee IEC,x=3.25cm,y=2.25cm]|: |
| 93 |
|
| 94 |
\begin{tikzpicture}[rotate=-90,circuit ee IEC,x=3cm,y=2.25cm] |
| 95 |
% Let us start with some contacts: |
| 96 |
\foreach \contact/\y in {1/1,2/2,3/3.5,4/4.5,5/5.5} |
| 97 |
{ |
| 98 |
\node [contact] (left contact \contact) at (0,\y) {}; |
| 99 |
\node [contact] (right contact \contact) at (1,\y) {}; |
| 100 |
} |
| 101 |
\draw (right contact 1) -- (right contact 2) -- (right contact 3) |
| 102 |
-- (right contact 4) -- (right contact 5); |
| 103 |
|
| 104 |
\draw (left contact 1) to [diode] ++(down:1) |
| 105 |
to [voltage source={near start,direction info={volt=3}}, |
| 106 |
resistor={near end,ohm=3}] ++(right:1) |
| 107 |
to (right contact 1); |
| 108 |
\draw (left contact 1) to [resistor={ohm=4}] (right contact 1); |
| 109 |
\draw (left contact 1) to [resistor={ohm=3}] (left contact 2); |
| 110 |
\draw (left contact 2) to [voltage source={near start, |
| 111 |
direction info={<-,volt=8}}, |
| 112 |
resistor={ohm=2,near end}] (right contact 2); |
| 113 |
\draw (left contact 2) to [resistor={near start,ohm=1}, |
| 114 |
make contact={near end,info'={[red]$S_1$}}] (left contact 3); |
| 115 |
\draw (left contact 3) to [current direction'={near start,info=$\iota$}, |
| 116 |
resistor={near end,info={$R=4\Omega$}}] |
| 117 |
(right contact 3); |
| 118 |
\draw (left contact 4) to [voltage source={near start, |
| 119 |
direction info={<-,volt=8}}, |
| 120 |
resistor={ohm=2,near end}] (right contact 4); |
| 121 |
\draw (left contact 3) to [resistor={ohm=1}] (left contact 4); |
| 122 |
\draw (left contact 4) to [resistor={ohm=3}] (left contact 5); |
| 123 |
\draw (left contact 5) to [resistor={ohm=4}] (right contact 5); |
| 124 |
\draw (left contact 5) to [diode] ++(up:1) |
| 125 |
to [voltage source={near start,direction info={volt=3}}, |
| 126 |
resistor={near end,ohm=3}] ++(right:1) |
| 127 |
to (right contact 5); |
| 128 |
\end{tikzpicture} |
| 129 |
|
| 130 |
|
| 131 |
\subsubsection{Symbols} |
| 132 |
|
| 133 |
A circuit typically consists of numerous electronic elements like logical gates |
| 134 |
or resistors or diodes that are connected by wires. In \pgfname/\tikzname, we |
| 135 |
use nodes for the electronic elements and normal lines for the wires. |
| 136 |
\tikzname\ offers a large number of different ways of positioning and |
| 137 |
connecting nodes in general, all of which can be used here. Additionally, the |
| 138 |
|circuits| library defines an additional useful |to|-path that is particularly |
| 139 |
useful for elements like a resistor on a line. |
| 140 |
|
| 141 |
There are many different names that are used to refer to electrical |
| 142 |
``elements'', so a bit of terminology standardization is useful: We will call |
| 143 |
such elements \emph{symbols}. A \emph{symbol shape} is a \pgfname\ shape |
| 144 |
declared using the |\pgfdeclareshape| command. A \emph{symbol node} is a node |
| 145 |
whose shape is a symbol shape. |
| 146 |
|
| 147 |
|
| 148 |
\subsubsection{Symbol Graphics} |
| 149 |
|
| 150 |
Symbols can be created by |\node[shape=some symbol shape]|. However, in order |
| 151 |
to represent some symbols correctly, just using standard \pgfname\ shapes is |
| 152 |
not sufficient. For instance, most symbols have a visually appealing ``default |
| 153 |
size'', but the size of a symbol shape depends only on the current values of |
| 154 |
parameters like |minimum height| or |inner xsep|. |
| 155 |
|
| 156 |
For these reasons, the circuit libraries introduce the concept of a |
| 157 |
\emph{symbol graphic}. This is a style that causes a |\node| to not only have |
| 158 |
the correct shape, but also the correct size and the correct path usage. More |
| 159 |
generally, this style may set up things in any way so that the ``symbol looks |
| 160 |
correct''. When you write, for instance, |\node[diode]|, then the style called |
| 161 |
|diode graphic| is used, which in turn is set to something like |
| 162 |
|shape=diode IEC,draw,minimum height=...|. |
| 163 |
|
| 164 |
Here is an overview of the different kinds of circuit libraries: |
| 165 |
% |
| 166 |
\begin{itemize} |
| 167 |
\item The \tikzname-library |circuits| defines general keys for creating |
| 168 |
circuits. Mostly, these keys are useful for defining more specialized |
| 169 |
libraries. |
| 170 |
|
| 171 |
You normally do not use this library directly since it does not define |
| 172 |
any symbol graphics. |
| 173 |
\item The \tikzname-library |circuits.logic| defines keys for creating |
| 174 |
logical gates like and-gates or xor-gates. However, this library also |
| 175 |
does not actually define any symbol graphics; this is done by two |
| 176 |
sublibraries: |
| 177 |
% |
| 178 |
\begin{itemize} |
| 179 |
\item The library |circuits.logic.US| defines symbol graphics that |
| 180 |
cause the logical gates to be rendered in the ``US-style''. It |
| 181 |
includes all of the above libraries and you can use this |
| 182 |
library directly. |
| 183 |
\item The library |circuits.logic.IEC| also defines symbol graphics |
| 184 |
for logical gates, but it uses rectangular gates rather that |
| 185 |
the round US-gates. This library can coexist peacefully with |
| 186 |
the above library, you can change which symbol graphics are |
| 187 |
used ``on the fly''. |
| 188 |
\end{itemize} |
| 189 |
\item The \tikzname-library |circuits.ee| defines keys for symbols from |
| 190 |
electrical engineering like resistors or capacitors. Again, |
| 191 |
sublibraries define the actual symbol graphics. |
| 192 |
% |
| 193 |
\begin{itemize} |
| 194 |
\item The library |circuits.ee.IEC| defines symbol shapes that |
| 195 |
follow the IEC norm. |
| 196 |
\end{itemize} |
| 197 |
\item The \pgfname-libraries |shapes.gates.*| define (circuit) symbol |
| 198 |
shapes. However, you normally do not use these shapes directly, rather |
| 199 |
you use a style that uses an appropriate symbol graphic, which in turn |
| 200 |
uses one of these shapes. |
| 201 |
\end{itemize} |
| 202 |
|
| 203 |
Let us have a look at a simple example. Suppose we wish to create a logical |
| 204 |
circuit. Then we first have to decide which symbol graphics we would like to |
| 205 |
use. Suppose we wish to use the US-style, then we would include the library |
| 206 |
|circuits.logic.US|. If you wish to use IEC-style symbols, use |
| 207 |
|circuits.logic.IEC|. If you cannot decide, include both: |
| 208 |
% |
| 209 |
\begin{codeexample}[code only] |
| 210 |
\usetikzlibrary{circuits.logic.US,circuits.logic.IEC} |
| 211 |
\end{codeexample} |
| 212 |
% |
| 213 |
To create a picture that contains a US-style circuit you can now use the option |
| 214 |
|circuit logic US|. This will set up keys like |and gate| to create use an |
| 215 |
appropriate symbol graphic for rendering an |and gate|. Using the |
| 216 |
|circuit logic IEC| instead will set up |and gate| to use another symbol |
| 217 |
graphic. |
| 218 |
% |
| 219 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.US}}] |
| 220 |
\begin{tikzpicture}[circuit logic US] |
| 221 |
\matrix[column sep=7mm] |
| 222 |
{ |
| 223 |
\node (i0) {0}; & & \\ |
| 224 |
& \node [and gate] (a1) {}; & \\ |
| 225 |
\node (i1) {0}; & & \node [or gate] (o) {};\\ |
| 226 |
& \node [nand gate] (a2) {}; & \\ |
| 227 |
\node (i2) {1}; & & \\ |
| 228 |
}; |
| 229 |
\draw (i0.east) -- ++(right:3mm) |- (a1.input 1); |
| 230 |
\draw (i1.east) -- ++(right:3mm) |- (a1.input 2); |
| 231 |
\draw (i1.east) -- ++(right:3mm) |- (a2.input 1); |
| 232 |
\draw (i2.east) -- ++(right:3mm) |- (a2.input 2); |
| 233 |
\draw (a1.output) -- ++(right:3mm) |- (o.input 1); |
| 234 |
\draw (a2.output) -- ++(right:3mm) |- (o.input 2); |
| 235 |
\draw (o.output) -- ++(right:3mm); |
| 236 |
\end{tikzpicture} |
| 237 |
\end{codeexample} |
| 238 |
|
| 239 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.IEC}}] |
| 240 |
\begin{tikzpicture}[circuit logic IEC] |
| 241 |
\matrix[column sep=7mm] |
| 242 |
{ |
| 243 |
\node (i0) {0}; & & \\ |
| 244 |
& \node [and gate] (a1) {}; & \\ |
| 245 |
\node (i1) {0}; & & \node [or gate] (o) {};\\ |
| 246 |
& \node [nand gate] (a2) {}; & \\ |
| 247 |
\node (i2) {1}; & & \\ |
| 248 |
}; |
| 249 |
\draw (i0.east) -- ++(right:3mm) |- (a1.input 1); |
| 250 |
\draw (i1.east) -- ++(right:3mm) |- (a1.input 2); |
| 251 |
\draw (i1.east) -- ++(right:3mm) |- (a2.input 1); |
| 252 |
\draw (i2.east) -- ++(right:3mm) |- (a2.input 2); |
| 253 |
\draw (a1.output) -- ++(right:3mm) |- (o.input 1); |
| 254 |
\draw (a2.output) -- ++(right:3mm) |- (o.input 2); |
| 255 |
\draw (o.output) -- ++(right:3mm); |
| 256 |
\end{tikzpicture} |
| 257 |
\end{codeexample} |
| 258 |
|
| 259 |
|
| 260 |
\subsubsection{Annotations} |
| 261 |
|
| 262 |
An \emph{annotation} is a little extra drawing that can be added to a symbol. |
| 263 |
For instance, when you add two little parallel arrows pointing away from some |
| 264 |
electrical element, this usually means that the element is light emitting. |
| 265 |
|
| 266 |
Instead of having one symbol for ``diode'' and another for ``light emitting |
| 267 |
diode'', there is just one |diode| symbol, but you can add the |light emitting| |
| 268 |
annotation to it. This is done by passing the annotation as a parameter to the |
| 269 |
symbol as in the following example: |
| 270 |
% |
| 271 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 272 |
\tikz [circuit ee IEC] |
| 273 |
\draw (0,0) to [diode={light emitting}] (3,0) |
| 274 |
to [resistor={adjustable}] (3,2); |
| 275 |
\end{codeexample} |
| 276 |
|
| 277 |
|
| 278 |
\subsection{The Base Circuit Library} |
| 279 |
|
| 280 |
\begin{tikzlibrary}{circuits} |
| 281 |
This library is a base library that is included by other circuit libraries. |
| 282 |
You do not include it directly, but you will typically use some of the |
| 283 |
general keys, described below. |
| 284 |
\end{tikzlibrary} |
| 285 |
|
| 286 |
\begin{key}{/tikz/circuits} |
| 287 |
This key should be passed as an option to a picture or a scope that contains |
| 288 |
a circuit. It will do some internal setups. This key is normally called by |
| 289 |
more specialized keys like |circuit ee IEC|. |
| 290 |
\end{key} |
| 291 |
|
| 292 |
|
| 293 |
\subsubsection{Symbol Size} |
| 294 |
|
| 295 |
\begin{key}{/tikz/circuit symbol unit=\meta{dimension} (initially 7pt)} |
| 296 |
This dimension is a ``unit'' for the size of symbols. The libraries |
| 297 |
generally define the sizes of symbols relative to this dimension. For |
| 298 |
instance, the longer side of an inductor is, by default, in the IEC library |
| 299 |
equal to five times this \meta{dimension}. When you change this |
| 300 |
\meta{dimension}, the size of all symbols will automatically change |
| 301 |
accordingly. |
| 302 |
|
| 303 |
Note, that it is still possible to overwrite the size of any particular |
| 304 |
symbol. These settings apply only to the default sizes. |
| 305 |
% |
| 306 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 307 |
\begin{tikzpicture}[circuit ee IEC] |
| 308 |
\draw (0,1) to [resistor] (3.5,1); |
| 309 |
\draw[circuit symbol unit=14pt] |
| 310 |
(0,0) to [resistor] (3.5,0); |
| 311 |
\end{tikzpicture} |
| 312 |
\end{codeexample} |
| 313 |
% |
| 314 |
\end{key} |
| 315 |
|
| 316 |
\begin{stylekey}{/tikz/huge circuit symbols} |
| 317 |
This style sets the default circuit symbol unit to |10pt|. |
| 318 |
\end{stylekey} |
| 319 |
% |
| 320 |
\begin{stylekey}{/tikz/large circuit symbols} |
| 321 |
This style sets the default circuit symbol unit to |8pt|. |
| 322 |
\end{stylekey} |
| 323 |
% |
| 324 |
\begin{stylekey}{/tikz/medium circuit symbols} |
| 325 |
This style sets the default circuit symbol unit to |7pt|. |
| 326 |
\end{stylekey} |
| 327 |
% |
| 328 |
\begin{stylekey}{/tikz/small circuit symbols} |
| 329 |
This style sets the default circuit symbol unit to |6pt|. |
| 330 |
\end{stylekey} |
| 331 |
% |
| 332 |
\begin{stylekey}{/tikz/tiny circuit symbols} |
| 333 |
This style sets the default circuit symbol unit to |5pt|. |
| 334 |
\end{stylekey} |
| 335 |
|
| 336 |
\begin{key}{/tikz/circuit symbol size=|width| \meta{width} |height| \meta{height}} |
| 337 |
This key sets |minimum height| to \meta{height} times the current value of |
| 338 |
the circuit symbol unit and the |minimum width| to \meta{width} times this |
| 339 |
value. Thus, this option can be used with a node command to set the size of |
| 340 |
the node as a multiple of the circuit symbol unit. |
| 341 |
% |
| 342 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 343 |
\begin{tikzpicture}[circuit ee IEC] |
| 344 |
\draw (0,1) to [resistor] (2,1) to[inductor] (4,1); |
| 345 |
|
| 346 |
\begin{scope} |
| 347 |
[every resistor/.style={circuit symbol size=width 3 height 1}] |
| 348 |
\draw (0,0) to [resistor] (2,0) to[inductor] (4,0); |
| 349 |
\end{scope} |
| 350 |
\end{tikzpicture} |
| 351 |
\end{codeexample} |
| 352 |
% |
| 353 |
\end{key} |
| 354 |
|
| 355 |
|
| 356 |
\subsubsection{Declaring New Symbols} |
| 357 |
|
| 358 |
\begin{key}{/tikz/circuit declare symbol=\meta{name}} |
| 359 |
This key is used to declare a symbol. It does not cause this symbol to be |
| 360 |
shown nor does it set a graphic to be used for the symbol, it simply |
| 361 |
``prepares'' several keys that can later be used to draw a symbol and to |
| 362 |
configure it. |
| 363 |
|
| 364 |
In detail, the first key that is defined is just called \meta{name}. This |
| 365 |
key should be given as an option to a |node| or on a |to| path, as |
| 366 |
explained below. The key will take options, which can be used to influence |
| 367 |
the way the symbol graphic is rendered. |
| 368 |
|
| 369 |
Let us have a look at an example. Suppose we want to define a symbol called |
| 370 |
|foo|, which just looks like a simple rectangle. We could then say |
| 371 |
% |
| 372 |
\begin{codeexample}[code only] |
| 373 |
\tikzset{circuit declare symbol=foo} |
| 374 |
\end{codeexample} |
| 375 |
% |
| 376 |
The symbol could now be used like this: |
| 377 |
% |
| 378 |
\begin{codeexample}[code only] |
| 379 |
\node [foo] at (1,1) {}; |
| 380 |
\node [foo={red}] at (2,1) {}; |
| 381 |
\end{codeexample} |
| 382 |
|
| 383 |
However, in the above example we would not actually see anything since we |
| 384 |
have not yet set up the graphic to be used by |foo|. For this, we must use |
| 385 |
a key called |set foo graphic| or, generally, |set| \meta{name} |graphic|. |
| 386 |
This key gets graphic options as parameter that will be set when a symbol |
| 387 |
|foo| should be shown: |
| 388 |
% |
| 389 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits}}] |
| 390 |
\begin{tikzpicture} |
| 391 |
[circuit declare symbol=foo, |
| 392 |
set foo graphic={draw,shape=rectangle,minimum size=5mm}] |
| 393 |
|
| 394 |
\node [foo] at (1,1) {}; |
| 395 |
\node [foo={red}] at (2,1) {}; |
| 396 |
\end{tikzpicture} |
| 397 |
\end{codeexample} |
| 398 |
|
| 399 |
In detail, when you use the key \meta{name}=\meta{options} with a node, the |
| 400 |
following happens: |
| 401 |
% |
| 402 |
\begin{enumerate} |
| 403 |
\item The |inner sep| is set to |0.5pt|. |
| 404 |
\item The following style is executed: |
| 405 |
% |
| 406 |
\begin{stylekey}{/tikz/every circuit symbol} |
| 407 |
Use this style to set up things in general. |
| 408 |
\end{stylekey} |
| 409 |
\item The graphic options that have been set using |set| \meta{name} |
| 410 |
|graphic| are set. |
| 411 |
\item The style |every |\meta{name} is executed. You can use it to |
| 412 |
configure the symbol further. |
| 413 |
\item The \meta{options} are executed. |
| 414 |
\end{enumerate} |
| 415 |
|
| 416 |
The key \meta{name} will have a different effect when it is used on a |to| |
| 417 |
path command inside a |circuit| environment (the |circuit| environment sets |
| 418 |
up |to| paths in such a way that the use of a key declared using |
| 419 |
|circuit declare symbol| is automatically detected). When \meta{name} is |
| 420 |
used on a |to| path, the above actions also happen (setting the inner |
| 421 |
separation, using the symbol graphic, and so on), but they are passed to |
| 422 |
the key |circuit handle symbol|, which is explained next. |
| 423 |
\end{key} |
| 424 |
|
| 425 |
\begin{key}{/tikz/circuit handle symbol=\meta{options}} |
| 426 |
This key is mostly used internally. Its purpose is to render a symbol. The |
| 427 |
effect of this key differs, depending on whether it is used as the optional |
| 428 |
argument of a |to| path command or elsewhere. |
| 429 |
|
| 430 |
If the key is not used as an argument of a |to| path command, the |
| 431 |
\meta{options} are simply executed. |
| 432 |
|
| 433 |
The more interesting case happens when the key is given on a |to| path |
| 434 |
command. In this case, several things happen: |
| 435 |
% |
| 436 |
\begin{enumerate} |
| 437 |
\item The |to| path is locally changed and set to an internal path |
| 438 |
(which you should not try to change) that consists mostly of a |
| 439 |
single straight line. |
| 440 |
\item The \meta{options} are tentatively executed with filtering |
| 441 |
switched on. Everything is filtered out, except for the key |pos| |
| 442 |
and also the styles |at start|, |very near start|, |near start|, |
| 443 |
|midway|, |near end|, |very near end|, and |at end|. If none of |
| 444 |
them is found, |midway| is used. |
| 445 |
\item The filtered option is used to determine a position for the |
| 446 |
symbol on the path. At the given position (with |pos=0| |
| 447 |
representing the start and |pos=1| representing the end), a node |
| 448 |
will be added to the path (in a manner to be described presently). |
| 449 |
\item This node gets \meta{options} as its option list. |
| 450 |
\item The node is added by virtue of a special |markings| decoration. |
| 451 |
This means that a |mark| command is executed that causes the node |
| 452 |
to be placed as a mark on the path. |
| 453 |
\item The marking decoration will automatically subdivide the path and |
| 454 |
cause a line to be drawn from the start of the path to the node's |
| 455 |
border (at the position that lies on a line from the node's center |
| 456 |
to the start of the path) and then from the node's border (at a |
| 457 |
position on the other side of the node) to the end of the path. |
| 458 |
\item The marking decoration will also take care of the case that |
| 459 |
multiple marks are present on a path, in this case the lines from |
| 460 |
and to the borders of the nodes are only between consecutive nodes. |
| 461 |
\item The marking decoration will also rotate the coordinate system in |
| 462 |
such a way that the $x$-axis points along the path. Thus, if you |
| 463 |
use the |transform shape| option, the node will ``point along'' the |
| 464 |
path. |
| 465 |
\item In case a node is at |pos=0| or at |pos=1| some special code will |
| 466 |
suppress the superfluous lines to the start or end of the path. |
| 467 |
\end{enumerate} |
| 468 |
|
| 469 |
The net effect of all of the above is that a node will be placed ``on the |
| 470 |
path'' and the path will have a ``gap'' just large enough to encompass the |
| 471 |
node. Another effect is that you can use this key multiple times on a path |
| 472 |
to add several node to a path, provided they do not overlap. |
| 473 |
% |
| 474 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits}}] |
| 475 |
\begin{tikzpicture}[circuit] |
| 476 |
\draw (0,0) to [circuit handle symbol={draw,shape=rectangle,near start}, |
| 477 |
circuit handle symbol={draw,shape=circle,near end}] (3,2); |
| 478 |
\end{tikzpicture} |
| 479 |
\end{codeexample} |
| 480 |
% |
| 481 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits}}] |
| 482 |
\begin{tikzpicture}[transform shape,circuit] |
| 483 |
\draw (0,0) to [circuit handle symbol={draw,shape=rectangle,at start}, |
| 484 |
circuit handle symbol={draw,shape=circle,near end}] (3,2); |
| 485 |
\end{tikzpicture} |
| 486 |
\end{codeexample} |
| 487 |
% |
| 488 |
\end{key} |
| 489 |
|
| 490 |
|
| 491 |
\subsubsection{Pointing Symbols in the Right Direction} |
| 492 |
|
| 493 |
Unlike normal nodes, which generally should not be rotated since this will make |
| 494 |
their text hard to read, symbols often need to be rotated. There are two ways |
| 495 |
of achieving such rotations: |
| 496 |
% |
| 497 |
\begin{enumerate} |
| 498 |
\item When you place a symbol on a |to| path, the graphic symbol is |
| 499 |
automatically rotated such that it ``points along the path''. Here is |
| 500 |
an examples that shows how the inductor shape (which looks, unrotated, |
| 501 |
like this: \tikz[circuit ee IEC]\node[inductor]{};) is automatically |
| 502 |
rotated around: |
| 503 |
% |
| 504 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 505 |
\tikz [circuit ee IEC] |
| 506 |
\draw (3,0) to[inductor] (1,0) to[inductor] (0,2); |
| 507 |
\end{codeexample} |
| 508 |
% |
| 509 |
\item Many shapes cannot be placed ``on'' a path in this way, namely |
| 510 |
whenever there are more than two possible inputs. Also, you may wish to |
| 511 |
place the nodes first, possibly using a matrix, and connect them |
| 512 |
afterwards. In this case, you can simply add rotations like |rotate=90| |
| 513 |
to the shapes to rotate them. The following four keys make this |
| 514 |
slightly more convenient: |
| 515 |
% |
| 516 |
\begin{key}{/tikz/point up} |
| 517 |
This is the same as |rotate=90|. |
| 518 |
% |
| 519 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 520 |
\tikz [circuit ee IEC] \node [diode,point up] {}; |
| 521 |
\end{codeexample} |
| 522 |
\end{key} |
| 523 |
% |
| 524 |
\begin{key}{/tikz/point down} |
| 525 |
This is the same as |rotate=-90|. |
| 526 |
% |
| 527 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 528 |
\tikz [circuit ee IEC] \node [diode,point down] {}; |
| 529 |
\end{codeexample} |
| 530 |
\end{key} |
| 531 |
% |
| 532 |
\begin{key}{/tikz/point left} |
| 533 |
This is the same as |rotate=-180|. |
| 534 |
% |
| 535 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 536 |
\tikz [circuit ee IEC] \node [diode,point left] {}; |
| 537 |
\end{codeexample} |
| 538 |
\end{key} |
| 539 |
% |
| 540 |
\begin{key}{/tikz/point right} |
| 541 |
This key has no effect. |
| 542 |
% |
| 543 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 544 |
\tikz [circuit ee IEC] \node [diode,point right] {}; |
| 545 |
\end{codeexample} |
| 546 |
\end{key} |
| 547 |
\end{enumerate} |
| 548 |
|
| 549 |
|
| 550 |
\subsubsection{Info Labels} |
| 551 |
|
| 552 |
Info labels are used to add text to a circuit symbol. Unlike normal nodes like |
| 553 |
a rectangle, circuit symbols typically do not have text ``on'' them, but the |
| 554 |
text is placed next to them (like the text ``$3\,\Omega$'' next to a resistor). |
| 555 |
|
| 556 |
\tikzname\ already provides the |label| option for this purpose. The |info| |
| 557 |
option is built on top of this option, but it comes in some predefined variants |
| 558 |
that are especially useful in conjunction with circuits. |
| 559 |
|
| 560 |
\begin{key}{/tikz/info=\opt{|[|\meta{options}|]|\meta{angle}|:|}\meta{text}} |
| 561 |
This key has nearly the same effect as the |label| key, only the following |
| 562 |
style is used additionally automatically: |
| 563 |
% |
| 564 |
\begin{stylekey}{/tikz/every info} |
| 565 |
Set this style to configure the styling of info labels. Since this |
| 566 |
key is \emph{not} used with normal labels, it provides an easy way |
| 567 |
of changing the way info labels look without changing other |
| 568 |
labels. |
| 569 |
\end{stylekey} |
| 570 |
% |
| 571 |
The \meta{options} and \meta{angle} are passed directly to the |label| |
| 572 |
command. |
| 573 |
% |
| 574 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 575 |
\begin{tikzpicture}[circuit ee IEC,every info/.style=red] |
| 576 |
\node [resistor,info=$3\Omega$] {}; |
| 577 |
\end{tikzpicture} |
| 578 |
\end{codeexample} |
| 579 |
|
| 580 |
You will find a detailed discussion of the |label| option on |
| 581 |
page~\pageref{label-option}. |
| 582 |
|
| 583 |
Hint: To place some text \emph{on} the main node, use |center| as the |
| 584 |
\meta{angle}: |
| 585 |
% |
| 586 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 587 |
\begin{tikzpicture}[circuit ee IEC,every info/.style=red] |
| 588 |
\node [resistor,info=center:$3\Omega$] {}; |
| 589 |
\node [resistor,point up,info=center:$R_1$] at (2,0) {}; |
| 590 |
\end{tikzpicture} |
| 591 |
\end{codeexample} |
| 592 |
% |
| 593 |
\end{key} |
| 594 |
|
| 595 |
\begin{key}{/tikz/info'=\opt{|[|\meta{options}|]|\meta{angle}|:|}\meta{text}} |
| 596 |
This key works exactly like the |info| key, only in case the \meta{angle} |
| 597 |
is missing, it defaults to |below| instead of the current value of |
| 598 |
|label position|, which is usually |above|. This means that when you use |
| 599 |
|info|, you get a label above the node, while when you use the |info'| key |
| 600 |
you get a label below the node. In case the node has been rotated, the |
| 601 |
positions of the info nodes are rotated accordingly. |
| 602 |
% |
| 603 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 604 |
\begin{tikzpicture}[circuit ee IEC,every info/.style=red] |
| 605 |
\draw (0,0) to[resistor={info={$3\Omega$},info'={$R_1$}}] (3,0) |
| 606 |
to[resistor={info={$4\Omega$},info'={$R_2$}}] (3,2); |
| 607 |
\end{tikzpicture} |
| 608 |
\end{codeexample} |
| 609 |
% |
| 610 |
\end{key} |
| 611 |
|
| 612 |
\begin{key}{/tikz/info sloped=\opt{|[|\meta{options}|]|\meta{angle}|:|}\meta{text}} |
| 613 |
This key works like |info|, only the |transform shape| option is set when |
| 614 |
the label is drawn, causing it to follow the sloping of the main node. |
| 615 |
% |
| 616 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 617 |
\begin{tikzpicture}[circuit ee IEC,every info/.style=red] |
| 618 |
\draw (0,0) to[resistor={info sloped={$3\Omega$}}] (3,0) |
| 619 |
to[resistor={info sloped={$4\Omega$}}] (3,2); |
| 620 |
\end{tikzpicture} |
| 621 |
\end{codeexample} |
| 622 |
% |
| 623 |
\end{key} |
| 624 |
|
| 625 |
\begin{key}{/tikz/info' sloped=} |
| 626 |
This is a combination of |info'| and |info sloped|. |
| 627 |
% |
| 628 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 629 |
\begin{tikzpicture}[circuit ee IEC,every info/.style=red] |
| 630 |
\draw (0,0) to[resistor={info' sloped={$3\Omega$}}] (3,0) |
| 631 |
to[resistor={info' sloped={$4\Omega$}}] (3,2); |
| 632 |
\end{tikzpicture} |
| 633 |
\end{codeexample} |
| 634 |
% |
| 635 |
\end{key} |
| 636 |
|
| 637 |
\begin{key}{/tikz/circuit declare unit=\marg{name}\marg{unit}} |
| 638 |
This key is used to declare keys that make it easy to attach physical units |
| 639 |
to nodes. The idea is that instead of |info=$3\Omega$| you can write |
| 640 |
|ohm=3| or instead of |info'=$5\mathrm{S}$| you can write |siemens'=5|. |
| 641 |
|
| 642 |
In detail, four keys are defined, namely |/tikz/|\meta{name}, |
| 643 |
|/tikz/|\meta{name}|'|, |/tikz/|\meta{name} |sloped|, and |
| 644 |
|/tikz/|\meta{name}|'| |sloped|. The arguments of all of these keys are of |
| 645 |
the form \opt{|[|\meta{options}|]|\meta{angle}|:|}\meta{value} and it is |
| 646 |
passed (slightly modified) to the corresponding key |info|, |info'|, |info| |
| 647 |
|sloped|, or |info'| |sloped|. The ``slight modification'' is the |
| 648 |
following: The text that is passed to the, say, |info| key is not |
| 649 |
\meta{value}, but rather |$\mathrm{|\meta{value}\meta{unit}|}$| |
| 650 |
|
| 651 |
This means that after you said |circuit declare unit={ohm}{\Omega}|, then |
| 652 |
|ohm=5k| will have the same effect as |
| 653 |
|info={[every ohm]$\mathrm{5k\Omega}$}|. Here, |every ohm| is a style that |
| 654 |
allows you to configure the appearance of this unit. Since the |info| key |
| 655 |
is used internally, by changing the |every info| style, you can change the |
| 656 |
appearance of all units infos. |
| 657 |
% |
| 658 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 659 |
\begin{tikzpicture}[circuit ee IEC,circuit declare unit={my ohm}{O}] |
| 660 |
\draw (0,0) to[resistor={my ohm' sloped=3}] (3,2); |
| 661 |
\end{tikzpicture} |
| 662 |
\end{codeexample} |
| 663 |
% |
| 664 |
\end{key} |
| 665 |
|
| 666 |
|
| 667 |
\subsubsection{Declaring and Using Annotations} |
| 668 |
|
| 669 |
Annotations are quite similar to info labels. The main difference is that they |
| 670 |
generally cause something to be drawn by default rather than some text to be |
| 671 |
added (although an annotation might also add some text). |
| 672 |
|
| 673 |
Annotations can be declared using the following key: |
| 674 |
|
| 675 |
\begin{key}{/tikz/circuit declare annotation=\marg{name}\marg{distance}\marg{path}} |
| 676 |
This key is used to declare an annotation named \meta{name}. Once declared, |
| 677 |
it can be used as an argument of a symbol and will add the drawing in |
| 678 |
\meta{path} to the symbol. In detail, the following happens: |
| 679 |
|
| 680 |
|
| 681 |
\textbf{The Main Keys.} |
| 682 |
Two keys called \meta{name} and \meta{name}|'| are defined. The second |
| 683 |
causes the annotation to be ``mirrored and placed on the other side'' of |
| 684 |
the symbol. Both of these keys may also take further keys as parameter like |
| 685 |
|info| keys. Whenever the \meta{name} key is used, a local scope is opened |
| 686 |
and in this scope the following things are done: |
| 687 |
% |
| 688 |
\begin{enumerate} |
| 689 |
\item The style |every| \meta{name} is executed. |
| 690 |
\item The following style is executed and then |arrows=->|: |
| 691 |
% |
| 692 |
\begin{stylekey}{/tikz/annotation arrow} |
| 693 |
This style should set the |>| key to some desirable arrow tip. |
| 694 |
\end{stylekey} |
| 695 |
\item The coordinate system is shifted such that the origin is at the |
| 696 |
north anchor of the symbol. (For the \meta{name}|'| key the |
| 697 |
coordinate system is flipped and shifted such that the origin is at |
| 698 |
the south anchor of the symbol.) |
| 699 |
\item The |label distance| is locally set to \meta{distance}. |
| 700 |
\item The parameter options given to the \meta{name} key are executed. |
| 701 |
\item The \meta{path} is executed. |
| 702 |
\end{enumerate} |
| 703 |
|
| 704 |
|
| 705 |
\textbf{Usage.} |
| 706 |
What all of the above amounts to is best explained by an example. Suppose |
| 707 |
we wish to create an annotation that looks like a little circular arrow |
| 708 |
(like \tikz \draw [->] (0,0) arc (-270:80:1ex);). We could then say: |
| 709 |
% |
| 710 |
\begin{codeexample}[code only] |
| 711 |
\tikzset{circuit declare annotation= |
| 712 |
{circular annotation} |
| 713 |
{9pt} |
| 714 |
{(0pt,8pt) arc (-270:80:3.5pt)} |
| 715 |
} |
| 716 |
\end{codeexample} |
| 717 |
% |
| 718 |
We can then use it like this: |
| 719 |
% |
| 720 |
\tikzset{circuit declare annotation= |
| 721 |
{circular annotation} |
| 722 |
{8pt} |
| 723 |
{(0pt,8pt) arc (-270:80:3.5pt)} |
| 724 |
} |
| 725 |
\begin{codeexample}[ |
| 726 |
preamble={\usetikzlibrary{circuits.ee.IEC}} |
| 727 |
pre={\tikzset{circuit declare annotation= |
| 728 |
{circular annotation} |
| 729 |
{8pt} |
| 730 |
{(0pt,8pt) arc (-270:80:3.5pt)} |
| 731 |
}}] |
| 732 |
\tikz[circuit ee IEC] |
| 733 |
\draw (0,0) to [resistor={circular annotation}] (3,0); |
| 734 |
\end{codeexample} |
| 735 |
% |
| 736 |
Well, not very impressive since we do not see anything. This is due to the |
| 737 |
fact that the \meta{path} becomes part of a path that contains the symbol |
| 738 |
node an nothing else. This path is not drawn or filled, so we do not see |
| 739 |
anything. What we must do is to use an |edge| path operation: |
| 740 |
% |
| 741 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 742 |
\tikzset{circuit declare annotation={circular annotation}{9pt} |
| 743 |
{(0pt,8pt) edge[to path={arc(-270:80:3.5pt)}] ()} |
| 744 |
} |
| 745 |
\tikz[circuit ee IEC] |
| 746 |
\draw (0,0) to [resistor={circular annotation}] (3,0) |
| 747 |
to [capacitor={circular annotation'}] (3,2); |
| 748 |
\end{codeexample} |
| 749 |
% |
| 750 |
The \meta{distance} is important for the correct placement of additional |
| 751 |
|info| labels. When an annotation is present, the info labels may need to |
| 752 |
be moved further away from the symbol, but not always. For this reason, an |
| 753 |
annotation defines an additional \meta{distance} that is applied to all |
| 754 |
info labels given as parameters to the annotation. Here is an example, that |
| 755 |
shows the difference: |
| 756 |
% |
| 757 |
\tikzset{circuit declare annotation={circular annotation}{9pt} |
| 758 |
{(0pt,8pt) edge[to path={arc (-270:80:3.5pt)}] ()} |
| 759 |
} |
| 760 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}} |
| 761 |
pre={\tikzset{circuit declare annotation= |
| 762 |
{circular annotation} |
| 763 |
{8pt} |
| 764 |
{(0pt,8pt) arc (-270:80:3.5pt)} |
| 765 |
}}] |
| 766 |
\tikz[circuit ee IEC] |
| 767 |
\draw (0,0) to [resistor={circular annotation,ohm=5}] (2,0) |
| 768 |
to [resistor={circular annotation={ohm=5}}] (4,0); |
| 769 |
\end{codeexample} |
| 770 |
% |
| 771 |
\end{key} |
| 772 |
|
| 773 |
|
| 774 |
\subsubsection{Theming Symbols} |
| 775 |
\label{section-theming-symbols} |
| 776 |
|
| 777 |
For each symbol, a certain graphical representation is chosen to actually show |
| 778 |
the symbol. You can modify this graphical representation in several ways: |
| 779 |
% |
| 780 |
\begin{itemize} |
| 781 |
\item You can select a different library and use a different |circuit ...| |
| 782 |
key. This will change all graphics used for the symbols. |
| 783 |
\item You can generally change the size of graphic symbols by setting |
| 784 |
|circuit size unit| to a different value or using a key like |
| 785 |
|small circuit symbols|. |
| 786 |
\item You can add options to the graphics used by symbols either globally |
| 787 |
by setting the |every circuit| |symbol| style or locally by setting the |
| 788 |
|every| \meta{name} style, where \meta{name} is the name of a symbol. |
| 789 |
For instance, in the following picture the symbols are ridiculously |
| 790 |
thick and resistors are red. |
| 791 |
% |
| 792 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 793 |
\begin{tikzpicture} |
| 794 |
[circuit ee IEC, |
| 795 |
every circuit symbol/.style={ultra thick}, |
| 796 |
every resistor/.style={red}] |
| 797 |
|
| 798 |
\draw (0,0) to [inductor] ++(right:3) to [resistor] ++(up:2); |
| 799 |
\end{tikzpicture} |
| 800 |
\end{codeexample} |
| 801 |
% |
| 802 |
\item You can selectively change the graphic used for a symbol by saying |
| 803 |
|set resistor graphic=|. |
| 804 |
\item You can change one or more of the following styles: |
| 805 |
% |
| 806 |
\begin{stylekey}{/tikz/circuit symbol open (initially draw)} |
| 807 |
This style is used with symbols that consist of lines that surround |
| 808 |
some area. For instance, the IEC version of a resistor is an open |
| 809 |
symbol. |
| 810 |
% |
| 811 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 812 |
\tikz [circuit ee IEC, |
| 813 |
circuit symbol open/.style={thick,draw,fill=yellow}] |
| 814 |
\draw (0,0) to [inductor] ++(right:3) to [resistor] ++(up:2); |
| 815 |
\end{codeexample} |
| 816 |
\end{stylekey} |
| 817 |
% |
| 818 |
\begin{stylekey}{/tikz/circuit symbol filled (initially {draw,fill=black})} |
| 819 |
This style is used with symbols that are completely filled. For |
| 820 |
instance, the variant IEC version of an inductor is a filled, black |
| 821 |
rectangle. |
| 822 |
\end{stylekey} |
| 823 |
% |
| 824 |
\begin{stylekey}{/tikz/circuit symbol lines (initially draw)} |
| 825 |
This style is used with symbols that consist only of lines that do |
| 826 |
not surround anything. Examples are a capacitor. |
| 827 |
% |
| 828 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 829 |
\tikz [circuit ee IEC, |
| 830 |
circuit symbol lines/.style={thick,draw=red}] |
| 831 |
\draw (0,0) to [capacitor] ++(right:3) to [resistor] ++(up:2); |
| 832 |
\end{codeexample} |
| 833 |
\end{stylekey} |
| 834 |
% |
| 835 |
\begin{stylekey}{/tikz/circuit symbol wires (initially draw)} |
| 836 |
This style is used for symbols that consist only of ``wires''. The |
| 837 |
difference to the previous style is that a symbol consisting of |
| 838 |
wires will look strange when the lines are thicker than the lines |
| 839 |
of normal wires, while for symbols consisting of lines (but not |
| 840 |
wires) it may look nice to make them thicker. An example is the |
| 841 |
|make contact| symbol. |
| 842 |
|
| 843 |
Compare |
| 844 |
% |
| 845 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 846 |
\tikz [circuit ee IEC,circuit symbol lines/.style={draw,very thick}] |
| 847 |
\draw (0,0) to [capacitor={near start}, |
| 848 |
make contact={near end}] (3,0); |
| 849 |
\end{codeexample} |
| 850 |
% |
| 851 |
to |
| 852 |
% |
| 853 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 854 |
\tikz [circuit ee IEC,circuit symbol wires/.style={draw,very thick}] |
| 855 |
\draw (0,0) to [capacitor={near start}, |
| 856 |
make contact={near end}] (3,0); |
| 857 |
\end{codeexample} |
| 858 |
\end{stylekey} |
| 859 |
\end{itemize} |
| 860 |
|
| 861 |
All circuit environments like |circuit logic IEC| mainly use options like |
| 862 |
|set and gate graphic=...| to set up the graphics used for a certain symbol. It |
| 863 |
turns out that graphic hidden in the ``|...|'' part is also always available as |
| 864 |
a separate style, whose name contains the library's initials. For instance, the |
| 865 |
|circuit logic IEC| option actually contains the following command: |
| 866 |
% |
| 867 |
\begin{codeexample}[code only] |
| 868 |
set and gate graphic = and gate IEC graphic, |
| 869 |
\end{codeexample} |
| 870 |
% |
| 871 |
The |and gate IEC graphic| style, in turn, is defined as follows: |
| 872 |
% |
| 873 |
\begin{codeexample}[code only] |
| 874 |
\tikzset{and gate IEC graphic/.style= |
| 875 |
{ |
| 876 |
circuit symbol open, |
| 877 |
circuit symbol size=width 2.5 height 4, |
| 878 |
shape=and gate IEC, |
| 879 |
inner sep=.5ex |
| 880 |
} |
| 881 |
} |
| 882 |
\end{codeexample} |
| 883 |
|
| 884 |
Normally, you do not need to worry about this, since you will not need to |
| 885 |
access a style like |and gate IEC graphic| directly; you will only use the |
| 886 |
|and gate| key. However, sometimes libraries define \emph{variants} of a |
| 887 |
graphic; for instance, there are two variants for the resistor graphic in the |
| 888 |
IEC library. In this case you can set the graphic for the resistor to this |
| 889 |
variant (or back to the original) by saying |set resistor graphic| yourself: |
| 890 |
% |
| 891 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 892 |
\begin{tikzpicture}[circuit ee IEC] |
| 893 |
% Standard resistor |
| 894 |
\draw (0,2) to [resistor] (3,2); |
| 895 |
|
| 896 |
% Var resistor |
| 897 |
\begin{scope}[set resistor graphic=var resistor IEC graphic] |
| 898 |
\draw (0,1) to [resistor] (3,1); |
| 899 |
|
| 900 |
% Back to original |
| 901 |
\draw [set resistor graphic=resistor IEC graphic] |
| 902 |
(0,0) to [resistor] (3,0); |
| 903 |
\end{scope} |
| 904 |
\end{tikzpicture} |
| 905 |
\end{codeexample} |
| 906 |
|
| 907 |
|
| 908 |
\subsection{Logical Circuits} |
| 909 |
|
| 910 |
\subsubsection{Overview} |
| 911 |
|
| 912 |
A \emph{logical circuit} is a circuit that contains what we call \emph{logical |
| 913 |
gates} like an |and gate| or an |xor gate|. The logical libraries are intended |
| 914 |
to make it easy to draw such circuits. |
| 915 |
|
| 916 |
In the following, we first have a look at the different libraries that can be |
| 917 |
used in principle and how the symbols look like. Then we have a more detailed |
| 918 |
look at how the symbols are used. Finally, we discuss the implementation |
| 919 |
details. |
| 920 |
|
| 921 |
There are different ways of depicting logical gates, which is why there are |
| 922 |
different (sub-)libraries for drawing them. They provide the necessary |
| 923 |
graphical representations of the symbols declared in the following library: |
| 924 |
|
| 925 |
\begin{tikzlibrary}{circuits.logic} |
| 926 |
This library declares the logical gate symbols, but does not provide the |
| 927 |
symbol graphics. The library also defines the following key which, however, |
| 928 |
is also only used indirectly, namely by other libraries: |
| 929 |
% |
| 930 |
\begin{key}{/tikz/circuit logic} |
| 931 |
This style calls the keys |circuit| (which internally calls |
| 932 |
|every circuit|, then it defines the |inputs| key and it calls the |
| 933 |
|every circuit logic| key. |
| 934 |
% |
| 935 |
\begin{key}{/tikz/inputs=\meta{inputs}} |
| 936 |
This key is defined only inside the scope of a |circuit logic|. |
| 937 |
There, it has the same effect as |logic gate inputs|, described on |
| 938 |
page~\pageref{logic-gate-inputs}. |
| 939 |
\end{key} |
| 940 |
% |
| 941 |
\begin{stylekey}{/tikz/every circuit logic} |
| 942 |
Use this key to configure the appearance of logical circuits. |
| 943 |
\end{stylekey} |
| 944 |
\end{key} |
| 945 |
\end{tikzlibrary} |
| 946 |
|
| 947 |
Since the |circuits.logic| library does not define any actual graphics, you need |
| 948 |
to use one of the following libraries, instead: |
| 949 |
|
| 950 |
\begin{tikzlibrary}{circuits.logic.IEC} |
| 951 |
This library provides graphics based on gates recommended by the |
| 952 |
International Electrotechnical Commission. When you include this library, |
| 953 |
you can use the following key to set up a scope that contains a logical |
| 954 |
circuit where the gates are shown in this style. |
| 955 |
|
| 956 |
\begin{key}{/tikz/circuit logic IEC} |
| 957 |
This key calls |circuit logic| and installs the IEC-like graphics for |
| 958 |
the logical symbols like |and gate|. |
| 959 |
|
| 960 |
As explained in Section~\ref{section-theming-symbols}, for each graphic |
| 961 |
symbol of the library there is also a style that stores this particular |
| 962 |
appearance. These keys are called |and gate IEC graphic|, |
| 963 |
|or gate IEC graphic|, and so on. |
| 964 |
% |
| 965 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.IEC}}] |
| 966 |
\begin{tikzpicture}[circuit logic IEC, |
| 967 |
every circuit symbol/.style={ |
| 968 |
logic gate IEC symbol color=black, |
| 969 |
fill=blue!20,draw=blue,very thick}] |
| 970 |
\matrix[column sep=7mm] |
| 971 |
{ |
| 972 |
\node (i0) {0}; & & \\ |
| 973 |
& \node [and gate] (a1) {}; & \\ |
| 974 |
\node (i1) {0}; & & \node [or gate] (o) {};\\ |
| 975 |
& \node [nand gate] (a2) {}; & \\ |
| 976 |
\node (i2) {1}; & & \\ |
| 977 |
}; |
| 978 |
\draw (i0.east) -- ++(right:3mm) |- (a1.input 1); |
| 979 |
\draw (i1.east) -- ++(right:3mm) |- (a1.input 2); |
| 980 |
\draw (i1.east) -- ++(right:3mm) |- (a2.input 1); |
| 981 |
\draw (i2.east) -- ++(right:3mm) |- (a2.input 2); |
| 982 |
\draw (a1.output) -- ++(right:3mm) |- (o.input 1); |
| 983 |
\draw (a2.output) -- ++(right:3mm) |- (o.input 2); |
| 984 |
\draw (o.output) -- ++(right:3mm); |
| 985 |
\end{tikzpicture} |
| 986 |
\end{codeexample} |
| 987 |
\end{key} |
| 988 |
\end{tikzlibrary} |
| 989 |
|
| 990 |
\begin{tikzlibrary}{circuits.logic.US} |
| 991 |
This library provides graphics showing ``American'' logic gates. It defines |
| 992 |
the following key: |
| 993 |
|
| 994 |
\begin{key}{/tikz/circuit logic US} |
| 995 |
This style calls |circuit logic| and installs US-like graphics for the |
| 996 |
logical symbols like |and gate|. For instance, it says |
| 997 |
% |
| 998 |
\begin{codeexample}[code only] |
| 999 |
set and gate graphic = and gate US graphic |
| 1000 |
\end{codeexample} |
| 1001 |
|
| 1002 |
Here is an example: |
| 1003 |
% |
| 1004 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.CDH}}] |
| 1005 |
\begin{tikzpicture}[circuit logic CDH, |
| 1006 |
tiny circuit symbols, |
| 1007 |
every circuit symbol/.style={ |
| 1008 |
fill=white,draw}] |
| 1009 |
\matrix[column sep=7mm] |
| 1010 |
{ |
| 1011 |
\node (i0) {0}; & & \\ |
| 1012 |
& \node [and gate] (a1) {}; & \\ |
| 1013 |
\node (i1) {0}; & & \node [or gate] (o) {};\\ |
| 1014 |
& \node [nand gate] (a2) {}; & \\ |
| 1015 |
\node (i2) {1}; & & \\ |
| 1016 |
}; |
| 1017 |
\draw (i0.east) -- ++(right:3mm) |- (a1.input 1); |
| 1018 |
\draw (i1.east) -- ++(right:3mm) |- (a1.input 2); |
| 1019 |
\draw (i1.east) -- ++(right:3mm) |- (a2.input 1); |
| 1020 |
\draw (i2.east) -- ++(right:3mm) |- (a2.input 2); |
| 1021 |
\draw (a1.output) -- ++(right:3mm) |- (o.input 1); |
| 1022 |
\draw (a2.output) -- ++(right:3mm) |- (o.input 2); |
| 1023 |
\draw (o.output) -- ++(right:3mm); |
| 1024 |
\end{tikzpicture} |
| 1025 |
\end{codeexample} |
| 1026 |
\end{key} |
| 1027 |
\end{tikzlibrary} |
| 1028 |
|
| 1029 |
\begin{tikzlibrary}{circuits.logic.CDH} |
| 1030 |
This library provides graphics based on the logic symbols used in A. Croft, |
| 1031 |
R. Davidson, and M. Hargreaves (1992), \emph{Engineering Mathematics}, |
| 1032 |
Addison-Wesley, 82--95. They are identical to the US-style symbols, except |
| 1033 |
for the and- and nand-gates. |
| 1034 |
|
| 1035 |
\begin{key}{/tikz/circuit logic CDH} |
| 1036 |
This key calls |circuit logic US| and installs the two special and- and |
| 1037 |
nand-gates, that is, it uses |set and gate graphic| with |
| 1038 |
|and gate CDH graphic| and likewise for nand-gates. |
| 1039 |
\end{key} |
| 1040 |
\end{tikzlibrary} |
| 1041 |
|
| 1042 |
Inside |circuit logic XYZ| scopes, you can now use the keys shown in |
| 1043 |
Section~\ref{section-logic-symbols}. We have a more detailed look at one of |
| 1044 |
them, all the other work the same way: |
| 1045 |
|
| 1046 |
\begin{key}{/tikz/and gate} |
| 1047 |
This key should be passed to a |node| command. It will cause the node to |
| 1048 |
``look like'' an |and gate|, where the exact appearance of the gate is |
| 1049 |
dictated by the which circuit environment is used. To further configure the |
| 1050 |
appearance of the |and gate|, see Section~\ref{section-theming-symbols}. |
| 1051 |
% |
| 1052 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.IEC}}] |
| 1053 |
\tikz [circuit logic IEC] \node [and gate] {$A$}; |
| 1054 |
\end{codeexample} |
| 1055 |
% |
| 1056 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.US}}] |
| 1057 |
\tikz [circuit logic US] |
| 1058 |
{ |
| 1059 |
\node [and gate,point down] {$A$}; |
| 1060 |
\node [and gate,point down,info=center:$A$] at (1,0) {}; |
| 1061 |
} |
| 1062 |
\end{codeexample} |
| 1063 |
|
| 1064 |
\medskip\textbf{Inputs.} |
| 1065 |
Multiple inputs can be specified for a logic gate (provided they support |
| 1066 |
multiple inputs: a not gate -- also known as an inverter -- does not). |
| 1067 |
However, there is an upper limit for the number of inputs which has been |
| 1068 |
set to 1024, which should be \emph{way} more than would ever be needed. |
| 1069 |
|
| 1070 |
The following key is used to configure the inputs. It is available only |
| 1071 |
inside a |circuit logic| environment. |
| 1072 |
|
| 1073 |
\begin{key}{/tikz/inputs=\meta{input list} (initially \char`\{normal,normal\char`\})} |
| 1074 |
If a gate has $n$ inputs, the \meta{input list} should consists of $n$ |
| 1075 |
letters, each being |i| for ``inverted'' or |n| for ``normal''. |
| 1076 |
Inverted gates will be indicated by a little circle. In any case the |
| 1077 |
anchors for the inputs will be set up appropriately, numbered from top |
| 1078 |
to bottom |input 1|, |input 2|, \ldots and so on. If the gate only |
| 1079 |
supports one input the anchor is simply called |input| with no |
| 1080 |
numerical index. |
| 1081 |
% |
| 1082 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.IEC}}] |
| 1083 |
\begin{tikzpicture}[circuit logic IEC] |
| 1084 |
\node[and gate,inputs={inini}] (A) {}; |
| 1085 |
\foreach \a in {1,...,5} |
| 1086 |
\draw (A.input \a -| -1,0) -- (A.input \a); |
| 1087 |
\draw (A.output) -- ++(right:5mm); |
| 1088 |
\end{tikzpicture} |
| 1089 |
\end{codeexample} |
| 1090 |
\end{key} |
| 1091 |
|
| 1092 |
(This key is just a shorthand for |logic gate inputs|, described in detail |
| 1093 |
on page~\pageref{logic-gate-inputs}. There you will also find descriptions |
| 1094 |
of how to configure the size of the inverted circles and the way the symbol |
| 1095 |
size increases when there are too many inputs.) |
| 1096 |
|
| 1097 |
\textbf{Output.} |
| 1098 |
Every logic gate has one anchor called |output|. |
| 1099 |
\end{key} |
| 1100 |
|
| 1101 |
|
| 1102 |
\subsubsection{Symbols: The Gates} |
| 1103 |
\label{section-logic-symbols} |
| 1104 |
|
| 1105 |
The following table shows which symbols are declared by the main |
| 1106 |
|circuits.logic| library and their appearance in the different sublibraries. |
| 1107 |
\medskip |
| 1108 |
|
| 1109 |
\def\gateexamples#1{% |
| 1110 |
\texttt{#1} |
| 1111 |
\indexkey{#1} & |
| 1112 |
\tikz[baseline,circuit logic IEC] \node[#1,label=] {}; & |
| 1113 |
\tikz[baseline,circuit logic US] \node[#1] {}; & |
| 1114 |
\tikz[baseline,circuit logic CDH] \node[#1] {}; |
| 1115 |
} |
| 1116 |
\begin{tabular}{lccc} |
| 1117 |
\emph{Key} & \emph{Appearance inside} & \emph{Appearance inside} & \emph{Appearance inside} \\ |
| 1118 |
& |circuit logic IEC| & |circuit logic US| & |circuit logic CDH| \\ |
| 1119 |
\gateexamples{/tikz/and gate}\\ |
| 1120 |
\gateexamples{/tikz/nand gate}\\ |
| 1121 |
\gateexamples{/tikz/or gate}\\ |
| 1122 |
\gateexamples{/tikz/nor gate}\\ |
| 1123 |
\gateexamples{/tikz/xor gate}\\ |
| 1124 |
\gateexamples{/tikz/xnor gate}\\ |
| 1125 |
\gateexamples{/tikz/not gate}\\ |
| 1126 |
\gateexamples{/tikz/buffer gate} |
| 1127 |
\end{tabular} |
| 1128 |
|
| 1129 |
|
| 1130 |
\subsubsection{Implementation: The Logic Gates Shape Library} |
| 1131 |
|
| 1132 |
The previous sections described the \tikzname\ interface for creating logical |
| 1133 |
circuits. In this section we take a closer look at the underlying \pgfname\ |
| 1134 |
libraries. |
| 1135 |
|
| 1136 |
Just as there are several \tikzname\ circuit libraries, there are two |
| 1137 |
underlying \pgfname\ shape libraries, one for creating US-style gates and one |
| 1138 |
for IEC-style gates. These libraries define \emph{shapes} only. It is the job |
| 1139 |
of the circuit libraries to ``theme'' them so that they ``look nice''. However, |
| 1140 |
in principle, you can also use these shapes directly. |
| 1141 |
|
| 1142 |
Let us begin with the base library that defines the handling of inputs. |
| 1143 |
|
| 1144 |
\begin{pgflibrary}{shapes.gates.logic} |
| 1145 |
This library defines common keys used by all logical gate shapes. |
| 1146 |
|
| 1147 |
\begin{key}{/pgf/logic gate inputs=\meta{input list} (initially \char`\{normal,normal\char`\})} |
| 1148 |
\label{logic-gate-inputs}% |
| 1149 |
Specify the inputs for the logic gate. The keyword |inverted| indicates |
| 1150 |
an inverted input which will mean \pgfname{} will draw a circle |
| 1151 |
attached to the main shape of the logic gate. Any keyword that is not |
| 1152 |
|inverted| will be treated as a ``normal'' or ``non-inverted'' input |
| 1153 |
(however, for readability, you may wish to use |normal| or |
| 1154 |
|non-inverted|), and \pgfname{} will not draw the circle. In both cases |
| 1155 |
the anchors for the inputs will be set up appropriately, numbered from |
| 1156 |
top to bottom |input 1|, |input 2|, \ldots and so on. If the gate only |
| 1157 |
supports one input the anchor is simply called |input| with no |
| 1158 |
numerical index. |
| 1159 |
% |
| 1160 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.IEC}}] |
| 1161 |
\begin{tikzpicture}[minimum height=0.75cm] |
| 1162 |
\node[and gate IEC, draw, logic gate inputs={inverted, normal, inverted}] |
| 1163 |
(A) {}; |
| 1164 |
\foreach \a in {1,...,3} |
| 1165 |
\draw (A.input \a -| -1,0) -- (A.input \a); |
| 1166 |
\draw (A.output) -- ([xshift=0.5cm]A.output); |
| 1167 |
\end{tikzpicture} |
| 1168 |
\end{codeexample} |
| 1169 |
|
| 1170 |
For multiple inputs it may be somewhat unwieldy to specify a long list, |
| 1171 |
thus, the following ``shorthand'' is permitted (this is an extension of |
| 1172 |
ideas due to Jürgen Werber and Christoph Bartoschek): Using |i| for |
| 1173 |
inverted and |n| for normal inputs, \meta{input list} can be specified |
| 1174 |
\emph{without the commas}. So, for example, |ini| is equivalent to |
| 1175 |
|inverted, normal, inverted|. |
| 1176 |
% |
| 1177 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.US}}] |
| 1178 |
\begin{tikzpicture}[minimum height=0.75cm] |
| 1179 |
\node[or gate US, draw,logic gate inputs=inini] (A) {}; |
| 1180 |
\foreach \a in {1,...,5} |
| 1181 |
\draw (A.input \a -| -1,0) -- (A.input \a); |
| 1182 |
\draw (A.output) -- ([xshift=0.5cm]A.output); |
| 1183 |
\end{tikzpicture} |
| 1184 |
\end{codeexample} |
| 1185 |
\end{key} |
| 1186 |
|
| 1187 |
The height of the gate may be increased to accommodate the number of |
| 1188 |
inputs. In fact, it depends on three variables: $n$, the number of inputs, |
| 1189 |
$r$, the radius of the circle used to indicate an inverted input and $s$, |
| 1190 |
the distance between the centers of the inputs. The default height is then |
| 1191 |
calculated according to the expression $(n+1)\times\max(2r,s)$. This then |
| 1192 |
may be increased to accommodate the node contents or any minimum size |
| 1193 |
specifications. |
| 1194 |
|
| 1195 |
The radius of the inverted input circle and the distance between the |
| 1196 |
centers of the inputs can be customized using the following keys: |
| 1197 |
|
| 1198 |
\begin{key}{/pgf/logic gate inverted radius=\meta{length} (initially 2pt)} |
| 1199 |
Set the radius of the circle that is used to indicate inverted inputs. |
| 1200 |
This is also the radius of the circle used for the inverted output of |
| 1201 |
the |nand|, |nor|, |xnor| and |not| gates. |
| 1202 |
% |
| 1203 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.CDH}}] |
| 1204 |
\begin{tikzpicture}[minimum height=0.75cm] |
| 1205 |
\tikzset{every node/.style={shape=nand gate CDH, draw, logic gate inputs=ii}} |
| 1206 |
\node[logic gate inverted radius=2pt] {A}; |
| 1207 |
\node[logic gate inverted radius=4pt] at (0,-1) {B}; |
| 1208 |
\end{tikzpicture} |
| 1209 |
\end{codeexample} |
| 1210 |
% |
| 1211 |
\end{key} |
| 1212 |
|
| 1213 |
\begin{key}{/pgf/logic gate input sep=\meta{length} (initially .125cm)} |
| 1214 |
Set the distance between the \emph{centers} of the inputs to the logic |
| 1215 |
gate. |
| 1216 |
% |
| 1217 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.IEC}}] |
| 1218 |
\begin{tikzpicture}[minimum size=0.75cm] |
| 1219 |
\draw [help lines] grid (3,2); |
| 1220 |
\tikzset{every node/.style={shape=and gate IEC, draw, logic gate inputs=ini}} |
| 1221 |
\node[logic gate input sep=0.33333cm] at (1,1)(A) {A}; |
| 1222 |
\node[logic gate input sep=0.5cm] at (3,1) (B) {B}; |
| 1223 |
\foreach \a in {1,...,3} |
| 1224 |
\draw (A.input \a -| 0,0) -- (A.input \a) |
| 1225 |
(B.input \a -| 2,0) -- (B.input \a); |
| 1226 |
\end{tikzpicture} |
| 1227 |
\end{codeexample} |
| 1228 |
% |
| 1229 |
\end{key} |
| 1230 |
|
| 1231 |
\pgfname{} will increase the size of the logic gate to accommodate the |
| 1232 |
number of inputs, and the size of the inverted radius and the separation |
| 1233 |
between the inputs. However with all shapes in this library, any increase |
| 1234 |
in size (including any minimum size requirements) will be applied so that |
| 1235 |
the default aspect ratio is unaltered. This means that changing the height |
| 1236 |
will change the width and vice versa. |
| 1237 |
\end{pgflibrary} |
| 1238 |
|
| 1239 |
|
| 1240 |
\subsubsection{Implementation: The US-Style Logic Gates Shape Library} |
| 1241 |
|
| 1242 |
\begin{pgflibrary}{shapes.gates.logic.US} |
| 1243 |
This library provides ``American'' logic gate shapes whose names are |
| 1244 |
suffixed with the identifier |US|. Additionally, alternative |and| and |
| 1245 |
|nand| gates are provided which are based on the logic symbols used in A. |
| 1246 |
Croft, R. Davidson, and M. Hargreaves (1992), \emph{Engineering |
| 1247 |
Mathematics}, Addison-Wesley, 82--95. These two shapes are suffixed with |
| 1248 |
|CDH|. |
| 1249 |
|
| 1250 |
The ``compass point'' anchors apply to the main part of the shape and do |
| 1251 |
not include any inverted inputs or outputs. This library provides an |
| 1252 |
additional feature to facilitate the relative positioning of logic gates: |
| 1253 |
|
| 1254 |
\begin{key}{/pgf/logic gate anchors use bounding box=\meta{boolean} (initially false)} |
| 1255 |
When set to |true| this key will ensure that the compass point anchors |
| 1256 |
use the bounding rectangle of the main shape, which, ignore any |
| 1257 |
inverted inputs or outputs, but includes any |outer sep|. This |
| 1258 |
\emph{only} affects the compass point anchors and is not set on a shape |
| 1259 |
by shape basis: whether the bounding box is used is determined by value |
| 1260 |
of this key when the anchor is accessed. |
| 1261 |
% |
| 1262 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.US}}] |
| 1263 |
\begin{tikzpicture}[minimum height=1.5cm] |
| 1264 |
\node[xnor gate US, draw, gray!50,line width=2pt] (A) {}; |
| 1265 |
\foreach \x/\y/\z in {false/blue/1pt, true/red/2pt} |
| 1266 |
\foreach \a in {north, south, east, west, north east, |
| 1267 |
south east, north west, south west} |
| 1268 |
\draw[logic gate anchors use bounding box=\x, color=\y] |
| 1269 |
(A.\a) circle(\z); |
| 1270 |
\end{tikzpicture} |
| 1271 |
\end{codeexample} |
| 1272 |
% |
| 1273 |
\end{key} |
| 1274 |
|
| 1275 |
The library defines a number of shapes. For each shape the allowed number |
| 1276 |
of inputs is also shown: |
| 1277 |
% |
| 1278 |
\begin{itemize} |
| 1279 |
\item |and gate US|, two or more inputs |
| 1280 |
\item |and gate CDH|, two or more inputs |
| 1281 |
\item |nand gate US|, two or more inputs |
| 1282 |
\item |nand gate CDH|, two or more inputs |
| 1283 |
\item |or gate US|, two or more inputs |
| 1284 |
\item |nor gate US|, two or more Inputs |
| 1285 |
\item |xor gate US|, two inputs |
| 1286 |
\item |xnor gate US|, two inputs |
| 1287 |
\item |not gate US|, one input |
| 1288 |
\item |buffer gate US|, one input |
| 1289 |
\end{itemize} |
| 1290 |
|
| 1291 |
In the following, we only have a detailed look at the anchors defined by |
| 1292 |
one of them. We choose the |nand gate US| because it shows all the |
| 1293 |
``interesting'' anchors. |
| 1294 |
|
| 1295 |
\begin{shape}{nand gate US} |
| 1296 |
This shape is a nand gate, which supports two or more inputs. If less |
| 1297 |
than two inputs are specified an error will result. The anchors for |
| 1298 |
this gate with two non-inverted inputs (using the normal compass point |
| 1299 |
anchors) are shown below. Anchor |30| is an example of a border anchor. |
| 1300 |
% |
| 1301 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.US}}] |
| 1302 |
\Huge |
| 1303 |
\begin{tikzpicture} |
| 1304 |
\node[name=s,shape=nand gate US,shape example, inner sep=0cm, |
| 1305 |
logic gate inputs={in}, |
| 1306 |
logic gate inverted radius=.5cm] {Nand Gate\vrule width1pt height2cm}; |
| 1307 |
\foreach \anchor/\placement in |
| 1308 |
{center/above, text/above, 30/above right, |
| 1309 |
mid/right, mid east/left, mid west/above, |
| 1310 |
base/below, base east/below, base west/left, |
| 1311 |
north/above, south/below, east/above, west/above, |
| 1312 |
north east/above, south east/below, south west/below, north west/above, |
| 1313 |
output/right, input 1/above, input 2/below} |
| 1314 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 1315 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 1316 |
\end{tikzpicture} |
| 1317 |
\end{codeexample} |
| 1318 |
|
| 1319 |
(For the definition of the |shape example| style, see |
| 1320 |
Section~\ref{section-libs-shapes}.) |
| 1321 |
\end{shape} |
| 1322 |
\end{pgflibrary} |
| 1323 |
|
| 1324 |
|
| 1325 |
\subsubsection{Implementation: The IEC-Style Logic Gates Shape Library} |
| 1326 |
|
| 1327 |
\begin{pgflibrary}{shapes.gates.logic.IEC} |
| 1328 |
This library provides rectangular logic gate shapes. These shapes are |
| 1329 |
suffixed with |IEC| as they are based on gates recommended by the |
| 1330 |
International Electrotechnical Commission. |
| 1331 |
|
| 1332 |
By default each gate is drawn with a symbol, $\char`\&$ for |and| and |
| 1333 |
|nand| gates, $\geq1$ for |or| and |nor| gates, $1$ for |not| and |buffer| |
| 1334 |
gates, and $=1$ for |xor| and |xnor| gates. These symbols are drawn |
| 1335 |
automatically (internally they are drawn using the ``foreground'' path), |
| 1336 |
and are not strictly speaking part of the node contents. However, the gate |
| 1337 |
is enlarged to make sure the symbols are within the border of the node. It |
| 1338 |
is possible to change the symbols and their position within the node using |
| 1339 |
the following keys: |
| 1340 |
|
| 1341 |
\begin{key}{/pgf/and gate IEC symbol=\meta{text} (initially \char`\\char\char`\`\char`\\\char`\&)} |
| 1342 |
Set the symbol for the |and gate|. Note that if the node is filled, |
| 1343 |
this color will be used for the symbol, making it invisible, so it will |
| 1344 |
be necessary set \meta{text} to something like |\color{black}\char`\&|. |
| 1345 |
Alternatively, the |logic gate IEC symbol color| key can be used to set |
| 1346 |
the color of all symbols simultaneously. |
| 1347 |
|
| 1348 |
In \tikzname, when the |use IEC style logic gates| key has been used, |
| 1349 |
this key can be replaced by |and gate symbol|. |
| 1350 |
\end{key} |
| 1351 |
|
| 1352 |
\begin{key}{/pgf/nand gate IEC symbol=\meta{text} (initially \char`\\char\char`\`\char`\\\char`\&)} |
| 1353 |
Set the symbol for the |nand gate|. In \tikzname, when the |
| 1354 |
|use IEC style logic gates| key has been used, this key can be replaced |
| 1355 |
by |nand gate symbol|. |
| 1356 |
\end{key} |
| 1357 |
|
| 1358 |
\begin{key}{/pgf/or gate IEC symbol=\meta{text} (initially \char`\$\char`\\geq1\char`\$)} |
| 1359 |
Set the symbol for the |or gate|. In \tikzname, when the |
| 1360 |
|use IEC style logic gates| key has been used, this key can be replaced |
| 1361 |
by |or gate symbol|. |
| 1362 |
\end{key} |
| 1363 |
|
| 1364 |
\begin{key}{/pgf/nor gate IEC symbol=\meta{text} (initially \char`\$\char`\\geq1\char`\$)} |
| 1365 |
Set the symbol for the |nor gate|. In \tikzname, when the |
| 1366 |
|use IEC style logic gates| key has been used, this key can be replaced |
| 1367 |
by |nor gate symbol|. |
| 1368 |
\end{key} |
| 1369 |
|
| 1370 |
\begin{key}{/pgf/xor gate IEC symbol=\meta{text} (initially \char`\{\char`\$=1\char`\$\char`\})} |
| 1371 |
Set the symbol for the |xor gate|. Note the necessity for braces, as |
| 1372 |
the symbol contains |=|. In \tikzname, when the |
| 1373 |
|use IEC style logic gates| key has been used, this key can be replaced |
| 1374 |
by |xor gate symbol|. |
| 1375 |
\end{key} |
| 1376 |
|
| 1377 |
\begin{key}{/pgf/xnor gate IEC symbol=\meta{text} (initially \char`\{\char`\$=1\char`\$\char`\})} |
| 1378 |
Set the symbol for the |xnor gate|. In \tikzname, when the |
| 1379 |
|use IEC style logic gates| key has been used, this key can be replaced |
| 1380 |
by |xnor gate symbol|. |
| 1381 |
\end{key} |
| 1382 |
|
| 1383 |
\begin{key}{/pgf/not gate IEC symbol=\meta{text} (initially 1)} |
| 1384 |
Set the symbol for the |not gate|. In \tikzname, when the |
| 1385 |
|use IEC style logic gates| key has been used, this key can be replaced |
| 1386 |
by |not gate symbol|. |
| 1387 |
\end{key} |
| 1388 |
|
| 1389 |
\begin{key}{/pgf/buffer gate IEC symbol=\meta{text} (initially 1)} |
| 1390 |
Set the symbol for the |buffer gate|. In \tikzname, when the |
| 1391 |
|use IEC style logic gates| key has been used, this key can be replaced |
| 1392 |
by |buffer gate symbol|. |
| 1393 |
\end{key} |
| 1394 |
|
| 1395 |
\begin{key}{/pgf/logic gate IEC symbol align=\meta{align} (initially top)} |
| 1396 |
Set the alignment of the logic gate symbol (in \tikzname, when the |
| 1397 |
|use IEC style logic gates| key has been used, |IEC| can be omitted). |
| 1398 |
The specification in \meta{align} is a comma separated list from |top|, |
| 1399 |
|bottom|, |left| or |right|. The distance between the border of the |
| 1400 |
node and the outer edge of the symbol is determined by the values of |
| 1401 |
the |inner xsep| and |inner ysep|. |
| 1402 |
% |
| 1403 |
\begin{codeexample}[preamble={\usetikzlibrary{shapes.gates.logic.IEC}}] |
| 1404 |
\begin{tikzpicture}[minimum size=1cm, use IEC style logic gates] |
| 1405 |
\tikzset{every node/.style={nor gate, draw}} |
| 1406 |
\node (A) at (0,1.5) {}; |
| 1407 |
\node [logic gate symbol align={bottom, right}] (B) at (0,0) {}; |
| 1408 |
\foreach \g in {A, B}{ |
| 1409 |
\foreach \i in {1,2} |
| 1410 |
\draw ([xshift=-0.5cm]\g.input \i) -- (\g.input \i); |
| 1411 |
\draw (\g.output) -- ([xshift=0.5cm]\g.output); |
| 1412 |
} |
| 1413 |
\end{tikzpicture} |
| 1414 |
\end{codeexample} |
| 1415 |
% |
| 1416 |
\end{key} |
| 1417 |
|
| 1418 |
\begin{key}{/pgf/logic gate IEC symbol color=\meta{color}} |
| 1419 |
This key sets the color for all symbols simultaneously. This color can |
| 1420 |
be overridden on a case by case basis by specifying a color when |
| 1421 |
setting the symbol text. |
| 1422 |
\end{key} |
| 1423 |
|
| 1424 |
The library defines the following shapes: |
| 1425 |
% |
| 1426 |
\begin{itemize} |
| 1427 |
\item |and gate IEC|, two or more inputs |
| 1428 |
\item |nand gate IEC|, two or more inputs |
| 1429 |
\item |or gate IEC|, two or more inputs |
| 1430 |
\item |nor gate IEC|, two or more inputs |
| 1431 |
\item |xor gate IEC|, two inputs |
| 1432 |
\item |xnor gate IEC|, two inputs |
| 1433 |
\item |not gate IEC|, one input |
| 1434 |
\item |buffer gate IEC|, one input |
| 1435 |
\end{itemize} |
| 1436 |
|
| 1437 |
Again, we only have a look at the nand-gate in more detail: |
| 1438 |
|
| 1439 |
\begin{shape}{nand gate IEC} |
| 1440 |
This shape is a nand gate. It supports two or more inputs. If less than |
| 1441 |
two inputs are specified an error will result. The anchors for this |
| 1442 |
gate with two inverted inputs are shown below. Anchor |30| is an |
| 1443 |
example of a border anchor. |
| 1444 |
% |
| 1445 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.logic.IEC}}] |
| 1446 |
\Huge |
| 1447 |
\begin{tikzpicture} |
| 1448 |
\node[name=s,shape=nand gate IEC ,shape example, inner xsep=1cm, inner ysep=1cm, |
| 1449 |
minimum height=6cm, nand gate IEC symbol=\color{black!30}\char`\&, |
| 1450 |
logic gate inputs={in}, |
| 1451 |
logic gate inverted radius=0.65cm] |
| 1452 |
{Nand Gate\vrule width1pt height2cm}; |
| 1453 |
\foreach \anchor/\placement in |
| 1454 |
{center/above, text/above, 30/above right, |
| 1455 |
mid/right, mid east/left, mid west/above, |
| 1456 |
base/below, base east/below, base west/left, |
| 1457 |
north/above, south/below, east/above, west/above, |
| 1458 |
north east/above, south east/below, south west/below, north west/above, |
| 1459 |
output/right, input 1/above, input 2/below} |
| 1460 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 1461 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 1462 |
\end{tikzpicture} |
| 1463 |
\end{codeexample} |
| 1464 |
\end{shape} |
| 1465 |
\end{pgflibrary} |
| 1466 |
|
| 1467 |
|
| 1468 |
\subsection{Electrical Engineering Circuits} |
| 1469 |
|
| 1470 |
\subsubsection{Overview} |
| 1471 |
|
| 1472 |
An \emph{electrical engineering circuit} contains symbols like resistors or |
| 1473 |
capacitors or voltage sources and annotations like the two arrows pointing |
| 1474 |
toward an element whose behaviour is light dependent. The electrical |
| 1475 |
engineering libraries, abbreviated ee-libraries, provide such symbols and |
| 1476 |
annotations. |
| 1477 |
|
| 1478 |
Just as for logical gates, there are different ways of drawing ee-symbols. |
| 1479 |
Currently, there is one main library for drawing circuits, which uses the |
| 1480 |
graphics from the International Electrotechnical Commission, but you can add |
| 1481 |
your own libs. This is why, just as for logical gates, there is a base library |
| 1482 |
and more specific libraries. |
| 1483 |
|
| 1484 |
\begin{tikzlibrary}{circuits.ee} |
| 1485 |
This library declares the ee symbols, but (mostly) does not provide the |
| 1486 |
symbol graphics, which is left to the sublibraries. Just like the logical |
| 1487 |
gates library, a key is defined that is normally only used internally: |
| 1488 |
% |
| 1489 |
\begin{key}{/tikz/circuit ee} |
| 1490 |
This style calls the keys |circuit| (which internally calls |
| 1491 |
|every circuit| and the following style: |
| 1492 |
% |
| 1493 |
\begin{stylekey}{/tikz/every circuit ee} |
| 1494 |
Use this key to configure the appearance of logical circuits. |
| 1495 |
\end{stylekey} |
| 1496 |
\end{key} |
| 1497 |
|
| 1498 |
The library also declares some standard annotations and units. |
| 1499 |
\end{tikzlibrary} |
| 1500 |
|
| 1501 |
As for logical circuits, to draw a circuit the first step is to include a |
| 1502 |
library containing the symbols graphics. Currently, you have to include |
| 1503 |
|circuits.ee.IEC|. |
| 1504 |
|
| 1505 |
\begin{tikzlibrary}{circuits.ee.IEC} |
| 1506 |
When this library is loaded, you can use the following style: |
| 1507 |
% |
| 1508 |
\begin{key}{/tikz/circuit ee IEC} |
| 1509 |
This style calls |circuit ee| and installs the IEC-like graphics for |
| 1510 |
the logical symbols like |resistor|. |
| 1511 |
\end{key} |
| 1512 |
\end{tikzlibrary} |
| 1513 |
|
| 1514 |
Inside the |circuit ee IEC| scope, you can now use the keys for symbols, units, |
| 1515 |
and annotations listed in the later sections. We have a more detailed look at |
| 1516 |
one of each of them, all the others work the same way. |
| 1517 |
|
| 1518 |
Let us start with an example of a symbol: the resistor symbol. The other |
| 1519 |
predefined symbols are listed in Section~\ref{section-circuits-ee-symbols} and |
| 1520 |
later sections. |
| 1521 |
|
| 1522 |
\begin{key}{/tikz/resistor=\opt{\meta{options}}} |
| 1523 |
This key should be used with a |node| path command or with the |to| path |
| 1524 |
command. |
| 1525 |
|
| 1526 |
\medskip\textbf{Using the Key with Normal Nodes.} |
| 1527 |
When used with a node, it will cause this node to ``look like'' a resistor |
| 1528 |
(by default, in the IEC library, this is just a simple rectangle). |
| 1529 |
% |
| 1530 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1531 |
\tikz [circuit ee IEC] |
| 1532 |
\node [resistor] {}; |
| 1533 |
\end{codeexample} |
| 1534 |
|
| 1535 |
Unlike normal nodes, a resistor node generally should not take any text (as |
| 1536 |
in |node [resistor] {foo}|). Instead, the labeling of resistors should be |
| 1537 |
done using the |label|, |info| and |ohm| options. |
| 1538 |
% |
| 1539 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1540 |
\tikz [circuit ee IEC] |
| 1541 |
\node [resistor,ohm=5] {}; |
| 1542 |
\end{codeexample} |
| 1543 |
|
| 1544 |
The \meta{options} make no real sense when the |resistor| option is used |
| 1545 |
with a normal node, you can just as well given them to the |node| itself. |
| 1546 |
Thus, the following has the same effect as the above example: |
| 1547 |
% |
| 1548 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1549 |
\tikz [circuit ee IEC] |
| 1550 |
\node [resistor={ohm=5}] {}; |
| 1551 |
\end{codeexample} |
| 1552 |
|
| 1553 |
In a circuit, you will often wish to rotate elements. For this, the options |
| 1554 |
|point up|, |point down|, |point left| or |point right| may be especially |
| 1555 |
useful. They are just shorthands for appropriate rotations like |
| 1556 |
|rotate=90|. |
| 1557 |
% |
| 1558 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1559 |
\tikz [circuit ee IEC] { |
| 1560 |
\node (R1) [resistor,point up,ohm=5] at (3,1) {}; |
| 1561 |
\node (R2) [resistor,ohm=10k] at (0,0) {}; |
| 1562 |
\draw (R2) -| (R1); |
| 1563 |
} |
| 1564 |
\end{codeexample} |
| 1565 |
|
| 1566 |
\medskip\textbf{Using the Key on a To Path.} |
| 1567 |
When the |resistor| key is used on a |to| path inside a |circuit ee IEC|, |
| 1568 |
the |circuit handle symbol| key is called internally. This has a whole |
| 1569 |
bunch of effects: |
| 1570 |
% |
| 1571 |
\begin{enumerate} |
| 1572 |
\item The path currently being constructed is cut up to make place for |
| 1573 |
a node. |
| 1574 |
\item This node will be a |resistor node| that is rotated so that it |
| 1575 |
points ``along'' the path (unless an option like |shift only| or an |
| 1576 |
extra rotation is used to change this). |
| 1577 |
\item The \meta{options} passed to the |resistor| key are passed on to |
| 1578 |
the node. |
| 1579 |
\item The \meta{options} are pre-parsed to identify a |pos| key or a |
| 1580 |
key like |at start| or |midway|. These keys are used to determine |
| 1581 |
where on the |to| path the node will lie. |
| 1582 |
\end{enumerate} |
| 1583 |
|
| 1584 |
Since the \meta{options} of the |resistor| key are passed on to the |
| 1585 |
resistor node on the path, you can use it to add labels to the node. Here |
| 1586 |
is a simple example: |
| 1587 |
% |
| 1588 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1589 |
\tikz [circuit ee IEC] |
| 1590 |
\draw (0,0) to [resistor=red] (3,0) |
| 1591 |
to [resistor={ohm=2\mu}] (3,2); |
| 1592 |
\end{codeexample} |
| 1593 |
|
| 1594 |
You can add multiple labels to a resistor and you can have multiple |
| 1595 |
resistors (or other elements) on a single path. |
| 1596 |
|
| 1597 |
\medskip\textbf{Inputs, Outputs, and Anchors.} |
| 1598 |
Like the logical gates, all ee-symbols have an |input| and an |output| |
| 1599 |
anchor. Special-purpose-nodes may have even more anchors of this type. |
| 1600 |
Furthermore, the ee-symbols-nodes also have four standard compass direction |
| 1601 |
anchors. |
| 1602 |
|
| 1603 |
\medskip\textbf{Changing the Appearance.} |
| 1604 |
To configure the appearance of all |resistor|s, see |
| 1605 |
Section~\ref{section-theming-symbols}. You can use the \meta{options} to |
| 1606 |
locally change the appearance of a single resistor. |
| 1607 |
\end{key} |
| 1608 |
|
| 1609 |
Let us now have a look at an example of a unit: the Ohm unit. The other |
| 1610 |
predefined units are listed in Section~\ref{section-circuits-units}. |
| 1611 |
|
| 1612 |
\begin{key}{/tikz/ohm=\meta{value}} |
| 1613 |
This key is used to add an |info| label to a node with a special text: |
| 1614 |
|$\mathrm{|\meta{value}|\Omega}$|. In other words, the |ohm| key can only |
| 1615 |
be used with the options of a node and, when used, it will cause the |
| 1616 |
\meta{value} to be placed next to the node, followed by $\Omega$. Since the |
| 1617 |
\meta{value} is typeset inside a |\mathrm| command, when you write |ohm=5k| |
| 1618 |
you get $\mathrm{5k\Omega}$, |ohm=5p| yields $\mathrm{5p\Omega}$, and |
| 1619 |
|ohm=5.6\cdot 10^{2}\mu| yields $\mathrm{5.6\cdot 10^{2}\mu\Omega}$. |
| 1620 |
% |
| 1621 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1622 |
\tikz [circuit ee IEC] \draw (0,0) to [resistor={ohm=5M}] (0,2); |
| 1623 |
\end{codeexample} |
| 1624 |
|
| 1625 |
Instead of |ohm| you can also use |ohm'|, which places the label on the |
| 1626 |
other side. |
| 1627 |
% |
| 1628 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1629 |
\tikz [circuit ee IEC] \draw (0,0) to [resistor={ohm'=5M}] (0,2); |
| 1630 |
\end{codeexample} |
| 1631 |
|
| 1632 |
Finally, there are also keys |ohm sloped| and |ohm' sloped| for having the |
| 1633 |
info label rotate together with the main node. |
| 1634 |
% |
| 1635 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1636 |
\tikz [circuit ee IEC] |
| 1637 |
\draw (0,0) to [resistor={ohm sloped=5M}] (0,2) |
| 1638 |
(2,0) to [resistor={ohm' sloped=6f}] (2,2); |
| 1639 |
\end{codeexample} |
| 1640 |
|
| 1641 |
You can configure the appearance of an Ohm info label using the key |
| 1642 |
|every ohm|. |
| 1643 |
\end{key} |
| 1644 |
|
| 1645 |
Finally, let us have a look at an annotation: the |light emitting| annotation. |
| 1646 |
The other predefined units are listed in |
| 1647 |
Section~\ref{section-circuits-annotations}. |
| 1648 |
|
| 1649 |
\begin{key}{/tikz/light emitting=\opt{\meta{options}}} |
| 1650 |
Like a unit, an annotation should be given as an additional option to a |
| 1651 |
node. It causes some drawings (in this case, two parallel lines) to be |
| 1652 |
placed next to the node. |
| 1653 |
% |
| 1654 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1655 |
\tikz [circuit ee IEC] \draw (0,0) to [diode=light emitting] (2,0); |
| 1656 |
\end{codeexample} |
| 1657 |
|
| 1658 |
The \meta{options} can be used for three different things: |
| 1659 |
% |
| 1660 |
\begin{enumerate} |
| 1661 |
\item You can use keys like |red| to change the appearance of this |
| 1662 |
annotation, locally. |
| 1663 |
\item You can use keys like |<-| or |-latex| to change the direction |
| 1664 |
and kinds of arrows used in the annotation. |
| 1665 |
\item You can use info labels like |ohm=5| or |info=foo| inside the |
| 1666 |
\meta{options}. These info labels will be added to the main node |
| 1667 |
(not to the annotation itself), but the label distance will have |
| 1668 |
been changed to accommodate for the space taken up by the |
| 1669 |
annotation. |
| 1670 |
% |
| 1671 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1672 |
\tikz [circuit ee IEC] |
| 1673 |
{ |
| 1674 |
\draw (0,2) to [diode={light emitting,info=not good}] (2,2); |
| 1675 |
\draw (0,0) to [diode={light emitting={info=better}, |
| 1676 |
info'=also good}] (2,0); |
| 1677 |
} |
| 1678 |
\end{codeexample} |
| 1679 |
\end{enumerate} |
| 1680 |
|
| 1681 |
In addition to |light emitting| there is also a key called |
| 1682 |
|light emitting'|, which simply places the annotation on the other side of |
| 1683 |
the node. |
| 1684 |
|
| 1685 |
You can configure the appearance of annotations in three ways: |
| 1686 |
% |
| 1687 |
\begin{itemize} |
| 1688 |
\item You can set the |every circuit annotation| style. |
| 1689 |
\item You can set the |every light emitting| style. |
| 1690 |
\item You can set the following key: |
| 1691 |
% |
| 1692 |
\begin{stylekey}{/tikz/annotation arrow} |
| 1693 |
This style should set the default |>| arrow to some nice value. |
| 1694 |
\end{stylekey} |
| 1695 |
\end{itemize} |
| 1696 |
\end{key} |
| 1697 |
|
| 1698 |
\def\eelineexample#1#2{% |
| 1699 |
\texttt{#1}\indexkey{#1} |
| 1700 |
& |
| 1701 |
\tikz[baseline=-.5ex,circuit ee IEC] \draw (0,0) to [#1] (3,0); |
| 1702 |
& |
| 1703 |
\relax\def\temp{#2} |
| 1704 |
\ifx\temp\empty\else |
| 1705 |
{\tikz[baseline=-.5ex,circuit ee IEC,set #2 graphic=var #2 IEC graphic] |
| 1706 |
\draw (0,0) to [#2] (3,0);} |
| 1707 |
\fi \\[.2em] |
| 1708 |
} |
| 1709 |
\def\eeendexample#1#2{% |
| 1710 |
\texttt{#1}\indexkey{#1} |
| 1711 |
& |
| 1712 |
\tikz[baseline=-.5ex,circuit ee IEC] \draw (0,0) to [#1={at end}] (1.5,0)(3,0); |
| 1713 |
& |
| 1714 |
\relax\def\temp{#2} |
| 1715 |
\ifx\temp\empty\else |
| 1716 |
{\tikz[baseline=-.5ex,circuit ee IEC,set #2 graphic=var #2 IEC graphic] |
| 1717 |
\draw (0,0) to [#2={at end}] (1.5,0)(3,0);} |
| 1718 |
\fi \\[.2em] |
| 1719 |
} |
| 1720 |
\def\unitexample#1{% |
| 1721 |
\texttt{#1}\indexkey{#1} |
| 1722 |
& |
| 1723 |
\tikz [baseline,inner sep=0pt] \node[#1=1] {};\\ |
| 1724 |
} |
| 1725 |
\def\annotationexample#1{% |
| 1726 |
\texttt{#1}\indexkey{#1} |
| 1727 |
& |
| 1728 |
\tikz[baseline=-.5ex,circuit ee IEC] |
| 1729 |
\draw (0,0) to [resistor={#1}] (2,0) |
| 1730 |
to [diode ={#1'}] (4,0);\\ |
| 1731 |
} |
| 1732 |
\def\empty{} |
| 1733 |
|
| 1734 |
|
| 1735 |
\subsubsection{Symbols: Indicating Current Directions} |
| 1736 |
\label{section-ee-symbols} |
| 1737 |
\label{section-circuits-ee-symbols} |
| 1738 |
|
| 1739 |
There \todosp{why two labels? The first doesn't seem to be used.} are two |
| 1740 |
symbols for indicating current directions. These symbols are defined directly |
| 1741 |
inside |circuit ee|. |
| 1742 |
\medskip |
| 1743 |
|
| 1744 |
\noindent |
| 1745 |
\begin{tabular}{p{5cm}ll} |
| 1746 |
\emph{Key} & \emph{Appearance}\\[.25em] |
| 1747 |
\eelineexample{/tikz/current direction}{} |
| 1748 |
\eelineexample{/tikz/current direction'}{} |
| 1749 |
\end{tabular} |
| 1750 |
|
| 1751 |
\medskip |
| 1752 |
The examples have been produced by (in essence) |
| 1753 |
|\draw (0,0) to[|\meta{symbol name}|] (3,0);|. |
| 1754 |
|
| 1755 |
|
| 1756 |
\subsubsection{Symbols: Basic Elements} |
| 1757 |
|
| 1758 |
The following table show basic symbols as they are depicted inside the |
| 1759 |
|circuit ee IEC| environment. To install one of alternate graphics, you have to |
| 1760 |
say |set| \meta{symbol name} |graphic=var| \meta{symbol name} |IEC graphic|. |
| 1761 |
\medskip |
| 1762 |
|
| 1763 |
\noindent |
| 1764 |
\begin{tabular}{p{5cm}ll} |
| 1765 |
\emph{Key} & \emph{Appearance} & \emph{Alternate appearance} \\[.25em] |
| 1766 |
\eelineexample{/tikz/resistor}{resistor} |
| 1767 |
\eelineexample{/tikz/inductor}{inductor} |
| 1768 |
\eelineexample{/tikz/capacitor}{} |
| 1769 |
\eelineexample{/tikz/battery}{} |
| 1770 |
\eelineexample{/tikz/bulb}{} |
| 1771 |
\eelineexample{/tikz/current source}{} |
| 1772 |
\eelineexample{/tikz/voltage source}{} |
| 1773 |
\eelineexample{/tikz/ac source}{} |
| 1774 |
\eelineexample{/tikz/dc source}{} |
| 1775 |
\eeendexample{/tikz/ground}{} |
| 1776 |
\end{tabular} |
| 1777 |
|
| 1778 |
|
| 1779 |
\subsubsection{Symbols: Diodes} |
| 1780 |
|
| 1781 |
The following table shows diodes as they are depicted inside the |
| 1782 |
|circuit ee IEC| environment. |
| 1783 |
\medskip |
| 1784 |
|
| 1785 |
\noindent |
| 1786 |
\begin{tabular}{p{5cm}ll} |
| 1787 |
\emph{Key} & \emph{Appearance} & \emph{Alternate appearance} \\[.25em] |
| 1788 |
\eelineexample{/tikz/diode}{diode} |
| 1789 |
\eelineexample{/tikz/Zener diode}{Zener diode} |
| 1790 |
\eelineexample{/tikz/Schottky diode}{Schottky diode} |
| 1791 |
\eelineexample{/tikz/tunnel diode}{tunnel diode} |
| 1792 |
\eelineexample{/tikz/backward diode}{backward diode} |
| 1793 |
\eelineexample{/tikz/breakdown diode}{breakdown diode} |
| 1794 |
\end{tabular} |
| 1795 |
|
| 1796 |
|
| 1797 |
\subsubsection{Symbols: Contacts} |
| 1798 |
|
| 1799 |
The following table shows contacts as they are depicted inside the |
| 1800 |
|circuit ee IEC| environment. |
| 1801 |
\medskip |
| 1802 |
|
| 1803 |
\noindent |
| 1804 |
\begin{tabular}{p{5cm}ll} |
| 1805 |
\emph{Key} & \emph{Appearance} & \emph{Alternate appearance} \\[.25em] |
| 1806 |
\eelineexample{/tikz/contact}{} |
| 1807 |
\eelineexample{/tikz/make contact}{make contact} |
| 1808 |
\eelineexample{/tikz/break contact}{} |
| 1809 |
\end{tabular} |
| 1810 |
|
| 1811 |
|
| 1812 |
\subsubsection{Symbols: Measurement devices} |
| 1813 |
|
| 1814 |
The following table shows measurement devices as they are depicted inside the |
| 1815 |
|circuit ee IEC| environment. |
| 1816 |
\medskip |
| 1817 |
|
| 1818 |
\noindent |
| 1819 |
\begin{tabular}{p{5cm}ll} |
| 1820 |
\emph{Key} & \emph{Appearance} \\[.25em] |
| 1821 |
\eelineexample{/tikz/amperemeter}{} |
| 1822 |
\eelineexample{/tikz/voltmeter}{} |
| 1823 |
\eelineexample{/tikz/ohmmeter}{} |
| 1824 |
\end{tabular} |
| 1825 |
|
| 1826 |
|
| 1827 |
\subsubsection{Units} |
| 1828 |
\label{section-circuits-units} |
| 1829 |
|
| 1830 |
The |circuits.ee| library predefines the following unit keys: |
| 1831 |
\medskip |
| 1832 |
|
| 1833 |
\noindent |
| 1834 |
\begin{tabular}{p{5cm}c} |
| 1835 |
\emph{Key} & \emph{Appearance of $1$ unit} \\[.25em] |
| 1836 |
\unitexample{/tikz/ampere} |
| 1837 |
\unitexample{/tikz/volt} |
| 1838 |
\unitexample{/tikz/ohm} |
| 1839 |
\unitexample{/tikz/siemens} |
| 1840 |
\unitexample{/tikz/henry} |
| 1841 |
\unitexample{/tikz/farad} |
| 1842 |
\unitexample{/tikz/coulomb} |
| 1843 |
\unitexample{/tikz/voltampere} |
| 1844 |
\unitexample{/tikz/watt} |
| 1845 |
\unitexample{/tikz/hertz} |
| 1846 |
\end{tabular} |
| 1847 |
|
| 1848 |
|
| 1849 |
\subsubsection{Annotations} |
| 1850 |
\label{section-circuits-annotations} |
| 1851 |
|
| 1852 |
The |circuits.ee.IEC| library defines the following annotations: |
| 1853 |
\medskip |
| 1854 |
|
| 1855 |
\noindent |
| 1856 |
\begin{tabular}{p{5cm}ll} |
| 1857 |
\emph{Key} & \emph{Appearance} \\[.25em] |
| 1858 |
\annotationexample{/tikz/light emitting} |
| 1859 |
\annotationexample{/tikz/light dependent} |
| 1860 |
\annotationexample{/tikz/direction info} |
| 1861 |
\annotationexample{/tikz/adjustable} |
| 1862 |
\end{tabular} |
| 1863 |
\medskip |
| 1864 |
|
| 1865 |
The lines have been produced using, in essence, |
| 1866 |
% |
| 1867 |
\begin{codeexample}[code only] |
| 1868 |
\draw (0,0) to [resistor=light emitting] (2,0) to [diode=light emitting'] (4,0); |
| 1869 |
\end{codeexample} |
| 1870 |
% |
| 1871 |
and similarly for the other annotations. |
| 1872 |
|
| 1873 |
|
| 1874 |
\subsubsection{Implementation: The EE-Symbols Shape Library} |
| 1875 |
|
| 1876 |
The \tikzname\ libraries depend on two shape libraries, which are included |
| 1877 |
automatically. Usually, you will not need to use these shapes directly. |
| 1878 |
|
| 1879 |
\begin{pgflibrary}{shapes.gates.ee} |
| 1880 |
This library defines basic shapes that can be used by all ee-circuit |
| 1881 |
libraries. Currently, it defines the following shapes: |
| 1882 |
% |
| 1883 |
\begin{itemize} |
| 1884 |
\item |rectangle ee| |
| 1885 |
\item |circle ee| |
| 1886 |
\item |direction ee| |
| 1887 |
\end{itemize} |
| 1888 |
% |
| 1889 |
Additionally, the library defines the following arrow tip: The |
| 1890 |
|direction ee| arrow tip is basically the same as a |triangle 45| arrow tip |
| 1891 |
with rounded joins. |
| 1892 |
|
| 1893 |
\begin{tabular}{ll} |
| 1894 |
\symarrow{direction ee} |
| 1895 |
\end{tabular} |
| 1896 |
|
| 1897 |
However, unlike normal arrow tips, its size does \emph{not} depend on the |
| 1898 |
current line width. Rather, it depends on the value of its arrow options, |
| 1899 |
which should be set to the desired size. Thus, you should say something |
| 1900 |
like |\pgfsetarrowoptions{direction ee}{5pt}| to set the size of the arrow. |
| 1901 |
\end{pgflibrary} |
| 1902 |
|
| 1903 |
\begin{shape}{rectangle ee} |
| 1904 |
This shape is completely identical to a normal |rectangle|, only there are |
| 1905 |
two additional anchors: The |input| anchor is an alias for the |west| |
| 1906 |
anchor, while the |output| anchor is an alias for the |east| anchor. |
| 1907 |
\end{shape} |
| 1908 |
|
| 1909 |
\begin{shape}{circle ee} |
| 1910 |
Like the |rectangle ee| shape, only for circles. |
| 1911 |
\end{shape} |
| 1912 |
|
| 1913 |
\begin{shape}{direction ee} |
| 1914 |
This shape is rather special. It is intended to be used to ``turn an arrow |
| 1915 |
tip into a shape''. First, you should set the following key to the name of |
| 1916 |
an arrow tip: |
| 1917 |
% |
| 1918 |
\begin{key}{/pgf/direction ee arrow=\meta{right arrow tip name}} |
| 1919 |
The value of this key will be used for the arrow tip depicted in an |
| 1920 |
|direction ee| shape. |
| 1921 |
\end{key} |
| 1922 |
% |
| 1923 |
When a node of shape |direction ee| is created, several things happen: |
| 1924 |
% |
| 1925 |
\begin{enumerate} |
| 1926 |
\item The size of the shape is computed according to the following |
| 1927 |
rules: The width of the shape is set up so that the left border of |
| 1928 |
the shape is at the left end of the arrow tip and the right border |
| 1929 |
is at the right end of the arrow tip. These left and right ``ends'' |
| 1930 |
of the arrow are the tip end and the back end specified by the |
| 1931 |
arrow itself (see Section~\ref{section-arrow-terminology} for |
| 1932 |
details). You usually need not worry about this width setting. |
| 1933 |
|
| 1934 |
By comparison, the height of the arrow is given by the current |
| 1935 |
setting of |minimum height|. Thus, this key must have been set up |
| 1936 |
correctly to reflect the ``real'' height of the arrow tip. The |
| 1937 |
reason is that the height of an arrow is not specified when arrows |
| 1938 |
are declared and is, thus, not available, here. |
| 1939 |
|
| 1940 |
Possibly, the height computation will change in the future to |
| 1941 |
reflect the real height of the arrow, so you should generally set |
| 1942 |
up the |minimum height| to be the same as the real height. |
| 1943 |
\item A straight line from left to right inside the shape's boundaries |
| 1944 |
is added to the background path. |
| 1945 |
\item The arrow tip, pointing right, is drawn before the background |
| 1946 |
path. |
| 1947 |
\end{enumerate} |
| 1948 |
% |
| 1949 |
The anchors of this shape are just the compass anchors, which lie on a |
| 1950 |
rectangle whose width and height are the above-computed height and width. |
| 1951 |
% |
| 1952 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1953 |
\begin{tikzpicture} |
| 1954 |
\pgfsetarrowoptions{direction ee}{6cm} |
| 1955 |
\node[name=s,shape=direction ee,shape example,minimum height=0.7654*6cm] {}; |
| 1956 |
\foreach \anchor/\placement in |
| 1957 |
{center/above, 30/above right, |
| 1958 |
north/above, south/below, east/left, west/right, |
| 1959 |
north east/above, south east/below, south west/below, north west/above, |
| 1960 |
input/left,output/right} |
| 1961 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 1962 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 1963 |
\end{tikzpicture} |
| 1964 |
\end{codeexample} |
| 1965 |
|
| 1966 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 1967 |
\begin{tikzpicture}[direction ee arrow=angle 45] |
| 1968 |
\node[name=s,shape=direction ee,shape example,minimum height=1.75cm] {}; |
| 1969 |
\foreach \anchor/\placement in {north/above, south/below, |
| 1970 |
output/right, input/left} |
| 1971 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 1972 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 1973 |
\end{tikzpicture} |
| 1974 |
\end{codeexample} |
| 1975 |
% |
| 1976 |
\end{shape} |
| 1977 |
|
| 1978 |
|
| 1979 |
\subsubsection{Implementation: The IEC-Style EE-Symbols Shape Library} |
| 1980 |
|
| 1981 |
\begin{pgflibrary}{shapes.gates.ee.IEC} |
| 1982 |
This library defines shapes for depicting ee symbols according to the IEC |
| 1983 |
recommendations. These shapes will typically be used in conjunction with |
| 1984 |
the graphic mechanism detailed earlier, but you can also used them |
| 1985 |
directly. |
| 1986 |
\end{pgflibrary} |
| 1987 |
|
| 1988 |
\begin{shape}{generic circle IEC} |
| 1989 |
This shape inherits from |circle ee|, which in turn is just a normal |
| 1990 |
|circle| with additional |input| and |output| anchors at the left and right |
| 1991 |
ends. However, additionally, this shape allows you to specify a path that |
| 1992 |
should be added before the background path using the following key: |
| 1993 |
% |
| 1994 |
\begin{key}{/pgf/generic circle IEC/before background=\meta{code}} |
| 1995 |
When a node of shape |generic circle IEC| is created, the current |
| 1996 |
setting of this key is used as the ``before background path''. This |
| 1997 |
means that after the circle's background has been |
| 1998 |
drawn/filled/whatever, the \meta{code} is executed. |
| 1999 |
|
| 2000 |
When the \meta{code} is executed, the coordinate system will have been |
| 2001 |
transformed in such a way that the point $(1\mathrm{pt},0\mathrm{pt})$ |
| 2002 |
lies at the right end of the circle and $(0\mathrm{pt},1\mathrm{pt})$ |
| 2003 |
lies at the top of the circle. (More precisely, these points will lie |
| 2004 |
exactly on the middle of the radial line.) |
| 2005 |
\end{key} |
| 2006 |
% |
| 2007 |
Here is an examples of how to use this shape: |
| 2008 |
% |
| 2009 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2010 |
\tikz \node [generic circle IEC, |
| 2011 |
/pgf/generic circle IEC/before background={ |
| 2012 |
\pgfpathmoveto{\pgfpointorigin} |
| 2013 |
\pgfpathlineto{\pgfpoint{1pt}{0pt}} |
| 2014 |
\pgfpathlineto{\pgfpoint{0pt}{1pt}} |
| 2015 |
\pgfpathlineto{\pgfpoint{-0.5pt}{-0.5pt}} |
| 2016 |
\pgfusepathqstroke |
| 2017 |
}, |
| 2018 |
draw] {Hello world}; |
| 2019 |
\end{codeexample} |
| 2020 |
% |
| 2021 |
\end{shape} |
| 2022 |
|
| 2023 |
\begin{shape}{generic diode IEC} |
| 2024 |
This shape is used to depict diodes. The main shape is taken up by a |
| 2025 |
``right pointing'' triangle. The anchors are positioned on the border of a |
| 2026 |
rectangle around the diode, see the below example. The diode's size is |
| 2027 |
based on the current settings of |minimum width| and |minimum height|. |
| 2028 |
% |
| 2029 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2030 |
\begin{tikzpicture} |
| 2031 |
\node[name=s,shape=generic diode IEC,shape example,minimum size=6cm] {}; |
| 2032 |
\foreach \anchor/\placement in |
| 2033 |
{center/above, 30/above right, |
| 2034 |
north/above, south/below, east/left, west/right, |
| 2035 |
north east/above, south east/below, south west/below, north west/above, |
| 2036 |
input/left,output/right} |
| 2037 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 2038 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 2039 |
\end{tikzpicture} |
| 2040 |
\end{codeexample} |
| 2041 |
|
| 2042 |
This shape, like the |generic circle IEC| shape, is generic in the sense |
| 2043 |
that there is a special key that is used for the before background |
| 2044 |
drawings: |
| 2045 |
% |
| 2046 |
\begin{key}{/pgf/generic diode IEC/before background=\meta{code}} |
| 2047 |
Similarly to the |generic circle IEC| shape, when a node of shape |
| 2048 |
|generic diode IEC| is created, the current setting of this key is used |
| 2049 |
as the ``before background path''. When the \meta{code} is executed, |
| 2050 |
the coordinate system will have been transformed in such a way that the |
| 2051 |
origin is at the ``tip'' of the diode's triangle, the point |
| 2052 |
$(0\mathrm{pt},1\mathrm{pt})$ is exactly half the diode's height above |
| 2053 |
this origin, and the point $(1\mathrm{pt},0\mathrm{pt})$ is half the |
| 2054 |
diode's height to the right of the origin. |
| 2055 |
|
| 2056 |
The idea is that you use this key to draw different kinds of diode |
| 2057 |
endings. |
| 2058 |
% |
| 2059 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2060 |
\tikz \node [minimum size=1cm,generic diode IEC, |
| 2061 |
/pgf/generic diode IEC/before background={ |
| 2062 |
\pgfpathmoveto{\pgfqpoint{-.5pt}{-1pt}} |
| 2063 |
\pgfpathlineto{\pgfqpoint{.5pt}{-1pt}} |
| 2064 |
\pgfpathmoveto{\pgfqpoint{0pt}{-1pt}} |
| 2065 |
\pgfpathlineto{\pgfqpoint{0pt}{1pt}} |
| 2066 |
\pgfpathmoveto{\pgfqpoint{-.5pt}{1pt}} |
| 2067 |
\pgfpathlineto{\pgfqpoint{.5pt}{1pt}} |
| 2068 |
\pgfusepathqstroke |
| 2069 |
}, |
| 2070 |
draw] {}; |
| 2071 |
\end{codeexample} |
| 2072 |
\end{key} |
| 2073 |
\end{shape} |
| 2074 |
|
| 2075 |
\begin{shape}{breakdown diode IEC} |
| 2076 |
This shape is used to depict a bidirectional breakdown diode. The diode's |
| 2077 |
size is based on the current settings of |minimum width| and |
| 2078 |
|minimum height|. |
| 2079 |
% |
| 2080 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2081 |
\begin{tikzpicture} |
| 2082 |
\node[name=s,shape=breakdown diode IEC,shape example,minimum width=6cm,minimum height=4cm] {}; |
| 2083 |
\foreach \anchor/\placement in |
| 2084 |
{center/above, 30/above right, |
| 2085 |
north/above, south/below, east/left, west/right, |
| 2086 |
north east/above, south east/below, south west/below, north west/above, |
| 2087 |
input/left,output/right} |
| 2088 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 2089 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 2090 |
\end{tikzpicture} |
| 2091 |
\end{codeexample} |
| 2092 |
% |
| 2093 |
\end{shape} |
| 2094 |
|
| 2095 |
\begin{shape}{var resistor IEC} |
| 2096 |
This shape is used to depict a variant version of a resistor. Its size is |
| 2097 |
computed as for a rectangle (thus, its size depends things like the |
| 2098 |
|minimum height|). Then, inside this rectangle, a background path is set up |
| 2099 |
according to the following rule: Starting from the left end, zigzag |
| 2100 |
segments are added to the path. Each segment consists of a line at a 45 |
| 2101 |
degree angle going up to the top of the rectangle, then going down to the |
| 2102 |
bottom, then going up to mid height of the node. As many segments as |
| 2103 |
possible are put inside as possible. The last segment is then connected to |
| 2104 |
the output anchor via a straight line. |
| 2105 |
|
| 2106 |
All of this means that, in general, the shape should be much wider than |
| 2107 |
high. |
| 2108 |
% |
| 2109 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2110 |
\begin{tikzpicture} |
| 2111 |
\node[name=s,shape=var resistor IEC,shape example,minimum width=7cm,minimum height=1cm] {}; |
| 2112 |
\foreach \anchor/\placement in |
| 2113 |
{center/above, 30/above right, |
| 2114 |
north/above, south/below, east/left, west/right, |
| 2115 |
north east/above, south east/below, south west/below, north west/above, |
| 2116 |
input/left,output/right} |
| 2117 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 2118 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 2119 |
\end{tikzpicture} |
| 2120 |
\end{codeexample} |
| 2121 |
% |
| 2122 |
\end{shape} |
| 2123 |
|
| 2124 |
\begin{shape}{inductor IEC} |
| 2125 |
This shape is used to depict an inductor, using a bumpy line. Its size is |
| 2126 |
computed as follows: Any text and |inner sep| are ignored (and should |
| 2127 |
normally not be given). The |minimum height| plus (twice) the |outer ysep| |
| 2128 |
specify the distance between the |north| and |south| anchors, similarly for |
| 2129 |
the |minimum width| plus the |outer xsep| for the |east| and |west|. The |
| 2130 |
bumpy line is drawn starting from the lower left corner to the lower right |
| 2131 |
corner with bumps being half-circles whose height is exactly the |
| 2132 |
|minimum height|. The |center| of the shape is just above the |south| |
| 2133 |
anchor, at a distance of the |outer ysep|. |
| 2134 |
% |
| 2135 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2136 |
\begin{tikzpicture} |
| 2137 |
\node[name=s,shape=inductor IEC,shape example,minimum width=7cm,minimum height=1cm] {}; |
| 2138 |
\foreach \anchor/\placement in |
| 2139 |
{center/above, 30/above right, |
| 2140 |
north/above, south/below, east/left, west/right, |
| 2141 |
north east/above, south east/below, south west/below, north west/above, |
| 2142 |
input/left,output/right} |
| 2143 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 2144 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 2145 |
\end{tikzpicture} |
| 2146 |
\end{codeexample} |
| 2147 |
% |
| 2148 |
Just as for a |var resistor IEC|, as many bumps as possible are added and |
| 2149 |
the last bump is connected to the output anchor via a straight line. |
| 2150 |
\end{shape} |
| 2151 |
|
| 2152 |
\begin{shape}{capacitor IEC} |
| 2153 |
This shape is based on a |rectangle ee|. However, instead of a rectangle as |
| 2154 |
the background path, only the ``left and right lines'' that make up the |
| 2155 |
rectangle are drawn. |
| 2156 |
% |
| 2157 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2158 |
\begin{tikzpicture} |
| 2159 |
\node[name=s,shape=capacitor IEC,shape example, |
| 2160 |
minimum width=2cm,minimum height=3cm,inner sep=0pt] {}; |
| 2161 |
\foreach \anchor/\placement in |
| 2162 |
{center/above, 30/above right, |
| 2163 |
north/above, south/below, east/left, west/right, |
| 2164 |
north east/above, south east/below, south west/below, north west/above, |
| 2165 |
input/left,output/right} |
| 2166 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 2167 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 2168 |
\end{tikzpicture} |
| 2169 |
\end{codeexample} |
| 2170 |
% |
| 2171 |
\end{shape} |
| 2172 |
|
| 2173 |
\begin{shape}{battery IEC} |
| 2174 |
This shape is similar to a |capacitor IEC|, however, the right line is only |
| 2175 |
half the height of the left line. |
| 2176 |
% |
| 2177 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2178 |
\tikz \node[shape=battery IEC,shape example,minimum size=2cm, |
| 2179 |
inner sep=0pt] {}; |
| 2180 |
\end{codeexample} |
| 2181 |
% |
| 2182 |
\end{shape} |
| 2183 |
|
| 2184 |
\begin{shape}{ground IEC} |
| 2185 |
This shape is similar to a |batter IEC|, only three lines of different |
| 2186 |
heights are drawn. |
| 2187 |
% |
| 2188 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2189 |
\tikz \node[shape=ground IEC,shape example,minimum size=2cm, |
| 2190 |
inner sep=0pt] {}; |
| 2191 |
\end{codeexample} |
| 2192 |
% |
| 2193 |
\end{shape} |
| 2194 |
|
| 2195 |
\begin{shape}{make contact IEC} |
| 2196 |
This shape consists of a line going from the lower left corner to the upper |
| 2197 |
right corner. The size and anchors of this shape are computed in the same |
| 2198 |
way as for an |inductor IEC|. |
| 2199 |
% |
| 2200 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2201 |
\begin{tikzpicture} |
| 2202 |
\node[name=s,shape=make contact IEC,shape example,minimum width=3cm,minimum height=1cm] {}; |
| 2203 |
\foreach \anchor/\placement in |
| 2204 |
{center/above, 30/above right, |
| 2205 |
north/above, south/below, east/left, west/right, |
| 2206 |
north east/above, south east/below, south west/below, north west/above, |
| 2207 |
input/left,output/right} |
| 2208 |
\draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} |
| 2209 |
node[\placement] {\scriptsize\texttt{(s.\anchor)}}; |
| 2210 |
\end{tikzpicture} |
| 2211 |
\end{codeexample} |
| 2212 |
% |
| 2213 |
\end{shape} |
| 2214 |
|
| 2215 |
\begin{shape}{var make contact IEC} |
| 2216 |
This shape works like |make contact IEC|, only a little circle is added to |
| 2217 |
the path at the lower left corner. The radius of this circle is one twelfth |
| 2218 |
of the width of the node. |
| 2219 |
% |
| 2220 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2221 |
\tikz \node[shape=var make contact IEC,shape example, |
| 2222 |
minimum height=1cm,minimum width=3cm,inner sep=0pt] {}; |
| 2223 |
\end{codeexample} |
| 2224 |
% |
| 2225 |
\end{shape} |
| 2226 |
|
| 2227 |
\begin{shape}{break contact IEC} |
| 2228 |
This shape depicts a contact that can be broken. It works like |
| 2229 |
|make contact IEC|. |
| 2230 |
% |
| 2231 |
\begin{codeexample}[preamble={\usetikzlibrary{circuits.ee.IEC}}] |
| 2232 |
\tikz \node[shape=break contact IEC,shape example, |
| 2233 |
minimum height=1cm,minimum width=3cm,inner sep=0pt] {}; |
| 2234 |
\end{codeexample} |
| 2235 |
% |
| 2236 |
\end{shape} |