| 1 |
% circu.tex |
| 2 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 |
% Petr Olsak <[email protected]> March 2025 |
| 4 |
|
| 5 |
% This macro file enables features from LaTeX package circuitikz.sty |
| 6 |
% in plain TeX or OpTeX. |
| 7 |
% Usage: |
| 8 |
|
| 9 |
% \input circu % or \load[circu] in OpTeX |
| 10 |
% \circusetup {comma separated LaTeX options} |
| 11 |
% |
| 12 |
% \circu |
| 13 |
% ... TikZ and circuitikz drawing commands ... |
| 14 |
% \endcircu |
| 15 |
|
| 16 |
% See the LaTeX documentation of circuitikz package for more information. |
| 17 |
% See also the end of this file for more examples. |
| 18 |
|
| 19 |
\ifx\circu\undefined \else \endinput \fi |
| 20 |
\ifx\useoptex\undefined |
| 21 |
\input tikz |
| 22 |
\expandafter\def\expandafter\newdimen\expandafter{\newdimen} |
| 23 |
\def\circuwarning#1{\immediate\write16{circu WARNING: #1}} |
| 24 |
\else |
| 25 |
\load[tikz] |
| 26 |
\def\circuwarning#1{\opwarning{circu: #1}} |
| 27 |
\def\sevenrm{\setfontsize{mag.7}\rm} \def\fiverm{\setfontsize{mag.5}\rm} |
| 28 |
\fi |
| 29 |
|
| 30 |
\usetikzlibrary{calc} |
| 31 |
\usetikzlibrary{arrows.meta, bending} |
| 32 |
\usetikzlibrary{fpu} |
| 33 |
|
| 34 |
\edef\circuleave{\catcode`\string @=\the\catcode`\@ } |
| 35 |
\catcode`\@=11 |
| 36 |
|
| 37 |
\input pgfcirc.defines.tex |
| 38 |
\input pgfcircutils.tex |
| 39 |
\input pgfcircpath.tex |
| 40 |
\input pgfcircshapes.tex |
| 41 |
\input pgfcircmonopoles.tex |
| 42 |
\input pgfcircbipoles.tex |
| 43 |
\input pgfcirctripoles.tex |
| 44 |
\input pgfcircquadpoles.tex |
| 45 |
\input pgfcircmultipoles.tex |
| 46 |
\input pgfcirclabel.tex |
| 47 |
\input pgfcircvoltage.tex |
| 48 |
\input pgfcirccurrent.tex |
| 49 |
\input pgfcircflow.tex |
| 50 |
|
| 51 |
\def\circusetup#1{\circusetupA#1,\relax,\end} |
| 52 |
\def\circusetupA#1#2,{\ifx\relax#1\relax \expandafter\circusetupE |
| 53 |
\else \circuX{#1#2}\expandafter\circusetupA\fi |
| 54 |
} |
| 55 |
\def\circusetupE#1\end{} |
| 56 |
|
| 57 |
\def\circuoption#1#2{\expandafter\gdef \csname circuopt:#1\endcsname{#2}} |
| 58 |
\def\circuX#1{\ifcsname circuopt:#1\endcsname \csname circuopt:#1\endcsname |
| 59 |
\else \circuwarning{Unknown option: "#1"}\fi} |
| 60 |
|
| 61 |
\circuoption {europeanvoltage} {\ctikzset{voltage=european}} |
| 62 |
\circuoption {straightvoltages} {\ctikzset{voltage=straight}} |
| 63 |
\circuoption {americanvoltage} {\ctikzset{voltage=american}} |
| 64 |
\circuoption {europeanvoltages} {\ctikzset{voltage=european}} |
| 65 |
\circuoption {americanvoltages} {\ctikzset{voltage=american}} |
| 66 |
\circuoption {oldvoltagedirection} |
| 67 |
{\pgf@circ@oldvoltagedirectiontrue |
| 68 |
\pgf@circ@explicitvdirtrue |
| 69 |
\pgf@circ@fixbatteriesfalse} |
| 70 |
\circuoption {nooldvoltagedirection} |
| 71 |
{\pgf@circ@oldvoltagedirectionfalse |
| 72 |
\pgf@circ@explicitvdirtrue |
| 73 |
\pgf@circ@fixbatteriesfalse} |
| 74 |
\circuoption {RPvoltages} |
| 75 |
{\pgf@circ@oldvoltagedirectiontrue |
| 76 |
\pgf@circ@explicitvdirtrue |
| 77 |
\pgf@circ@fixbatteriestrue} |
| 78 |
\circuoption {EFvoltages} |
| 79 |
{\pgf@circ@oldvoltagedirectionfalse |
| 80 |
\pgf@circ@explicitvdirtrue |
| 81 |
\pgf@circ@fixbatteriestrue} |
| 82 |
\circuoption {europeancurrent} {\ctikzset{current=european}} |
| 83 |
\circuoption {americancurrent} {\ctikzset{current=american}} |
| 84 |
\circuoption {europeancurrents} {\ctikzset{current=european}} |
| 85 |
\circuoption {americancurrents} {\ctikzset{current=american}} |
| 86 |
\circuoption {americanresistor} {\ctikzset{resistor=american}} |
| 87 |
\circuoption {europeanresistor} {\ctikzset{resistor=european}} |
| 88 |
\circuoption {americanresistors} {\ctikzset{resistor=american}} |
| 89 |
\circuoption {europeanresistors} {\ctikzset{resistor=european}} |
| 90 |
\circuoption {americaninductor} {\ctikzset{inductor=american}} |
| 91 |
\circuoption {europeaninductor} {\ctikzset{inductor=european}} |
| 92 |
\circuoption {cuteinductor} {\ctikzset{inductor=cute}} |
| 93 |
\circuoption {americaninductors} {\ctikzset{inductor=american}} |
| 94 |
\circuoption {europeaninductors} {\ctikzset{inductor=european}} |
| 95 |
\circuoption {cuteinductors} {\ctikzset{inductor=cute}} |
| 96 |
\circuoption {americanport} {\ctikzset{logic ports=american}} |
| 97 |
\circuoption {europeanport} {\ctikzset{logic ports=european}} |
| 98 |
\circuoption {americanports} {\ctikzset{logic ports=american}} |
| 99 |
\circuoption {europeanports} {\ctikzset{logic ports=european}} |
| 100 |
\circuoption {americangfsurgearrester} |
| 101 |
{\ctikzset{gas filled surge arrester choice=american}} |
| 102 |
\circuoption {europeangfsurgearrester} |
| 103 |
{\ctikzset{gas filled surge arrester choice=european}} |
| 104 |
\circuoption {fulldiodes} {\ctikzset{diode=full}} |
| 105 |
\circuoption {emptydiodes} {\ctikzset{diode=empty}} |
| 106 |
\circuoption {strokediodes} {\ctikzset{diode=stroke}} |
| 107 |
\circuoption {fulldiode} {\ctikzset{diode=full}} |
| 108 |
\circuoption {emptydiode} {\ctikzset{diode=empty}} |
| 109 |
\circuoption {strokediode} {\ctikzset{diode=stroke}} |
| 110 |
\circuoption {arrowmos} {\pgf@circuit@mos@arrowstrue} |
| 111 |
\circuoption {noarrowmos} {\pgf@circuit@mos@arrowsfalse} |
| 112 |
\circuoption {fetbodydiode} {\pgf@circuit@fet@bodydiodetrue} |
| 113 |
\circuoption {nofetbodydiode} {\pgf@circuit@fet@bodydiodefalse} |
| 114 |
\circuoption {fetsolderdot} {\pgf@circuit@fet@solderdottrue} |
| 115 |
\circuoption {nofetsolderdot} {\pgf@circuit@fet@solderdotfalse} |
| 116 |
\circuoption {emptypmoscircle} {\pgf@circuit@pmos@emptycircletrue} |
| 117 |
\circuoption {lazymos} |
| 118 |
{\ctikzset{tripoles/nmos/width=.5} |
| 119 |
\ctikzset{tripoles/nmos/gate height=.35} |
| 120 |
\ctikzset{tripoles/nmos/base height=.35} |
| 121 |
\ctikzset{tripoles/nmos/height/.initial=1.2} |
| 122 |
\ctikzset{tripoles/nmos/base width=.5} |
| 123 |
\ctikzset{tripoles/nmos/gate width=.65} |
| 124 |
\ctikzset{tripoles/pmos/width=.5} |
| 125 |
\ctikzset{tripoles/pmos/gate height=.35} |
| 126 |
\ctikzset{tripoles/pmos/base height=.35} |
| 127 |
\ctikzset{tripoles/pmos/height/.initial=1.2} |
| 128 |
\ctikzset{tripoles/pmos/base width=.5} |
| 129 |
\ctikzset{tripoles/pmos/gate width=.65} |
| 130 |
\pgf@circuit@pmos@emptycircletrue} |
| 131 |
\circuoption {legacytransistorstext} {\pgf@circuit@transisors@fixlabelsfalse} |
| 132 |
\circuoption {nolegacytransistorstext} {\pgf@circuit@transisors@fixlabelstrue} |
| 133 |
\circuoption {centertransistorstext} {\pgf@circuit@transisors@fixlabelstrue} |
| 134 |
\circuoption {straightlabels} {\ctikzset{label/align = straight}} |
| 135 |
\circuoption {rotatelabels} {\ctikzset{label/align = rotate}} |
| 136 |
\circuoption {smartlabels} {\ctikzset{label/align = smart}} |
| 137 |
\circuoption {betterproportions} |
| 138 |
{\ctikzset{monopoles/ground/width/.initial=.15} |
| 139 |
\ctikzset{bipoles/resistor/height/.initial=.23} |
| 140 |
\ctikzset{bipoles/resistor/width/.initial=.6} |
| 141 |
\ctikzset{bipoles/capacitor/height/.initial=.4} |
| 142 |
\ctikzset{bipoles/capacitor/width/.initial=.1} |
| 143 |
\ctikzset{bipoles/potentiometer/height/.initial=.6} |
| 144 |
\ctikzset{bipoles/potentiometer/height 2/.initial=.23} |
| 145 |
\ctikzset{bipoles/potentiometer/width/.initial=.6} |
| 146 |
\ctikzset{bipoles/photoresistor/height/.initial=.6} |
| 147 |
\ctikzset{bipoles/photoresistor/height 2/.initial=.23} |
| 148 |
\ctikzset{bipoles/photoresistor/width/.initial=.6} |
| 149 |
\ctikzset{bipoles/thermistor/main/.initial=.7} |
| 150 |
\ctikzset{bipoles/thermistor/height/.initial=.328}%.23/.7 |
| 151 |
\ctikzset{bipoles/thermistor/width/.initial=.6} |
| 152 |
\ctikzset{bipoles/thermistorntc/width/.initial=.6} |
| 153 |
\ctikzset{bipoles/thermistorntc/main/.initial=.7} |
| 154 |
\ctikzset{bipoles/thermistorntc/height/.initial=.328}%.23/.7 |
| 155 |
\ctikzset{bipoles/thermistorntc/height 2/.initial=.75}%.23/.7 |
| 156 |
\ctikzset{bipoles/thermistorptc/width/.initial=.6} |
| 157 |
\ctikzset{bipoles/thermistorptc/main/.initial=.7} |
| 158 |
\ctikzset{bipoles/thermistorptc/height/.initial=.328}%.23/.7 |
| 159 |
\ctikzset{bipoles/varistor/main/.initial=.7} |
| 160 |
\ctikzset{bipoles/varistor/height/.initial=.328}%.23/.7 |
| 161 |
\ctikzset{bipoles/varistor/width/.initial=.6} |
| 162 |
\ctikzset{bipoles/vresistor/height/.initial=.45} |
| 163 |
\ctikzset{bipoles/vresistor/width/.initial=.6} |
| 164 |
\ctikzset{bipoles/generic/height/.initial=.23} |
| 165 |
\ctikzset{bipoles/generic/width/.initial=.6} |
| 166 |
\ctikzset{bipoles/generic potentiometer/height/.initial=.6} |
| 167 |
\ctikzset{bipoles/generic potentiometer/height 2/.initial=.23} |
| 168 |
\ctikzset{bipoles/generic potentiometer/width/.initial=.6} |
| 169 |
\ctikzset{bipoles/ageneric/height/.initial=.23} |
| 170 |
\ctikzset{bipoles/ageneric/width/.initial=.6} |
| 171 |
\ctikzset{bipoles/memristor/height/.initial=.23} |
| 172 |
\ctikzset{bipoles/memristor/wave height/.initial=.375} |
| 173 |
\ctikzset{bipoles/memristor/width/.initial=.60} |
| 174 |
\ctikzset{bipoles/tgeneric/height/.initial=.525} |
| 175 |
\ctikzset{bipoles/tgeneric/width/.initial=.6} |
| 176 |
\ctikzset{bipoles/tfullgeneric/height/.initial=.525} |
| 177 |
\ctikzset{bipoles/tfullgeneric/width/.initial=.60} |
| 178 |
\ctikzset{bipoles/fullgeneric/height/.initial=.23} |
| 179 |
\ctikzset{bipoles/fullgeneric/width/.initial=.6} |
| 180 |
\ctikzset{bipoles/diode/height/.initial=.3} |
| 181 |
\ctikzset{bipoles/diode/width/.initial=.25} |
| 182 |
\ctikzset{bipoles/bidirectionaldiode/height/.initial=.66} |
| 183 |
\ctikzset{bipoles/bidirectionaldiode/width/.initial=.6} |
| 184 |
\ctikzset{bipoles/bidirectionaldiode/diode width left/.initial=.3} |
| 185 |
\ctikzset{bipoles/bidirectionaldiode/diode width right/.initial=.3} |
| 186 |
\ctikzset{tripoles/thyristor/height/.initial=.66} |
| 187 |
\ctikzset{tripoles/thyristor/height 2/.initial=.3} |
| 188 |
\ctikzset{tripoles/thyristor/width/.initial=.6} |
| 189 |
\ctikzset{tripoles/thyristor/diode height/.initial=.3} |
| 190 |
\ctikzset{tripoles/thyristor/diode width left/.initial=.4} |
| 191 |
\ctikzset{tripoles/thyristor/diode width right/.initial=.3} |
| 192 |
\ctikzset{tripoles/triac/height/.initial=.66} |
| 193 |
\ctikzset{tripoles/triac/width/.initial=.6} |
| 194 |
\ctikzset{tripoles/triac/diode width left/.initial=.3} |
| 195 |
\ctikzset{tripoles/triac/diode width right/.initial=.3}} |
| 196 |
\circuoption {european} |
| 197 |
{\circusetup{europeanvoltage,europeancurrent,europeanresistor, |
| 198 |
europeaninductor,europeangfsurgearrester,europeanport}} |
| 199 |
\circuoption {american} |
| 200 |
{\circusetup{americanvoltage,americancurrent,americanresistor, |
| 201 |
americaninductor,americangfsurgearrester,americanport}} |
| 202 |
|
| 203 |
\circuoption {siunitx} {\pgf@circ@siunitxtrue \the\siunitxdefs} |
| 204 |
\circuoption {nosiunitx} {\pgf@circ@siunitxfalse} |
| 205 |
\circuoption {compatibility} {\pgf@circuit@compattrue} |
| 206 |
|
| 207 |
% The \SI macro is executed when a user sets siunitx option and uses value<unit> syntax. |
| 208 |
% We don't want to load complicated siunitx.sty LaTeX package, |
| 209 |
% only few units are provided in simply way, you can declare others similarly. |
| 210 |
|
| 211 |
\newtoks\siunitxdefs \siunitxdefs={ |
| 212 |
\def\SI#1#2{#1\,\hbox{#2}} |
| 213 |
\def\ampere{A} |
| 214 |
\def\ohm{$\Omega$} |
| 215 |
\def\volt{V} |
| 216 |
\def\farrad{F} |
| 217 |
\def\pico{p} |
| 218 |
\def\micro{$\ifx\mupmu\undefined \mu\else \mupmu\fi$} |
| 219 |
\def\mili{m} |
| 220 |
\def\kilo{k} |
| 221 |
} |
| 222 |
|
| 223 |
% We don't need xstring.sty macros for searching angles in the parameter: |
| 224 |
|
| 225 |
\def\pgf@circ@handleSI#1{\circuangles #1\end<>\end\relax{#1}} |
| 226 |
\def\circuangles #1<#2>#3\end#4\relax#5{% |
| 227 |
\ifx\end#4\end \pgf@circ@siunitx@resfalse |
| 228 |
\else \pgf@circ@siunitx@restrue |
| 229 |
\def\pgf@circ@handleSI@unit{#2}% |
| 230 |
\def\pgf@circ@handleSI@val{#1}% |
| 231 |
\fi |
| 232 |
} |
| 233 |
|
| 234 |
\circuleave % @ has its original catcode |
| 235 |
|
| 236 |
% default options: |
| 237 |
\circusetup {nofetbodydiode, nofetsolderdot, europeancurrents, europeanvoltages, |
| 238 |
americanports, americanresistors, cuteinductors, |
| 239 |
europeangfsurgearrester, nosiunitx, noarrowmos, smartlabels} |
| 240 |
|
| 241 |
\let\circuitikz=\tikzpicture |
| 242 |
\let\endcircuitikz=\endtikzpicture |
| 243 |
\let\circu=\tikzpicture |
| 244 |
\let\endcircu=\endtikzpicture |
| 245 |
|
| 246 |
\endinput |
| 247 |
|
| 248 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 249 |
% |
| 250 |
% Examples: |
| 251 |
|
| 252 |
\input circu |
| 253 |
\circusetup{siunitx} |
| 254 |
|
| 255 |
\circu |
| 256 |
\draw (0,0) to[R=2<\ohm>, i=?, v=84<\volt>] (2,0) -- |
| 257 |
(2,2) to[V<=84<\volt>] (0,2) |
| 258 |
-- (0,0); |
| 259 |
\endcircu |
| 260 |
|
| 261 |
\bigskip |
| 262 |
|
| 263 |
\circusetup{siunitx, american} |
| 264 |
|
| 265 |
\circu |
| 266 |
\draw (0,0) to[R=2<\ohm>, i=?, v=84<\volt>] (2,0) -- |
| 267 |
(2,2) to[V<=84<\volt>] (0,2) |
| 268 |
-- (0,0); |
| 269 |
\endcircu |
| 270 |
|
| 271 |
\bigskip |
| 272 |
|
| 273 |
\circu [american] |
| 274 |
\draw (0,0) to[isource, l=$I_0$] (0,3) |
| 275 |
to[short, -*, i=$I_0$] (2,3) |
| 276 |
to[R=$R_1$, i=$i_1$] (2,0) -- (0,0); |
| 277 |
\draw (2,3) -- (4,3) |
| 278 |
to[R=$R_2$, i=$i_2$] |
| 279 |
(4,0) to[short, -*] (2,0); |
| 280 |
\endcircu |
| 281 |
|
| 282 |
\bigskip |
| 283 |
|
| 284 |
\circu [american, voltage shift=0.5] |
| 285 |
\draw (0,0) |
| 286 |
to[isource, l=$I_0$, v=$V_0$] (0,3) |
| 287 |
to[short, -*, f=$I_0$] (2,3) |
| 288 |
to[R=$R_1$, f>_=$i_1$] (2,0) -- (0,0); |
| 289 |
\draw (2,3) -- (4,3) |
| 290 |
to[R=$R_2$, f>_=$i_2$] |
| 291 |
(4,0) to[short, -*] (2,0); |
| 292 |
\draw[red, thick] (0.6,2.1) rectangle (4.2,3.8) |
| 293 |
node[pos=0.5, above]{KCL}; |
| 294 |
\endcircu |
| 295 |
|
| 296 |
\bigskip |
| 297 |
|
| 298 |
\ctikzset{amplifiers/fill=cyan!20, component text=left} |
| 299 |
\circu [scale=0.8, transform shape] |
| 300 |
\draw (0,0) node[above]{$v_i$} to[short, o-] ++(1,0) |
| 301 |
node[op amp, noinv input up, anchor=+](OA){\tt OA1} |
| 302 |
(OA.-) -- ++(0,-1) coordinate(FB) |
| 303 |
to[R=$R_1$] ++(0,-2) node[ground]{} |
| 304 |
(FB) to[R=$R_2$, *-] (FB -| OA.out) -- (OA.out) |
| 305 |
to [short, *-o] ++(1,0) node[above]{$v_o$}; |
| 306 |
\endcircu |
| 307 |
|
| 308 |
\bigskip |
| 309 |
|
| 310 |
\tikzset{sr-ff/.style={flipflop, flipflop def={ |
| 311 |
t1=S, t2=CP, t3=R, t4={\ctikztextnot{Q}}, |
| 312 |
t6=Q, nd=1}}, |
| 313 |
} |
| 314 |
\def\myblock#1{% Add #1- to the node and coord names |
| 315 |
node[sr-ff](#1-FF){} (#1-FF.bup) node[above]{SR-FF} |
| 316 |
(#1-FF.pin 1) -- ++(-1,0) node[and port, anchor=out](#1-AND1){} |
| 317 |
(#1-FF.pin 3) -- (#1-FF.pin 3 -| #1-AND1.out) |
| 318 |
node[and port, anchor=out](#1-AND2){} |
| 319 |
(#1-AND1.in 1) to[short, -*] ++(-1,0) coordinate(#1-in) |
| 320 |
to[inline not] (#1-in |- #1-AND2.in 2) -- (#1-AND2.in 2) |
| 321 |
} |
| 322 |
\circu |
| 323 |
\draw (0,0) \myblock{A}; |
| 324 |
\draw (0,-4) \myblock{B}; |
| 325 |
\draw (A-in) -- ++(-0.5, 0) node[below]{$a_0$}; |
| 326 |
\draw (B-in) -- ++(-0.5, 0) node[below]{$a_1$}; |
| 327 |
\draw (A-AND1.in 2) to[short, -*] (A-AND2.in 1) |
| 328 |
to[short, -*] (B-AND1.in 2) to[short, -*] (B-AND2.in 1) |
| 329 |
-- ++(0, -2) coordinate(down) node[below]{ENABLE}; |
| 330 |
\draw (A-FF.pin 2) to[short, -*] (B-FF.pin 2) |
| 331 |
-- (B-FF.pin 2 |- down) node[below]{CP}; |
| 332 |
\draw (B-FF.down) to[short, -*] ++(0,-0.3) coordinate(dd); |
| 333 |
\draw (A-FF.down) -- ++(0,-.5) -- ++(1.5,0) |- (dd) |
| 334 |
-- (dd |- down) node[below]{RESET}; |
| 335 |
\endcircu |
| 336 |
|
| 337 |
|
| 338 |
\bye |
| 339 |
|