Debian Codegraph @

texmf-dist/tex/generic/circuitikz/pgfcirc.defines.tex

raw
1 % Copyright 2018-2026 by Romano Giannetti
2 % Copyright 2015-2026 by Stefan Lindner
3 % Copyright 2013-2026 by Stefan Erhardt
4 % Copyright 2007-2026 by Massimo Redaelli
5 %
6 % This file may be distributed and/or modified
7 %
8 % 1. under the LaTeX Project Public License and/or
9 % 2. under the GNU Public License.
10 %
11 % See the files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.
12 %
13 % This file has folding marks for vim (See last line).
14 %
15
16 %
17 % This file is loaded *before* the options for the package are executed, mainly
18 % for the following three ifs
19 %
20 % these three ifs are fundamental for the package loading options;
21 % do not move away
22 \newif\ifpgf@circ@siunitx
23 \newif\ifpgf@circ@siunitx@res
24 \newif\ifpgf@circuit@compat
25
26 %% Key managements%<<<1
27
28 \long\def\pgf@circ@comment#1{}
29
30 \def\circuitikzbasekey{/tikz/circuitikz}
31
32 \pgfkeys{\circuitikzbasekey/.is family}
33
34 \def\circuitikzset{\expandafter\pgfqkeys\expandafter{\circuitikzbasekey}}
35 \let\ctikzset\circuitikzset
36 \def\ctikzvalof#1{\pgfkeysvalueof{\circuitikzbasekey/#1}}
37 \def\ctikzsetvalof#1#2{\pgfkeyssetvalue{\circuitikzbasekey/#1}{#2}}
38
39 \pgfkeys{\circuitikzbasekey/.search also={/tikz}}
40 %%>>>
41
42 %% Temporary Counters and dimensions%<<<1
43 %% Temporary Counters
44 \newcount\pgf@circ@count@a
45 \newcount\pgf@circ@count@b
46 \newcount\pgf@circ@count@c
47 %%%%%%%%%%%%
48 %% Dimensions
49 % coordinate
50 \newdimen\pgf@circ@res@up
51 \newdimen\pgf@circ@res@down
52 \newdimen\pgf@circ@res@zero
53 \newdimen\pgf@circ@res@left
54 \newdimen\pgf@circ@res@right
55 \newdimen\pgf@circ@res@other
56 \newdimen\pgf@circ@res@step
57 \newdimen\pgf@circ@res@temp
58 % Base len for all circuitikz
59 \newdimen\pgf@circ@Rlen
60 % scaled length for internal use in scalable shapes
61 \newdimen\pgf@circ@scaled@Rlen
62 \ctikzset{%
63 bipoles/length/.code={%
64 \pgf@circ@Rlen = #1\relax
65 % by default scale is 1.0
66 \pgf@circ@scaled@Rlen=\pgf@circ@Rlen
67 \ctikzsetvalof{bipoles/length}{#1}%
68 }%
69 ,bipoles/length=1.4cm%
70 }
71 % initial thickness
72 \newdimen \pgfstartlinewidth
73 %%>>>
74
75 %% Colors%<<<
76
77 % The following code is by @muzimuzhi --- see comment in
78 % https://github.com/circuitikz/circuitikz/issues/605#issuecomment-1030745366
79 \newif\ifpgf@circ@setcolor
80
81 % similar to how `/tikz/draw` and `/tikz/fill` are defined
82 %
83 % - `color=none`, \pgfusecolor is not executed at the beginning of node path(s)
84 % - `color` or `color=` (no or empty value), ignored
85 % - `color=<color name>`, \pgfusecolor{<color name>} will be executed
86 \ctikzset{
87 color/.code={%
88 \edef\pgf@circ@temp{#1}%
89 \ifx\pgf@circ@temp\pgf@nonetext
90 \pgf@circ@setcolorfalse
91 \else
92 \ifx\pgf@circ@temp\pgfutil@empty
93 \else
94 \pgf@circ@setcolortrue
95 \pgfkeyssetvalue{\circuitikzbasekey/color}{#1}%
96 \edef\ctikz@strokecolor{\ctikzvalof{color}}%
97 \fi
98 \fi
99 },
100 % init
101 color=none
102 }
103
104 \let\ctikz@strokecolor\pgfutil@empty
105 \let\ctikz@fillcolor\pgfutil@empty
106 % do our tracking of color
107 \pgfkeys{/tikz/color/.add code={}{%
108 \edef\ctikz@strokecolor{#1}\ctikzset{color={#1}}}}
109 % do our tracking of fill
110 \pgfkeys{/tikz/fill/.add code={}{%
111 \edef\ctikz@fillcolor{#1}}}
112 %
113 % This is to try to track the "implicit" color specification of Tikz,
114 % like \draw[red,...] ...; which are not exactly the same than saying
115 % \draw[color=red,...] ...;
116 % This is too dangerous to issue by default (it was in 1.5.0 and it
117 % was an error), so we will just define a command and tell it in the
118 % manual.
119 % It needs \usepackage{regexpatch} (which is not compatible with
120 % xpatch, unfortunately)
121 % I do not know how to do the xpatchcmd in ConTeXt...
122 %
123 \def\ctikzPatchImplicitColor{%
124 \ifpgfutil@format@is@latex
125 \pgfkeysgetvalue{/tikz/.unknown/.@cmd}{\my@temp}
126 \xpatchcmd*\my@temp % use starred-form to replace all (two places actually)
127 {\expandafter\tikz@addoption\expandafter}
128 {\edef\ctikz@strokecolor{\tikz@key}%
129 \expandafter\tikz@addoption\expandafter}
130 {}{%
131 \pgfutil@packagewarning{circuitikz}{%
132 Color patch failed, use only explicit color=... (see manual)}}
133 \pgfkeyslet{/tikz/.unknown/.@cmd}{\my@temp}
134 \else
135 \pgfutil@packagewarning{circuitikz}{%
136 Not on LaTeX: patch failed, ^^J%
137 use only explicit color=...(see manual).}
138 \fi
139 }
140 %
141 \def\pgf@circ@setcolor{%
142 \ifpgf@circ@setcolor
143 \pgfsetcolor{\ctikzvalof{color}}%
144 \fi
145 }%
146 %
147 % Try our best to set the fill color the same as the draw
148 % color. This needs the patch above
149 %
150 \def\pgf@circ@setfillcolorasdraw{%
151 \ifx\tikz@strokecolor\pgfutil@empty
152 % we do not have the stroke color. Resort to the
153 % last explicit color command; this will fail if
154 % the color is changed mid-draw.
155 % "Doctor, it hurts if I touch here..."
156 \ifx\ctikz@strokecolor\pgfutil@empty
157 % no info here. Try to use the current color.
158 \pgfsetfillcolor{.}%
159 \else
160 % Try with the last seen change-color command
161 \pgfsetfillcolor{\ctikz@strokecolor}
162 \fi
163 \else
164 % we have strokecolor, yay!
165 \pgfsetfillcolor{\tikz@strokecolor}
166 \fi
167 }
168 % we call this when we want to fill of the "draw"
169 % color. So if we have no explicit color, use ".".
170 \def\pgf@circ@fill@strokecolor{%
171 \pgf@circ@setfillcolorasdraw
172 }
173 % this is to select the \pgftext color; set it as
174 % the stroke color (\pgftext uses the fill color)
175 \def\pgf@circ@text@strokecolor{%
176 \pgf@circ@setfillcolorasdraw
177 }
178 % debug text
179 \def\pgf@circ@debug@colors{%
180 \pgfscope
181 \pgfsetcolor{black}%
182 \pgftext[y=10pt]{\tiny S:\tikz@strokecolor~T:\tikz@textcolor~F:\tikz@fillcolor}%
183 \pgftext[y=16pt]{\tiny CS:\ctikz@strokecolor~CF:\ctikz@fillcolor}%
184 \endpgfscope
185 }
186 %>>>
187
188 %% Macros for basic drawing%<<<
189 %
190 \long\gdef\pgf@circ@draw@component#1{%
191 \behindbackgroundpath{%
192 \pgf@circ@start@draw@hooks
193 #1%
194 \pgf@circ@end@draw@hooks
195 }%
196 }%
197 %
198 % auxiliary macros to reset some thing in paths, for background images.
199 % use with care and ALWAYS inside a \pgfscope, see here:
200 % https://matrix.to/#/!NuxCISwYQJuyWwNsEI:matrix.org/$vQO6luq1F66LJ79dERmaqKI46qMBcjStqYCPi725uZE?via=matrix.org&via=2krueger.de&via=im.f3l.de
201 % Thanks to @muzimuzhi
202 %
203 \def\pgf@circ@reset@arrows{%
204 \pgfsetshortenstart{+0pt}\pgfsetshortenend{+0pt}\pgfsetarrows{-}%
205 }
206 \def\pgf@circ@reset@rounded{%
207 \pgfsetcornersarced{\pgfpointorigin}%
208 }
209 \def\pgf@circ@reset@arrows@rounded{%
210 \pgf@circ@reset@arrows\pgf@circ@reset@rounded
211 }
212 \def\pgf@circ@adjustfill{%
213 \ifx\ctikz@fillcolor\pgfutil@empty
214 % do nothing
215 \else
216 \ifx\ctikz@fillcolor\pgf@nonetext
217 % do nothing
218 \else
219 \pgfsetfillcolor{\ctikz@fillcolor}%
220 \fi
221 \fi
222 }
223 %% Hook macros for the start and end of component drawing. The idea is that
224 %% specific macros overrides class macro that overrides generic macro
225 %% the generic macro is the one that resets arrows and curved path parameters
226 %% but let the path inherits the rest (dashed, etc.)
227
228 \def\pgf@circ@start@draw@hooks{%
229 % \typeout{SHAPE: \pgf@sm@shape@name}
230 \ifcsname ctikz@hook@start@draw@component@\pgf@sm@shape@name\endcsname
231 \csname ctikz@hook@start@draw@component@\pgf@sm@shape@name\endcsname
232 \else
233 \ifcsname ctikzclass\endcsname
234 \ifcsname ctikz@hook@start@draw@class@\ctikzclass\endcsname
235 \csname ctikz@hook@start@draw@class@\ctikzclass\endcsname
236 % class defined, but no hook, run generic hook
237 \else
238 \csname ctikz@hook@start@draw@default\endcsname
239 \fi
240 % we have no class, we did not run specific hook:run generic hook
241 \else
242 \csname ctikz@hook@start@draw@default\endcsname
243 \fi
244 \fi
245 }
246 \def\pgf@circ@end@draw@hooks{%
247 % \typeout{SHAPE: \pgf@sm@shape@name}
248 \ifcsname ctikz@hook@end@draw@component@\pgf@sm@shape@name\endcsname
249 \csname ctikz@hook@end@draw@component@\pgf@sm@shape@name\endcsname
250 \else
251 \ifcsname ctikzclass\endcsname
252 \ifcsname ctikz@hook@end@draw@class@\ctikzclass\endcsname
253 \csname ctikz@hook@end@draw@class@\ctikzclass\endcsname
254 % class defined, but no hook, run generic hook
255 \else
256 \csname ctikz@hook@end@draw@default\endcsname
257 \fi
258 % we have no class, we did not run specific hook:run generic hook
259 \else
260 \csname ctikz@hook@end@draw@default\endcsname
261 \fi
262 \fi
263 }
264 %
265 %% default hook is to stop the propagation of arrows parameters and
266 %% arced corners.
267 %
268 \def\ctikz@hook@start@draw@default{\pgf@circ@reset@arrows@rounded}
269 %
270 % we can't use dash pattern (not easily) to draw a fixed number of dashes.
271 % See https://github.com/circuitikz/circuitikz/issues/897
272 %
273 \def\pgf@circ@do@n@hdashes#1#2#3#4{%
274 % this does the following: draw #1 dashes, each of length #2
275 % separated by a blank space of the same length
276 % starting from (#3, #4) and going horizontal
277 \pgf@circ@count@a=0 %
278 \pgfmathloop%
279 \ifnum\pgf@circ@count@a<#1 %
280 \pgfpathmoveto{\pgfpointadd{\pgfpoint{#3}{#4}}{\pgfpoint{(2*\pgf@circ@count@a)*(#2)}{0pt}}}
281 \pgfpathlineto{\pgfpointadd{\pgfpoint{#3}{#4}}{\pgfpoint{(2*\pgf@circ@count@a+1)*(#2)}{0pt}}}
282 \advance\pgf@circ@count@a by 1\relax%
283 \repeatpgfmathloop
284 }
285 %
286 %
287 %>>>
288
289 %% check loaded TikZ/pgf/LaTeX version %<<<
290 %
291 % parse the release date, thanks to Skillmon
292 % https://github.com/pgf-tikz/pgf/issues/1348#issuecomment-2231681032
293 % date can be yyyy-mm-dd or (older TikZ) yyyy/mm/dd
294 \begingroup
295 \pgfutil@protected\def\parsedate#1%
296 {%
297 \afterassignment\parsedate@month
298 \pgf@circ@count@a=#1\relax
299 }
300 \pgfutil@protected\def\parsedate@month#1%
301 {%
302 \afterassignment\parsedate@day
303 \pgf@circ@count@b=%
304 }
305 \pgfutil@protected\def\parsedate@day#1%
306 {%
307 \afterassignment\parsedate@cleanup
308 \pgf@circ@count@c=%
309 }
310 \def\parsedate@cleanup#1\relax{}%
311 \parsedate{\pgfrevisiondate}%
312 \xdef\ctikz@@pgfyear{\the\pgf@circ@count@a}%
313 \xdef\ctikz@@pgfmonth{\the\pgf@circ@count@b}%
314 \xdef\ctikz@@pgfday{\the\pgf@circ@count@c}%
315 \endgroup
316 % The following code thanks to Skillmon:
317 % https://tex.stackexchange.com/a/722570/38080
318 % modified by romano to check the date
319 \def\ctikz@@ifpgfafter@auxi#1#2%
320 {%
321 \ifnum#1
322 \ctikz@@ifpgfafter@auxii{#2}%
323 \fi
324 }
325 \def\ctikz@@ifpgfafter@auxii#1\fi#2\ctikz@@ifpgfafter#3{\fi#1}
326 \def\ctikz@@ifpgfafter#1-#2-#3#%
327 {%
328 \ctikz@@ifpgfafter@auxi{\ctikz@@pgfyear>#1}\pgfutil@firstoftwo
329 \ctikz@@ifpgfafter@auxi{\ctikz@@pgfyear<#1}\pgfutil@secondoftwo
330 \ctikz@@ifpgfafter@auxi{\ctikz@@pgfmonth>#2}\pgfutil@firstoftwo
331 \ctikz@@ifpgfafter@auxi{\ctikz@@pgfmonth<#2}\pgfutil@secondoftwo
332 \ctikz@@ifpgfafter@auxi{\ctikz@@pgfday<#3}\pgfutil@secondoftwo
333 \pgfutil@gobble\ctikz@@ifpgfafter\pgfutil@firstoftwo
334 }
335 %
336 % usage \ctikz@@ifpgfafter 2023-01-16{true}{false}
337 % ^^^ no spaces here, braces needed.
338 %% check if the LaTeX is newer than 2020-10-01. We have to check it
339 %% in the preamble, because in some version the \IfFormat... must be used here
340 %% see https://chastackexchange.com/transcript/message/68697049#68697049
341 \newif\ifctikz@latex@has@hooks
342 \ifpgfutil@format@is@latex\ctikz@latex@has@hooksfalse\fi
343 % if \IfFormat... does not exist is for sure too old!
344 \ifdefined\IfFormatAtLeastTF
345 \IfFormatAtLeastTF{2020-10-01}{\ctikz@latex@has@hookstrue}{}%
346 \fi
347 %
348 %>>>
349
350 %% arrow tips macros and utilities %<<<1
351
352 % the default arrow is latexslim, which has been ported over old arrows library (deprecated)
353 % see https://tex.stackexchange.com/questions/234084/latex-arrow-tip-with-arrows-meta-library
354 % this was the original definition of latex' tips, renamed to avoid clashes
355 %
356 \pgfarrowsdeclare{latexslim}{latexslim}
357 {
358 \pgfutil@tempdima=0.28pt%
359 \advance\pgfutil@tempdima by.3\pgflinewidth%
360 \pgfarrowsleftextend{+-4\pgfutil@tempdima}
361 \pgfarrowsrightextend{+6\pgfutil@tempdima}
362 }
363 {
364 \pgfutil@tempdima=0.28pt%
365 \advance\pgfutil@tempdima by.3\pgflinewidth%
366 \pgfpathmoveto{\pgfqpoint{6\pgfutil@tempdima}{0\pgfutil@tempdima}}
367 \pgfpathcurveto
368 {\pgfqpoint{3.5\pgfutil@tempdima}{.5\pgfutil@tempdima}}
369 {\pgfqpoint{-1\pgfutil@tempdima}{1.5\pgfutil@tempdima}}
370 {\pgfqpoint{-4\pgfutil@tempdima}{3.75\pgfutil@tempdima}}
371 \pgfpathcurveto
372 {\pgfqpoint{-1.5\pgfutil@tempdima}{1\pgfutil@tempdima}}
373 {\pgfqpoint{-1.5\pgfutil@tempdima}{-1\pgfutil@tempdima}}
374 {\pgfqpoint{-4\pgfutil@tempdima}{-3.75\pgfutil@tempdima}}
375 \pgfpathcurveto
376 {\pgfqpoint{-1\pgfutil@tempdima}{-1.5\pgfutil@tempdima}}
377 {\pgfqpoint{3.5\pgfutil@tempdima}{-.5\pgfutil@tempdima}}
378 {\pgfqpoint{6\pgfutil@tempdima}{0\pgfutil@tempdima}}
379 \pgfpathclose
380 \pgfusepathqfill
381 }
382 \pgfarrowsdeclarereversed{latexslim reversed}{latexslim reversed}{latexslim}{latexslim}
383 %% Jack Tap, see
384 %% https://github.com/circuitikz/circuitikz/issues/806
385 \pgfdeclarearrow{name=Jack Tap,
386 parameters = {%
387 \the\pgfarrowlength,%
388 \the\pgfarrowwidth,%
389 \ifpgfarrowswap s\fi%
390 \ifpgfarrowopen o\fi%
391 \ifpgfarrowroundjoin j\fi
392 \ifpgfarrowroundcap c\fi%
393 },
394 setup code = {
395 \pgfarrowssettipend{.5\pgfarrowlength}
396 \pgfarrowssetlineend{-.6\pgfarrowlength}
397 \pgfarrowssetvisualbackend{-.6\pgfarrowlength}
398 \pgfarrowssetbackend{-.6\pgfarrowlength}
399 % hull
400 \pgfarrowshullpoint{.5\pgfarrowlength}{0pt}
401 \pgfarrowshullpoint{0pt}{\pgfarrowwidth}
402 \pgfarrowshullpoint{-.6\pgfarrowlength}{0pt}
403 % Saves: Only the length:
404 \pgfarrowssavethe\pgfarrowlength
405 \pgfarrowssavethe\pgfarrowwidth
406 },
407 drawing code = {
408 \pgfsetdash{}{+0pt}
409 \pgfarrowlinewidth=\pgflinewidth
410 \ifpgfarrowroundjoin\pgfsetroundjoin\else\pgfsetmiterjoin\fi
411 \ifpgfarrowroundcap\pgfsetroundcap\else\pgfsetbuttcap\fi
412 \pgfpathmoveto{\pgfqpoint{-.6\pgfarrowlength}{0pt}}
413 \pgfpathlineto{\pgfqpoint{-.5\pgfarrowlength}{0pt}}
414 \pgfpathlineto{\pgfqpoint{0pt}{\pgfarrowwidth}}
415 \pgfpathlineto{\pgfqpoint{.5\pgfarrowlength}{0pt}}
416 \ifpgfarrowopen
417 \pgfusepathqstroke
418 \else
419 \pgfpathclose
420 \ifdim\pgfarrowlinewidth>0pt\pgfusepathqfillstroke\else\pgfusepathqfill\fi
421 \fi
422 },
423 defaults = {length = 0.3cm, width=0.15cm, open},
424 % cache=false, % breaks everything
425 }
426 % the new "fill without arg" will be in TikZ 3.1.11. Apply it here if we have an
427 % older version
428 \ctikz@@ifpgfafter 2023-01-16{\relax}{%
429 % thanks @muzimuzhi https://github.com/pgf-tikz/pgf/issues/1348#issuecomment-2229075269
430 % undo the fill/.value required key
431 \expandafter\let\csname pgfk@/pgf/arrow keys/fill/.@def\endcsname\@undefined
432 \pgfkeys{/pgf/arrow keys/fill/.code={%
433 \def\pgf@temp{#1}%
434 \ifx\pgf@temp\pgf@nonetext%
435 \pgfarrowsaddtooptions{\pgfarrowopentrue}%
436 \else\ifx\pgf@temp\pgfkeysnovalue@text%
437 \pgfarrowsaddtooptions{\pgfarrowopenfalse}%
438 \else
439 \pgfarrowsaddtooptions{\pgfarrowopenfalse\def\pgf@arrows@fill@color{#1}}%
440 \fi\fi
441 }}%
442 }
443 \tikzset{v/.tip={Jack Tap[swap]}, ^/.tip={Jack Tap},
444 vf/.tip={Jack Tap[swap,fill]}, ^f/.tip={Jack Tap[fill]}}
445 %
446 % select the arrows using available defaults.
447 \def\pgfcirc@arrow@default{default}
448 % choose the arrows to use. Use #2 and #3 if the key is equal to "default"
449 % arguments: type, default start, default end
450 \def\pgfcirc@set@arrows#1#2#3{%
451 \pgfkeysifdefined{\circuitikzbasekey/#1 start arrow}%
452 {\edef\@@start{\ctikzvalof{#1 start arrow}}}%
453 {\edef\@@start{\pgfcirc@arrow@default}}
454 \pgfkeysifdefined{\circuitikzbasekey/#1 end arrow}%
455 {\edef\@@end{\ctikzvalof{#1 end arrow}}}%
456 {\edef\@@end{\pgfcirc@arrow@default}}
457 \ifx\@@start\pgfcirc@arrow@default
458 \pgfsetarrowsstart{#2}%
459 \else
460 \pgfsetarrowsstart{\@@start}%
461 \fi
462 \ifx\@@end\pgfcirc@arrow@default
463 \pgfsetarrowsend{#3}%
464 \else
465 \pgfsetarrowsend{\@@end}%
466 \fi
467 }
468
469 \def\pgf@circ@declare@family@arrows#1{%
470 \ctikzset{#1 start arrow/.initial={default}}
471 \ctikzset{#1 end arrow/.initial={default}}
472 \tikzset{#1 start arrow/.style={\circuitikzbasekey/#1 start arrow={##1}}}
473 \tikzset{#1 end arrow/.style={\circuitikzbasekey/#1 end arrow={##1}}}
474 }
475 %%>>>
476
477 %% Macros to do things depending on the class%<<<1
478
479 \def\pgf@circ@setifdefinedfill#1#2{%
480 % if \ctikzclass is defined and \ctikzclass/fill is defined and is not none:
481 % set the fill color and execute \pgfusepath{#1}, else execute \pgfusepath{#2}
482 % \typeout{SETIFDEF:#1\space#2:}
483 \ifdefined\ctikzclass
484 \pgfkeysifdefined{\circuitikzbasekey/\ctikzclass/fill}%
485 {% yes, it's defined
486 \edef\@@tmp{\ctikzvalof{\ctikzclass/fill}}\edef\@@none{none}%
487 \ifx\@@tmp\@@none % but it's none
488 \pgfusepath{#2}%
489 \else
490 \pgfsetfillcolor{\@@tmp}%
491 \pgfusepath{#1}%
492 \fi
493 }{% the class is defined but the fill key not; use #2
494 \pgfusepath{#2}%
495 }
496 \else
497 \pgfusepath{#2}%
498 \fi
499 }
500
501 %% Macro to fill or draw
502
503 \def\pgf@circ@draworfill{%
504 \ifx\tikz@fillcolor\pgfutil@empty
505 \ifx\ctikz@fillcolor\pgfutil@empty
506 \pgf@circ@setifdefinedfill{draw,fill}{draw}
507 \else
508 \ifx\ctikz@fillcolor\pgf@nonetext
509 \pgf@circ@setifdefinedfill{draw,fill}{draw}
510 \else
511 \pgfsetfillcolor{\ctikz@fillcolor}
512 \pgfusepath{draw, fill}
513 \fi
514 \fi
515 \else
516 \pgfsetfillcolor{\tikz@fillcolor}
517 \pgfusepath{draw, fill}
518 \fi
519 }
520
521 \def\pgf@circ@draworfillandclip{%
522 \ifx\tikz@fillcolor\pgfutil@empty
523 \ifx\ctikz@fillcolor\pgfutil@empty
524 \pgf@circ@setifdefinedfill{draw, clip, fill}{draw, clip}
525 \pgfusepath{draw, clip}
526 \else
527 \ifx\ctikz@fillcolor\pgf@nonetext
528 \pgf@circ@setifdefinedfill{draw, clip, fill}{draw, clip}
529 \pgfusepath{draw, clip}
530 \else
531 \pgfsetfillcolor{\ctikz@fillcolor}
532 \pgfusepath{draw, clip, fill}
533 \fi
534 \fi
535 \else
536 \pgfsetfillcolor{\tikz@fillcolor}
537 \pgfusepath{draw, clip, fill}
538 \fi
539 }
540
541 \def\pgf@circ@maybefill{%
542 % \typeout{MAYBEFILL\tikz@fillcolor}%
543 \ifx\tikz@fillcolor\pgfutil@empty
544 \ifx\ctikz@fillcolor\pgfutil@empty
545 \pgf@circ@setifdefinedfill{fill}{discard}
546 \else
547 \ifx\ctikz@fillcolor\pgf@nonetext
548 \pgf@circ@setifdefinedfill{fill}{discard}
549 \else
550 \pgfsetfillcolor{\ctikz@fillcolor}
551 \pgfusepath{fill}
552 \fi
553 \fi
554 \else
555 \pgfsetfillcolor{\tikz@fillcolor}
556 \pgfusepath{fill}
557 \fi
558 }
559
560 %% Macros for setting linewidth
561 % #1 is the legacy class (bipoles, tripoles) etc
562 % #2 is the reference linewidth
563 \def\pgf@circ@setlinewidth#1#2{%
564 \ifdefined\ctikzclass
565 \pgfkeysifdefined{\circuitikzbasekey/\ctikzclass/thickness}%
566 {% yes, it's defined
567 \edef\@@tmp{\ctikzvalof{\ctikzclass/thickness}}\edef\@@none{none}%
568 \ifx\@@tmp\@@none % but it's none
569 \pgfsetlinewidth{\ctikzvalof{#1/thickness}#2}% passthrough legacy class
570 \else
571 \pgfsetlinewidth{\@@tmp #2}%
572 \fi
573 }{ % key not defined, do the legacy thing
574 \pgfsetlinewidth{\ctikzvalof{#1/thickness}#2}%
575 }% Ok, do nothing
576 \else % no class
577 \pgfsetlinewidth{\ctikzvalof{#1/thickness}#2}%
578 \fi
579 }
580 % use \pgf@circ@setlinewidth{none}{\pgflinewidth} if there is no legacy case
581 \ctikzset{none/thickness/.initial=1.0} % do not touch
582
583 % set thickness relative to current thickness if exists class and key
584 \def\pgf@circ@set@relative@thickness#1{%
585 \ifdefined\ctikzclass
586 \pgfkeysifdefined{\circuitikzbasekey/\ctikzclass/#1}
587 {% yes, it's defined
588 \pgfsetlinewidth{\ctikzvalof{\ctikzclass/#1}\pgflinewidth}%
589 }{}
590 \fi
591 }
592 % set the color for a subset of the shape, following keys #1/color
593 % The key must exist, and check for default (no change)
594 \def\pgf@circ@subset@color#1{%
595 % You *must* be sure that this is called inside a \pgfscope!
596 \edef\@@default{default}
597 \edef\@@tmp{\ctikzvalof{#1}}
598 \ifx\@@tmp\@@default\else
599 \pgfsetstrokecolor{\@@tmp}
600 \fi
601 }
602
603 % set the color and dash pattern for a subset of the shape, following keys #1/color
604 % and #1/dash. The keys must exist, and check for none or default for both
605 \def\pgf@circ@subset@color@dash#1{%
606 % You *must* be sure that this is called inside a \pgfscope!
607 \edef\@@none{none}\edef\@@default{default}
608 \edef\@@tmp{\ctikzvalof{#1/color}}
609 \ifx\@@tmp\@@default\else
610 \pgfsetcolor{\@@tmp}
611 \fi
612 \edef\@@tmp{\ctikzvalof{#1/dash}}
613 \ifx\@@tmp\@@default\else
614 \ifx\@@tmp\@@none
615 \pgfsetdash{}{0pt}% solid line, override dash
616 \else
617 \expandafter\pgfsetdash\expandafter{\@@tmp}{0cm}
618 \fi
619 \fi
620 }
621 % similar o the above, use the fill parameter to set fill or draw
622 % for a subset of the shape
623 \def\pgf@circ@subset@fill@or@draw#1{%
624 % You *must* be sure that this is called inside a \pgfscope!
625 \edef\@@none{none}\edef\@@default{default}
626 \edef\@@tmp{\ctikzvalof{#1/fill}}
627 \ifx\@@tmp\@@none
628 \pgfusepath{draw}
629 \else
630 \ifx\@@tmp\@@default\else
631 \pgfsetfillcolor{\@@tmp}
632 \fi
633 \pgfusepath{draw, fill}
634 \fi
635 }
636 % ...and for the thickness
637 \def\pgf@circ@subset@thickness#1{%
638 % You *must* be sure that this is called inside a \pgfscope!
639 \edef\@@default{default}
640 \edef\@@tmp{\ctikzvalof{#1/thickness}}
641 \ifx\@@tmp\@@default\else
642 \pgfsetlinewidth{\@@tmp\pgflinewidth}%
643 \fi
644 }
645 % set the text color (via \color) if the color is not default or none
646 % needed in some strange case (like bodydiode' dots)
647 \def\pgf@circ@maybe@color#1{%
648 \edef\@@none{none}\edef\@@default{default}%
649 \edef\@@tmp{\ctikzvalof{#1}}%
650 \ifx\@@tmp\@@default\else
651 \ifx\@@tmp\@@none\else
652 \color{\@@tmp}%
653 \fi
654 \fi
655 }
656
657 %%>>>
658
659 %% font changes compatible with plain/LaTeX/ConTeXt%<<<1
660 %% thanks to Henri Menke https://github.com/circuitikz/circuitikz/issues/285#issuecomment-537224605
661
662 \ifpgfutil@format@is@latex
663 \long\def\pgf@circ@font@tiny{\tiny}
664 \long\def\pgf@circ@font@small{\small}
665 \long\def\pgf@circ@font@bold{\textbf}
666 \long\def\pgf@circ@font@boldmath{\boldmath}
667 \long\def\pgf@circ@font@sixbm{\fontsize{6}{7}\selectfont\boldmath}
668 \long\def\pgf@circ@font@tenbm{\fontsize{10}{12}\selectfont\boldmath}
669 \long\def\pgf@circ@font@twelve{\fontsize{12}{14}\selectfont}
670 \else\ifpgfutil@format@is@plain
671 \long\def\pgf@circ@font@tiny{\fiverm}
672 \long\def\pgf@circ@font@small{\sevenrm}
673 \long\def\pgf@circ@font@bold#1{{\bf#1}}
674 \long\def\pgf@circ@font@boldmath{\bf} % to be tested
675 \long\def\pgf@circ@font@sixbm{\sevenrm\bf} %
676 \long\def\pgf@circ@font@tenbm{\tenrm\bf} %
677 \long\def\pgf@circ@font@twelve{\twelverm} %
678 \else\ifpgfutil@format@is@context
679 \long\def\pgf@circ@font@tiny{\tfxx}
680 \long\def\pgf@circ@font@small{\tfx}
681 \long\def\pgf@circ@font@bold{\bold}
682 \long\def\pgf@circ@font@boldmath{\bold} % to be tested
683 \long\def\pgf@circ@font@sixbm{\tfx\bold} %
684 \long\def\pgf@circ@font@tenbm{\normal\bold}%
685 \long\def\pgf@circ@font@twelve{\tfa} %
686 \fi\fi\fi
687 % noop
688 \def\pgfcirc@nop#1{#1}% no operation, just strip {}
689 %
690 %
691 % Thanks to Phelype Oleinik https://tex.stackexchange.com/a/520806/38080
692 %
693 % this is needed to avoid problems with \ConTeXt
694 \ifcsname normalunexpanded\endcsname
695 \let\pgfcircutil@unexpanded\normalunexpanded
696 \else
697 \let\pgfcircutil@unexpanded\unexpanded
698 \fi
699 % minimally expand a pgfkey to check if it's {}/undefined or filled.
700 \def\unexpandedvalueof#1{%
701 \pgfcircutil@unexpanded\expandafter\expandafter
702 \expandafter\pgf@circ@valueof@chk\pgfkeysvalueof{#1}}
703 \def\pgf@circ@valueof@chk#1{%
704 \ifx\relax#1%
705 \expandafter\pgfutil@firstoftwo
706 \else
707 \expandafter\pgfutil@secondoftwo
708 \fi
709 {{}}% #1 is \relax, so consider empty
710 {\expandafter{#1}}% otherwise, leave the key after one more expansion
711 }%
712 %>>>
713
714 %% Generic macro for defining a bipole shape%<<<
715 % #1 - additional anchors
716 % #2 - lower y-size of the bipole (from the center).
717 % #3 - #shape is the name of the shape
718 % #4 - upper y-size of the bipole (from the center)
719 % #5 - width of the bipole
720 % #6 - macros drawing the bipole
721 %
722 \long\def\pgfcircdeclarebipole{%
723 \pgfcircdeclarebipolescaled{default}}
724
725 %% Generic macro for defining a bipole shape
726 % #1 - scale factor
727 % #2 - additional anchors
728 % #3 - lower y-size of the bipole (from the center).
729 % #4 - #shape is the name of the shape
730 % #5 - upper y-size of the bipole (from the center)
731 % #6 - width of the bipole
732 % #7 - macros drawing the bipole
733 %
734 \long\def\pgfcircdeclarebipolescaled#1#2#3#4#5#6#7{
735 % \typeout{Declaring bipole:\space #4,}
736 \pgfdeclareshape{#4shape}{
737 \savedmacro{\ctikzclass}{\edef\ctikzclass{#1}}
738 \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
739 \savedanchor{\northeast}{
740 \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
741 \pgf@y=#5\pgf@circ@scaled@Rlen
742 \pgf@y=.5\pgf@y
743 \pgf@x=#6\pgf@circ@scaled@Rlen
744 \pgf@x=.5\pgf@x
745 }
746 \savedanchor{\northeastborder}{
747 \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
748 \pgf@y=#5\pgf@circ@scaled@Rlen
749 \pgf@y=.5\pgf@y
750 \pgf@y=\ctikzvalof{bipoles/border margin}\pgf@y
751 \pgf@x=#6\pgf@circ@scaled@Rlen
752 \pgf@x=.5\pgf@x
753 \pgf@x=\ctikzvalof{bipoles/border margin}\pgf@x
754 }
755 \savedanchor{\southwestborder}{
756 \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
757 \pgf@y=-#3\pgf@circ@scaled@Rlen
758 \pgf@y=.5\pgf@y
759 \pgf@y=\ctikzvalof{bipoles/border margin}\pgf@y
760 \pgf@x=-#6\pgf@circ@scaled@Rlen
761 \pgf@x=.5\pgf@x
762 \pgf@x=\ctikzvalof{bipoles/border margin}\pgf@x
763 }
764 \savedanchor{\southwest}{
765 \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
766 \pgf@y=-#3\pgf@circ@scaled@Rlen
767 \pgf@y=.5\pgf@y
768 \pgf@x=-#6\pgf@circ@scaled@Rlen
769 \pgf@x=.5\pgf@x
770 }
771 \savedanchor{\centerpoint}{
772 \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
773 \pgf@circ@res@down=-#3\pgf@circ@scaled@Rlen
774 \pgf@circ@res@up=#5\pgf@circ@scaled@Rlen
775 \pgfpointorigin % this is ok, it loads \pgf@x\pgf@y
776 \pgf@y=\pgf@circ@res@up
777 \advance\pgf@y by\pgf@circ@res@down
778 \pgf@y=.5\pgf@y
779 }
780 \anchor{center}{\pgfpointorigin}
781 \anchor{n}{\northeast\pgf@x=0cm }
782 \anchor{north east}{\northeast}
783 \anchor{north west}{\northeast\pgf@x=-\pgf@x}
784 \anchor{ne}{\northeast}
785 \anchor{nw}{\northeast\pgf@x=-\pgf@x}
786 \anchor{e}{\northeast\pgf@y=0cm }
787 \anchor{s}{\southwest\pgf@x=0cm }
788 \anchor{south east}{\southwest\pgf@x=-\pgf@x}
789 \anchor{south west}{\southwest}
790 \anchor{se}{\southwest\pgf@x=-\pgf@x}
791 \anchor{sw}{\southwest}
792 \anchor{w}{\southwest\pgf@y=0cm }
793 \anchor{north}{\northeast\pgf@x=0cm }
794 \anchor{east}{\northeast\pgf@y=0cm }
795 \anchor{south}{\southwest\pgf@x=0cm }
796 \anchor{west}{\southwest\pgf@y=0cm }
797 \anchor{right}{\northeast\pgf@y=0cm }
798 \anchor{above}{\northeast\pgf@x=0cm }
799 \anchor{left}{\southwest\pgf@y=0cm }
800 \anchor{below}{\southwest\pgf@x=0cm }
801 \anchor{a}{\northeast\pgf@y=0cm }
802 \anchor{b}{\southwest\pgf@y=0cm }
803 \savedanchor{\textanchor}{%
804 \pgf@y=\ht\pgfnodeparttextbox
805 \pgf@x=-.5\wd\pgfnodeparttextbox
806 }
807 \anchor{text}{\textanchor}
808 \anchorborder{%
809 \ifpgf@circuit@bipole@inverted
810 \pgf@circ@res@left=-\pgf@x
811 \pgf@circ@res@up=-\pgf@y
812 \else
813 \pgf@circ@res@left=\pgf@x
814 \pgf@circ@res@up=\pgf@y
815 \fi
816 \ifdim\pgf@circ@res@up>0cm
817 \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\northeastborder}
818 \else
819 \southwestborder
820 \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{-\pgf@x}{-\pgf@y}}
821 \fi
822 }
823 #2%
824 \pgf@circ@draw@component{
825 \pgf@circ@setcolor
826 \northeast
827 \pgf@circ@res@up = \pgf@y
828 \pgf@circ@res@zero = 0cm
829 \pgf@circ@res@left = -\pgf@x
830 \pgf@circ@res@right = \pgf@x
831 \southwest
832 \pgf@circ@res@down = \pgf@y
833 \pgf@circ@scaled@Rlen=\scaledRlen
834 \pgfstartlinewidth=\pgflinewidth
835 % we used to reset arced corners here --- now it's in the hooks. I hope.
836 #7%
837 \pgfsetlinewidth{\pgfstartlinewidth}
838 }
839 }
840 }% %>>>
841
842 %% anchor adjustment macros%<<<
843 % Extend the border anchor position by the specified factors on the right-top (north east corner)
844 % and the left-down (southwest border). Argument must be number (possibly decimal) without sign
845 \def\pgfcirc@border@extend@full#1#2#3#4{% right, top, left, down
846 \anchorborder{%
847 \ifpgf@circuit@bipole@inverted
848 \pgf@circ@res@left=-\pgf@x
849 \pgf@circ@res@up=-\pgf@y
850 \else
851 \pgf@circ@res@left=\pgf@x
852 \pgf@circ@res@up=\pgf@y
853 \fi
854 \ifdim\pgf@circ@res@up>0cm
855 \northeastborder
856 \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{#1\pgf@x}{#2\pgf@y}}
857 \else
858 \southwestborder
859 \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{-#3\pgf@x}{-#4\pgf@y}}
860 \fi
861 }
862 }
863 % Just up and down (very common)
864 \def\pgfcirc@border@extend@updown#1#2{\pgfcirc@border@extend@full{1}{#1}{1}{#2}}%
865 % set of symmetrical, geographical anchors when a \northwest saved anchor is available
866 \long\def\pgfcirc@northwest@symmetric@geoanchors{%
867 \anchor{right}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
868 \anchor{east}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
869 \anchor{e}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
870 \anchor{left}{\northwest\pgf@y=0pt}
871 \anchor{west}{\northwest\pgf@y=0pt}
872 \anchor{w}{\northwest\pgf@y=0pt}
873 \anchor{south}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
874 \anchor{s}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
875 \anchor{north}{\northwest\pgf@x=0pt}
876 \anchor{n}{\northwest\pgf@x=0pt}
877 \anchor{south west}{\northwest\pgf@y=-\pgf@y}
878 \anchor{sw}{\northwest\pgf@y=-\pgf@y}
879 \anchor{north east}{\northwest\pgf@x=-\pgf@x}
880 \anchor{ne}{\northwest\pgf@x=-\pgf@x}
881 \anchor{north west}{\northwest}
882 \anchor{nw}{\northwest}
883 \anchor{south east}{\northwest\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
884 \anchor{se}{\northwest\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
885 }
886 % the same, when we have \northeast (I know...)
887 \long\def\pgfcirc@northeast@symmetric@geoanchors{%
888 \anchor{north}{\northeast\pgf@x=0cm\relax}
889 \anchor{n}{\northeast\pgf@x=0cm\relax}
890 \anchor{east}{\northeast\pgf@y=0cm\relax}
891 \anchor{e}{\northeast\pgf@y=0cm\relax}
892 \anchor{right}{\northeast\pgf@y=0cm\relax}
893 \anchor{south}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
894 \anchor{s}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
895 \anchor{west}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
896 \anchor{w}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
897 \anchor{left}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
898 \anchor{north east}{\northeast}
899 \anchor{ne}{\northeast}
900 \anchor{north west}{\northeast\pgf@x=-\pgf@x}
901 \anchor{nw}{\northeast\pgf@x=-\pgf@x}
902 \anchor{south east}{\northeast\pgf@y=-\pgf@y}
903 \anchor{se}{\northeast\pgf@y=-\pgf@y}
904 \anchor{south west}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
905 \anchor{sw}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
906 }
907 %>>>
908
909 %% text position in some component.%<<<1
910 % (added with ieeestd logic ports. Maybe to be extended to other components,
911 % like amplifiers)
912 %
913 \newif\ifpgf@circ@center@text\pgf@circ@center@texttrue
914 % when "center" is false, in the case of transistors, up or down?
915 \newif\ifpgf@circ@up@text\pgf@circ@up@texttrue
916 \tikzset{component text/.is choice}%
917 \tikzset{component text/center/.code={\pgf@circ@center@texttrue}}%
918 \tikzset{component text/left/.code={\pgf@circ@center@textfalse}}%
919 \tikzset{component text/up/.code={\pgf@circ@center@textfalse\pgf@circ@up@texttrue}}%
920 \tikzset{component text/down/.code={\pgf@circ@center@textfalse\pgf@circ@up@textfalse}}%
921 \ctikzset{component text/.is choice}%
922 \ctikzset{component text/center/.code={\pgf@circ@center@texttrue}}%
923 \ctikzset{component text/left/.code={\pgf@circ@center@textfalse}}%
924 \ctikzset{component text/up/.code={\pgf@circ@center@textfalse\pgf@circ@up@texttrue}}%
925 \ctikzset{component text/down/.code={\pgf@circ@center@textfalse\pgf@circ@up@textfalse}}%
926 \ctikzset{left text distance/.initial=0.3em}%
927 % used by blocks (twoportsplit for now)
928 \ctikzset{border text distance/.initial=2pt}
929 \ctikzset{component text/border/.code={\pgf@circ@center@textfalse}}%
930 \tikzset{border text distance/.code={\ctikzset{border text distance=#1}}}
931 \tikzset{component text/border/.code={\pgf@circ@center@textfalse}}%
932 %>>>
933
934 %% voltage direction options%<<<1
935
936 \newif\ifpgf@circ@oldvoltagedirection % default false
937 \newif\ifpgf@circ@explicitvdir
938 \newif\ifpgf@circ@fixbatteries
939
940 \ctikzset{voltage dir/.is choice}
941 \ctikzset{voltage dir/old/.code={\pgf@circ@oldvoltagedirectiontrue\pgf@circ@fixbatteriesfalse}}
942 \ctikzset{voltage dir/noold/.code={\pgf@circ@oldvoltagedirectionfalse\pgf@circ@fixbatteriesfalse}}
943 \ctikzset{voltage dir/RP/.code={\pgf@circ@oldvoltagedirectiontrue\pgf@circ@fixbatteriestrue}}
944 \ctikzset{voltage dir/EF/.code={\pgf@circ@oldvoltagedirectionfalse\pgf@circ@fixbatteriestrue}}
945 \tikzset{voltage dir/.style={circuitikz/voltage dir=#1}}%
946 %>>>
947
948 %% bipole definitions for path component and text decorations%%<<<1
949 %
950 % Option "t=*" for nodes
951 \pgfkeys{/tikz/t/.add code={}{\ctikzset{text=#1}}}
952 \pgfkeys{/tikz/t1/.add code={}{\ctikzset{text in=#1}}}
953 \pgfkeys{/tikz/t2/.add code={}{\ctikzset{text out=#1}}}
954 %
955 \ctikzset{bipole/.is family}
956 \ctikzset{bipole/kind/.initial=}
957 \ctikzset{bipole/name/.initial=}
958 \newif\ifpgf@circuit@bipole@isvoltage
959 \ctikzset{bipole/is voltage/.is if=pgf@circuit@bipole@isvoltage}
960 \newif\ifpgf@circuit@bipole@override@source@vif
961 \ctikzset{bipole/override source vif/.is if=pgf@circuit@bipole@override@source@vif}
962 \newif\ifpgf@circuit@bipole@voltageoutsideofsymbol
963 \ctikzset{bipole/is voltageoutsideofsymbol/.is if=pgf@circuit@bipole@voltageoutsideofsymbol}
964 \newif\ifpgf@circuit@bipole@strokedsymbol
965 \ctikzset{bipole/is strokedsymbol/.is if=pgf@circuit@bipole@strokedsymbol}
966 \newif\ifpgf@circuit@bipole@iscurrent
967 \ctikzset{bipole/is current/.is if=pgf@circuit@bipole@iscurrent}
968
969 \ctikzset{bipole/voltage/.is family}
970 \newif\ifpgf@circuit@bipole@voltage@backward
971 \ctikzset{bipole/voltage/direction/.is choice}
972 \ctikzset{bipole/voltage/direction/forward/.code={\pgf@circuit@bipole@voltage@backwardfalse}}
973 \ctikzset{bipole/voltage/direction/backward/.code={\pgf@circuit@bipole@voltage@backwardtrue}}
974 \newif\ifpgf@circuit@bipole@voltage@below
975 \ctikzset{bipole/voltage/position/.is choice}
976 \ctikzset{bipole/voltage/position/above/.code={\pgf@circuit@bipole@voltage@belowfalse}}
977 \ctikzset{bipole/voltage/position/below/.code={\pgf@circuit@bipole@voltage@belowtrue}}
978
979 \ctikzset{bipole/voltage/label/unit/.initial=}
980 \ctikzset{bipole/voltage/label/name/.initial=}
981
982 \ctikzset{bipole/current/.is family}
983 \newif\ifpgf@circuit@bipole@current@backward
984 \ctikzset{bipole/current/direction/.is choice}
985 \ctikzset{bipole/current/direction/forward/.code={\pgf@circuit@bipole@current@backwardfalse}}
986 \ctikzset{bipole/current/direction/backward/.code={\pgf@circuit@bipole@current@backwardtrue}}
987 \newif\ifpgf@circuit@bipole@current@before
988 \ctikzset{bipole/current/x position/.is choice}
989 \ctikzset{bipole/current/x position/after/.code={\pgf@circuit@bipole@current@beforefalse}}
990 \ctikzset{bipole/current/x position/before/.code={\pgf@circuit@bipole@current@beforetrue}}
991 \newif\ifpgf@circuit@bipole@current@below
992 \ctikzset{bipole/current/y position/.is choice}
993 \ctikzset{bipole/current/y position/above/.code={\pgf@circuit@bipole@current@belowfalse}}
994 \ctikzset{bipole/current/y position/below/.code={\pgf@circuit@bipole@current@belowtrue}}
995 \ctikzset{bipole/current/label/unit/.initial=}
996 \ctikzset{bipole/current/label/name/.initial=}
997
998 \ctikzset{bipole/flow/.is family}
999 \newif\ifpgf@circuit@bipole@flow@backward
1000 \ctikzset{bipole/flow/direction/.is choice}
1001 \ctikzset{bipole/flow/direction/forward/.code={\pgf@circuit@bipole@flow@backwardfalse}}
1002 \ctikzset{bipole/flow/direction/backward/.code={\pgf@circuit@bipole@flow@backwardtrue}}
1003 \newif\ifpgf@circuit@bipole@flow@before
1004 \ctikzset{bipole/flow/x position/.is choice}
1005 \ctikzset{bipole/flow/x position/after/.code={\pgf@circuit@bipole@flow@beforefalse}}
1006 \ctikzset{bipole/flow/x position/before/.code={\pgf@circuit@bipole@flow@beforetrue}}
1007 \newif\ifpgf@circuit@bipole@flow@below
1008 \ctikzset{bipole/flow/y position/.is choice}
1009 \ctikzset{bipole/flow/y position/above/.code={\pgf@circuit@bipole@flow@belowfalse}}
1010 \ctikzset{bipole/flow/y position/below/.code={\pgf@circuit@bipole@flow@belowtrue}}
1011 \ctikzset{bipole/flow/label/unit/.initial=}
1012 \ctikzset{bipole/flow/label/name/.initial=}
1013 \ctikzset{flow/distance/.initial = .5}
1014 \ctikzset{flow/offset/.initial = .2}%distance between flow-arrow and conductor
1015
1016 \ctikzset{bipole/label/.is family}
1017 \ctikzset{bipole/label/position/.initial=90}
1018 \ctikzset{bipole/label/unit/.initial=}
1019 \ctikzset{bipole/label/name/.initial=}
1020 \ctikzset{bipole/annotation/.is family}
1021 \ctikzset{bipole/annotation/position/.initial=-90}
1022 \ctikzset{bipole/annotation/unit/.initial=}
1023 \ctikzset{bipole/annotation/name/.initial=}
1024
1025
1026 \ctikzset{label/align/.is choice}
1027 \ctikzset{label/align/straight/.code={\ctikzsetvalof{label/align}{straight}}}
1028 \ctikzset{label/align/rotate/.code={\ctikzsetvalof{label/align}{rotate}}}
1029 \ctikzset{label/align/smart/.code={\ctikzsetvalof{label/align}{smart}}}
1030 %%>>>
1031
1032 %% traditional styles %<<<1
1033 %
1034 \ctikzset{thickness/.initial=2}
1035 \ctikzset{bipoles/border margin/.initial=1.1}
1036 \ctikzset{bipoles/thickness/.initial=2}
1037 \ctikzset{tripoles/thickness/.initial=2}
1038 \ctikzset{quadpoles/thickness/.initial=2}
1039 \ctikzset{nodes width/.initial=.04}
1040 %%>>>
1041
1042 %% Styles definitions and macros%<<<1
1043
1044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1045 %% main style definitions
1046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1047
1048 % load a style file: search ctikzstyle-NAME.tex in path
1049 \def\ctikzloadstyle#1{%
1050 \pgfutil@InputIfFileExists{ctikzstyle-#1}{}{%
1051 \tikzerror{I did not find the circuitikz style #1}}%
1052 }
1053
1054 % load and enact a style
1055 \def\ctikzsetstyle#1{%
1056 \ctikzloadstyle{#1}%
1057 \tikzset{#1 circuit style}%
1058 }
1059
1060 % global style parameters
1061 \ctikzset{default/scale/.initial=1.0} % do not touch
1062 \ctikzset{default/fill/.initial=none} % do not touch
1063 \ctikzset{default/thickness/.initial=none} % do not touch
1064 % default is use as the generic default style for bipoles
1065
1066 % mostly bipoles:
1067
1068 \ctikzset{resistors/scale/.initial=1.0}
1069 \ctikzset{resistors/fill/.initial=none}
1070 \ctikzset{resistors/thickness/.initial=none}
1071 \ctikzset{resistors/modifier thickness/.initial=1}% relative to main thickness
1072
1073 \ctikzset{capacitors/scale/.initial=1.0}
1074 \ctikzset{capacitors/fill/.initial=none}
1075 \ctikzset{capacitors/thickness/.initial=none}
1076 \ctikzset{capacitors/modifier thickness/.initial=1}
1077
1078 \ctikzset{inductors/scale/.initial=1.0}
1079 \ctikzset{inductors/fill/.initial=none}
1080 \ctikzset{inductors/thickness/.initial=none}
1081 \ctikzset{inductors/modifier thickness/.initial=1}
1082
1083 \ctikzset{diodes/scale/.initial=1.0}
1084 \ctikzset{diodes/fill/.initial=none}
1085 \ctikzset{diodes/thickness/.initial=none}
1086 % we define opto arrows style here because they are used also
1087 % in transistors
1088 \ctikzset{opto arrows/.is family}
1089 \ctikzset{opto arrows/relative thickness/.initial=1}
1090 \ctikzset{opto arrows/color/.initial=default}
1091 \ctikzset{opto arrows/dash/.initial=default}
1092 \def\pgf@circ@set@optoarrow@style{%
1093 % You *must* be sure that this is called inside a \pgfscope!
1094 \pgfsetlinewidth{\ctikzvalof{opto arrows/relative thickness}\pgflinewidth}
1095 \pgf@circ@subset@color@dash{opto arrows}
1096 \pgfcirc@set@arrows{opto}{}{latexslim}
1097 }
1098
1099 \ctikzset{batteries/scale/.initial=1.0}
1100 \ctikzset{batteries/fill/.initial=none}
1101 \ctikzset{batteries/thickness/.initial=none}
1102
1103 \ctikzset{sources/scale/.initial=1.0}
1104 \ctikzset{sources/fill/.initial=none}
1105 \ctikzset{sources/thickness/.initial=none}
1106
1107 \ctikzset{csources/scale/.initial=1.0}
1108 \ctikzset{csources/fill/.initial=none}
1109 \ctikzset{csources/thickness/.initial=none}
1110
1111 \ctikzset{instruments/scale/.initial=1.0}
1112 \ctikzset{instruments/fill/.initial=none}
1113 \ctikzset{instruments/thickness/.initial=none}
1114
1115 \ctikzset{mechanicals/scale/.initial=1.0}
1116 \ctikzset{mechanicals/fill/.initial=none}
1117 \ctikzset{mechanicals/thickness/.initial=none}
1118
1119 \ctikzset{misc/scale/.initial=1.0}
1120 \ctikzset{misc/fill/.initial=none}
1121 \ctikzset{misc/thickness/.initial=none}
1122
1123 \ctikzset{blocks/scale/.initial=1.0}
1124 \ctikzset{blocks/fill/.initial=none}
1125 \ctikzset{blocks/thickness/.initial=none}
1126
1127 % mostly nodes
1128
1129 \ctikzset{grounds/scale/.initial=1.0}
1130 \ctikzset{grounds/fill/.initial=none}
1131 \ctikzset{grounds/thickness/.initial=none}
1132
1133 \ctikzset{power supplies/scale/.initial=1.0}
1134 \ctikzset{power supplies/fill/.initial=none}
1135 \ctikzset{power supplies/thickness/.initial=none}
1136
1137 \ctikzset{transistors/scale/.initial=1.0}
1138 \ctikzset{transistors/fill/.initial=none}
1139 \ctikzset{transistors/thickness/.initial=none}
1140 \ctikzset{transistors/modifier thickness/.initial=1}% relative to main thickness
1141
1142 \ctikzset{tubes/scale/.initial=1.0}
1143 \ctikzset{tubes/fill/.initial=none}
1144 \ctikzset{tubes/thickness/.initial=none}
1145
1146 \ctikzset{RF/scale/.initial=1.0}
1147 \ctikzset{RF/fill/.initial=none}
1148 \ctikzset{RF/thickness/.initial=none}
1149
1150 \ctikzset{electromechanicals/scale/.initial=1.0}
1151 \ctikzset{electromechanicals/fill/.initial=none}
1152 \ctikzset{electromechanicals/thickness/.initial=none}
1153
1154 % transformers go with inductors
1155 \ctikzset{amplifiers/scale/.initial=1.0}
1156 \ctikzset{amplifiers/fill/.initial=none}
1157 \ctikzset{amplifiers/thickness/.initial=none}
1158
1159 \ctikzset{switches/scale/.initial=1.0}
1160 \ctikzset{switches/fill/.initial=none}
1161 \ctikzset{switches/thickness/.initial=none}
1162
1163 \ctikzset{logic ports/scale/.initial=1.0}
1164 \ctikzset{logic ports/fill/.initial=none}
1165 \ctikzset{logic ports/thickness/.initial=none}
1166
1167 \ctikzset{flipflops/scale/.initial=1.0}
1168 \ctikzset{flipflops/fill/.initial=none}
1169 \ctikzset{flipflops/thickness/.initial=none}
1170
1171 \ctikzset{muxdemuxes/scale/.initial=1.0}
1172 \ctikzset{muxdemuxes/fill/.initial=none}
1173 \ctikzset{muxdemuxes/thickness/.initial=none}
1174
1175 \ctikzset{chips/scale/.initial=1.0}
1176 \ctikzset{chips/fill/.initial=none}
1177 \ctikzset{chips/thickness/.initial=none}
1178
1179 \ctikzset{displays/scale/.initial=1.0}
1180 \ctikzset{displays/fill/.initial=none}
1181 \ctikzset{displays/thickness/.initial=none}
1182 %
1183 % general styles
1184 %
1185 \tikzset{european/.style = {european currents, european voltages, european resistors, european inductors, european ports, european gas filled surge arrester set}}
1186 \tikzset{american/.style = {american currents, american voltages, american resistors, american inductors, american ports, american gas filled surge arrester set}}
1187 \tikzset{cute/.style = {european currents, european voltages, american resistors, cute inductors, american ports}}
1188 %%>>>
1189
1190 %% voltage and current options%<<<1
1191 %
1192 \ctikzset{current arrow scale/.initial=16}
1193 \ctikzset{current/distance/.initial = .5}
1194
1195 \newif\ifpgf@circuit@europeancurrent
1196 \newif\ifpgf@circuit@europeanvoltage
1197 \newif\ifpgf@circuit@bipole@voltage@straight
1198 \newif\ifpgf@circuit@bipole@voltage@raised
1199
1200 \ctikzset{voltage/.is choice}
1201 %
1202 % straight is expected to be a subset of european, so disable it in american style
1203 %
1204 \ctikzset{voltage/american/.code = {%
1205 \pgf@circuit@europeanvoltagefalse
1206 \pgf@circuit@bipole@voltage@straightfalse
1207 \pgf@circuit@bipole@voltage@raisedfalse
1208 }}
1209 \ctikzset{voltage/raised/.code = {%
1210 \pgf@circuit@europeanvoltagefalse
1211 \pgf@circuit@bipole@voltage@straightfalse
1212 \pgf@circuit@bipole@voltage@raisedtrue
1213 }}
1214 \ctikzset{voltage/european/.code = {%
1215 \pgf@circuit@europeanvoltagetrue
1216 \pgf@circuit@bipole@voltage@straightfalse
1217 \pgf@circuit@bipole@voltage@raisedfalse
1218 }}
1219 \ctikzset{voltage/straight/.code = {%
1220 \pgf@circuit@europeanvoltagetrue
1221 \pgf@circuit@bipole@voltage@straighttrue
1222 \pgf@circuit@bipole@voltage@raisedfalse
1223 }}
1224 \ctikzset{voltage/curved/.code = {%
1225 \pgf@circuit@europeanvoltagetrue
1226 \pgf@circuit@bipole@voltage@straightfalse
1227 \pgf@circuit@bipole@voltage@raisedfalse
1228 }}
1229 % are these used?
1230 \ctikzset{current/.is choice}
1231 \ctikzset{current/american/.code = \pgf@circuit@europeancurrentfalse}
1232 \ctikzset{current/european/.code = \pgf@circuit@europeancurrenttrue}
1233
1234 % this is left for backward compatibility...
1235 \ctikzset{straight/.is choice}
1236 \ctikzset{straight/true/.code = {\pgf@circuit@bipole@voltage@straighttrue}}
1237 \ctikzset{straight/false/.code = {\pgf@circuit@bipole@voltage@straightfalse}}
1238 \ctikzset{bipole/straight/.is if=pgf@circuit@bipole@voltage@straight}
1239 %
1240 % voltage is used also to set parameters, apart for the /.is choice
1241 % above. I hope it is ok --- would be a mess otherwise
1242 %
1243 \ctikzset{voltage/shift/.initial=0.0} % shift form the cable of voltage symbols
1244 \ctikzset{voltage shift/.style={\circuitikzbasekey/voltage/shift=#1}}
1245 \tikzset{voltage shift/.style={\circuitikzbasekey/voltage/shift=#1}}
1246 %
1247 % keys for exporting voltage, current, flow anchors
1248 %
1249 \newif\ifpgfcirc@has@v\pgfcirc@has@vfalse
1250 \newif\ifpgfcirc@has@f\pgfcirc@has@ffalse
1251 \newif\ifpgfcirc@has@i\pgfcirc@has@ifalse
1252 \def\ctikzgetanchor#1#2{\csname pgfcirc@#1-#2-anchor\endcsname}
1253 \def\ctikzgetdirection#1{\csname pgfcirc@#1-direction\endcsname}
1254 %
1255 % shaping the +/- sign, see pgfcircvoltage.tex
1256 \ctikzset{voltage/american font/.initial={}}
1257 \ctikzset{voltage/american plus/.initial={$+$}}
1258 % In the mayority of fonts, the size of - is smaller than +, so we have
1259 % unaligned signs when positioned independently.
1260 % See https://github.com/circuitikz/circuitikz/issues/721
1261 \ctikzset{voltage/american minus/.initial={$\vphantom{+}-$}}
1262 % here we start the voltage adjustments for special components.
1263 % default values:
1264 %
1265 % this is the distance of the "point" marking the voltage along the line
1266 % 0.0 is on the external nodes of the to path
1267 % 1.0 is cramped on the object
1268 % this can be overriden component by component
1269 \ctikzset{voltage/distance from node/.initial=.5}% pos, 0->1
1270 %
1271 % this is the distance from the line (perpendicular to) where the voltage is drawn.
1272 % It is global, and not adjustable by component (use the "label distance" or locally
1273 % if you need it)
1274 \ctikzset{voltage/distance from line/.initial=.08}% in \pgf@circ@scaled@Rlen units
1275 %
1276 % bend paramenters for european arc. You can override them component-based
1277 \ctikzset{voltage/bump b/.initial=1.5}
1278 %
1279 % generator voltages symbols or arrows (always straight) are put along the
1280 % 60 ... 120 angles of the symbol (don't ask why). The distance here is on the
1281 % center..angle line. It's called bump a because I don't know...
1282 %
1283 \ctikzset{voltage/bump a/.initial=1.2}
1284 %
1285 % these are the label distances FROM the drawings.
1286 % You can override them component by component.
1287 \ctikzset{voltage/european label distance/.initial=1.4}
1288 \ctikzset{voltage/straight label distance/.initial=1.4}
1289 \ctikzset{voltage/american label distance/.initial=1.4}
1290 % american open voltage adjusting
1291 %
1292 \newif\ifpgf@adjust@open@voltage\pgf@adjust@open@voltagetrue
1293 \ctikzset{open voltage position/.is choice}
1294 \ctikzset{open voltage position/center/.code={\pgf@adjust@open@voltagetrue}}
1295 \ctikzset{open voltage position/legacy/.code={\pgf@adjust@open@voltagefalse}}
1296 % bad names, kept for compatibility, don't use
1297 \ctikzset{american open voltage/.is choice}
1298 \ctikzset{american open voltage/center/.code={\pgf@adjust@open@voltagetrue}}
1299 \ctikzset{american open voltage/legacy/.code={\pgf@adjust@open@voltagefalse}}
1300 %
1301 % voltage and current styles
1302 %
1303 \tikzset{american currents/.style = {\circuitikzbasekey/current = american}}
1304 \tikzset{european currents/.style = {\circuitikzbasekey/current = european}}
1305 \tikzset{american voltages/.style = {\circuitikzbasekey/voltage = american}}
1306 \tikzset{european voltages/.style = {\circuitikzbasekey/voltage = european}}
1307 \tikzset{straight voltages/.style = {\circuitikzbasekey/voltage = straight}}
1308 \tikzset{raised voltages/.style = {\circuitikzbasekey/voltage = raised}}
1309 %%>>>
1310
1311 \endinput
1312 % vim: set fdm=marker fmr=%<<<,%>>>: