Debian Codegraph @

texmf-dist/doc/latex/tikzdotncross/tikzdotncross.tex

raw
1 %%%==============================================================================
2 % WinEdt pragmas
3 % !Mode:: "TeX:EN"
4 % Default Compile engines:
5 % !TEX program = pdflatex
6 % !PDFTeXify ext = --enable-etex --restrict-write18
7 % !PDFLaTeX ext = --enable-etex --restrict-write18
8 % !BIB program = biber
9 %%%==============================================================================
10 %% Copyright 2024-present by Alceu Frigeri
11 %%
12 %% This work may be distributed and/or modified under the conditions of
13 %%
14 %% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
15 %% version 1.3c (or later), and/or
16 %% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html),
17 %% version 3 (or later)
18 %%
19 %% This work has the LPPL maintenance status *maintained*.
20 %%
21 %% The Current Maintainer of this work is Alceu Frigeri
22 %%
23 %% This is version {1.3b} {2025/11/10}
24 %%
25 %% The list of files that compose this work can be found in the README.md file at
26 %% https://ctan.org/pkg/tikzdotncross
27 %%
28 %%%==============================================================================
29 \documentclass[10pt]{article}
30 \RequirePackage[verbose,a4paper,marginparwidth=27.5mm,top=2.5cm,bottom=1.5cm,hmargin={40mm,20mm},marginparsep=2.5mm,columnsep=10mm,asymmetric]{geometry}
31 \usepackage[T1]{fontenc}
32 \usepackage[utf8]{inputenc}
33 \usepackage{lmodern}
34 \usepackage[infograb]{codedescribe}
35 \RequirePackage[inline]{enumitem}
36 \SetEnumitemKey{miditemsep}{parsep=0ex,itemsep=0.4ex}
37
38 \RequirePackage[backend=biber]{biblatex}
39 \addbibresource{tikzdotncross.bib}
40
41 \usepackage[american,siunitx,cuteinductors,smartlabels,arrowmos,EFvoltages,betterproportions]{circuitikz}
42 \usepackage{tikzdotncross}
43 \RequirePackage[hidelinks,hypertexnames=false]{hyperref}
44
45
46 %%
47 %% setting keywords emphasis
48 %%
49 \setnewcodekey{dotncross keys}
50 {
51 emph={draw,node,ncoord,pincoord,dotcoord,odotcoord},
52 emph2={pathcross},
53 emph3={name,path},
54 %basicstyle={\scriptsize\ttfamily},
55 numbers=left,
56 codeprefix={},
57 resultprefix={}
58 }
59
60
61 \begin{document}
62 \tstitle{
63 author={Alceu Frigeri\footnote{\tsverb{https://github.com/alceu-frigeri/tikzdotncross}}},
64 date={\tsdate},
65 title={The tikzdotncross Package\break Marking Coordinates and Crossing Paths\break Version \PkgInfo{tikzdotncross}{version}}
66 }
67
68
69 \begin{typesetabstract}
70
71 This package offers a few alternative ways for declaring and marking coordinates and drawing a line with ``jumps over'' an already given path, which is a quite common issue when drawing, for instance, Electronics Circuits, e.g. \tsobj[pkg]{CircuiTikZ}\cite{circuitikz}.
72 \end{typesetabstract}
73
74 \tableofcontents
75
76 \section{Introduction}
77 One recurring problem when drawing circuits in general is how to interpret a crossing line. There are many conventions, notably, for the old school (like the author of this) a jump denotes ``non touching lines'' while a simple cross is a connection, more recently (like the past 25 years), the winning convention has been that a dot marks a connection, whilst a simple cross denotes ``non touching lines''. Many, for the sake of staying in the safe side of the wall, mark a connection with dots and non touching lines with a jump, which is a bit overkill, but at least there is no margin for interpretation errors.
78
79 And that's it, this package defines some commands to mark/pin a connection, declaring a coordinate and node at the same spot, for later reference, and a command to draw a line jumping over crossing lines of a pre-existent path.
80
81 \section{Requirements}
82
83 The user has to load \tsobj[pkg]{tikz}\cite{TIKZPGF:3.1} (directly, or indirectly, for instance loading \tsobj[pkg]{circuitikz}\cite{circuitikz}) before using this package.
84
85 Keep in mind, as well, that this package loads some Ti\emph{k}Z libraries (\tsobj[pkg]{math,intersections}) and the \tsobj[pkg]{etoolbox}\cite{etoolbox} package.
86
87
88 \begin{codestore}[reqmts]
89 \usepackage{tikz}
90 \usepackage{tikzdotncross}
91 \end{codestore}
92 \begin{codestore}[reqmts]
93 \usepackage[american,siunitx]{circuitikz}
94 \usepackage{tikzdotncross}
95 \end{codestore}
96 \tscode*[dotncross keys]{reqmts}[1]
97 \tscode*[dotncross keys]{reqmts}[2]
98
99
100 \section{Package Options}\label{options}
101 \begin{describelist}{option}
102 \describe {pinsize} {pin (circle) size (default: 1.2), in pt.}
103 \describe {pinang} {pin angle (default: 45). }
104 \describe {pincolor} {pin color (default: blue).}
105 \describe {pinlength} {pin length (default: 4), in pt.}
106 \describe {coordcolor} {coordinate color (default: red), used if \tsobj{\showcoordstrue}.}
107 \end{describelist}
108
109
110 Those can also be set, middle code, via:
111 \begin{codedescribe}[code,new=2024/10/22]{\setpindefaults}
112 \begin{codesyntax}%
113 \tsmacro{\setpindefaults}{options as above}
114 \end{codesyntax}
115 \end{codedescribe}
116
117 \section{Declaring and Marking Coordinates/Nodes}\label{coord}
118 Those are based on some ideas from Redaelli et al. (\tsobj[pkg]{CircuiTikZ}). Main differences: a variable number of parameters (see below) and it always also adds an empty node n\tsobj[marg]{coord}.
119 \begin{codedescribe}{\showcoordstrue,\shoocoordsfalse}
120 \begin{codesyntax}%
121 \tsmacro{\showcoordstrue}{}
122 \tsmacro{\showcoordsfalse}{}
123 \end{codesyntax}
124 These will affect how \tsobj{\ncoord,\dotcoord,\odotcoord} will behave, with \tsobj{\showcoordstrue} a red pin will also be added to the newly defined coordinate/node. The initial state is \tsobj{\showcoordsfalse}. It can be turned on/off as needed.
125 \end{codedescribe}
126
127 \begin{codedescribe}[code,new=2025/10/29]{\showcoords}
128 \begin{codesyntax}%
129 \tsmacro{\showcoords}{val}
130 \end{codesyntax}
131 Alternative form to set newly defined coordinates visibility. If \tsobj[marg]{val} is either \tsobj[option,sep=or]{on,true} this will be equivalent to \tsobj{\showcoordstrue}, otherwise if \tsobj[marg]{val} is either \tsobj[option,sep=or]{off,false} this will be equivalent to \tsobj{\showcoordsfalse}.
132 \end{codedescribe}
133
134
135
136 \begin{codedescribe}{\ncoord,\pincoord}
137 \begin{codesyntax}%
138 \tsobj{\ncoord}\tsverb{(}\tsobj[oarg]{coord}\tsverb{)}
139 \tsobj{\pincoord}\tsverb{(}\tsobj[oarg,comma]{coord}\tsverb{)}
140 \tsobj{\pincoord}\tsverb{(}\tsobj[oarg,comma]{coord,color}\tsverb{)}
141 \tsobj{\pincoord}\tsverb{(}\tsobj[oarg,comma]{coord,color,angle}\tsverb{)}
142 \tsobj{\pincoord}\tsverb{(}\tsobj[oarg,comma]{coord,color,angle,length}\tsverb{)}
143 \end{codesyntax}
144 The \tsobj{\ncoord} always expects a single parameter \tsobj[parg]{coord}. A coordinate named \tsobj[marg]{coord} and node named n\tsobj[marg]{coord} (a ``n'' is added as a prefix) will be created for later use/reference. If \tsobj{\showcoordstrue} is en force, it will also add a pin.
145
146 The \tsobj{\pincoord} always draws a pin, besides declaring a coordinate and node as \tsobj{\ncoord}. It expects one to 4 parameters, as listed. If omitted, the default length is 4 (unit: pt), the default angle is -45 (degrees), the default color is blue.
147 Likewise, if \tsobj{\showcoordstrue}, \tsobj{\ncoord(name)} is just a short cut for \tsverb{\pincoord(name,red,45)}.
148 \end{codedescribe}
149 \begin{tsremark}
150 Those defaults can be changed via package options, see \ref{options}, or \tsobj{\setpindefaults}.
151 \end{tsremark}
152
153 \begin{codedescribe}{\dotcoord,\dotpincoord}
154 \begin{codesyntax}%
155 \tsobj{\dotcoord}\tsverb{(}\tsobj[oarg]{coord}\tsverb{)}
156 \tsobj{\dotpincoord}\tsverb{(}\tsobj[oarg,comma]{coord}\tsverb{)}
157 \tsobj{\dotpincoord}\tsverb{(}\tsobj[oarg,comma]{coord,color}\tsverb{)}
158 \tsobj{\dotpincoord}\tsverb{(}\tsobj[oarg,comma]{coord,color,angle}\tsverb{)}
159 \tsobj{\dotpincoord}\tsverb{(}\tsobj[oarg,comma]{coord,color,angle,length}\tsverb{)}
160 \end{codesyntax}
161 These are the same as \tsobj{\ncoord} and friends, just adding a dot (a filled in, small circle) at the coordinate.
162 \end{codedescribe}
163
164 \begin{codedescribe}{\odotcoord,\odotpincoord}
165 \begin{codesyntax}%
166 \tsobj{\odotcoord}\tsverb{(}\tsobj[oarg]{coord}\tsverb{)}
167 \tsobj{\odotpincoord}\tsverb{(}\tsobj[oarg,comma]{coord}\tsverb{)}
168 \tsobj{\odotpincoord}\tsverb{(}\tsobj[oarg,comma]{coord,color}\tsverb{)}
169 \tsobj{\odotpincoord}\tsverb{(}\tsobj[oarg,comma]{coord,color,angle}\tsverb{)}
170 \tsobj{\odotpincoord}\tsverb{(}\tsobj[oarg,comma]{coord,color,angle,length}\tsverb{)}
171 \end{codesyntax}
172 These are the same as \tsobj{\ncoord} and friends, just adding an open dot (a small circle filled with white) at the coordinate.
173 \end{codedescribe}
174
175
176
177 \section{Crossing Paths}\label{pathcross}
178
179 \begin{codedescribe}{\pathcross}
180 \begin{codesyntax}%
181 \tsobj{\pathcross*}\tsargs[oarg]{cross-name}\tsargs[marg]{coordA,coordB,path-name}\tsargs[oarg]{width}
182 \end{codesyntax}
183 This will draw a line from \tsobj[marg]{coordA} to \tsobj[marg]{coordB} ``jumping over'' any pre-existent (soft) path named \tsobj[marg]{path-name}.
184 First of, the reference path \tsobj[marg]{path-name} has to be defined using the \tsobj[key]{name path} key (\tsobj[key]{name path}=\tsobj[marg]{path-name}).
185
186 Then this will ``calculate'' the intersections between the line (defined by the coordinates (\tsobj[marg]{coordA}) and (\tsobj[marg]{coordB}) and the path named \tsobj[marg]{path-name}. At each intersection a coordinate named (\tsobj[oarg]{cross-name}-i) and a node (n\tsobj[oarg]{cross-name}-i) will be defined (i goes from 1 up to the number of crossings detected.) A macro named \tsobj[oarg]{cross-name}T will have the number of crossings found.
187
188 At each intersection a semi-circle will be drawn, and finally a line will be draw connecting \tsobj[marg]{coordA} to \tsobj[marg]{coordB} over all intermediate nodes.
189
190 The star version flips the semi-circles orientation.
191 \begin{tsremark}
192 The default \tsobj[oarg]{cross-name} is ``cross''. It may contain only characters, as any valid \TeX\ macro name. The default \tsobj[oarg]{width} of the semi-circle is 7pt.
193 \end{tsremark}
194 \begin{tsremark}
195 This is based on the \tsobj[pkg]{tikz} library \tsobj[pkg]{intersetions}, inheriting it's limitations. The main one: It only detects crossings over ``soft paths'', this means, if the line defined by \tsobj[marg]{coordA} and \tsobj[marg]{coordB} crosses over a node, it will, in most cases, miss it (depends on how the node is draw and interacts with the soft path system).
196 \end{tsremark}
197 \begin{tsremark}
198 When using the crossing coordinates, like (\tsobj[oarg]{cross-name}-i), be aware that in some ill-defined cases, \tsobj[pkg]{intersections} might detect a crossing either at the starting and/or ending points. \tsobj{\pathcross} accounts for that, but you will be left with some extra reference coordinates, either the first one, last one or both.
199 \end{tsremark}
200 \end{codedescribe}
201
202 %\newpage
203 \section{Some Examples}
204 \textbf{\color{red}Note:} In the examples below, the circuit doesn't make much/any sense, it is just a way to show the commands possibilities.
205
206 %\showcoordstrue
207 \showcoords{true}
208 \begin{codestore}[crossdemoA]
209 \resizebox{0.45\textwidth}{!}{
210 \begin{tikzpicture}
211 %% This is the reference, named path
212 %%
213 \draw[name path=base circ]
214 (0,0) \dotcoord(A) to[V,invert,l=$v_i(t)$] ++(0,2) -- ++(0,1) \ncoord(Y)
215 to[R=$R_i$] ++(2,0)
216 to[C] ++(1,0) \pincoord(A1) ++(1,0) \ncoord(B)
217 ++(1,0) node[pnp,anchor=B] (T1){}
218 (A) -- (A -| B) to[R=$R_{b_2}$] ++(0,2) \ncoord(Bb) (B) ++(0,1) \ncoord(Cb) to[R=$R_{b_1}$] ++(0,2) \ncoord(C)
219 (T1.C) to[R,l_=$R_c$] (T1.C |- A) -- (A)
220 (T1.E) to[R,l=$R_e$] (T1.E |- C) -- (C -| A) -- ++(-2,0) \ncoord(X) to[V,l=$V_{cc}$] (X |- A) -- (A)
221 (T1.C) -- ++(1,0) node[ocirc]{} \ncoord(k) to[open,v=$v_o(t)$] (k |- A) node[ocirc]{} -- (A)
222 (Bb) -- (Cb)
223 ;
224 %% These are just a few, marked, coords (they could be part of the previous path
225 %%
226 \path (T1.E) ++(1,0) \pincoord(B1) ++(-10,2) \pincoord(B2)
227 (B1) ++(0,-1) \pincoord(D1) (B2) ++(0,-1) \pincoord(D2)
228 (T1.C) ++(0.5,-0.5) \pincoord(C1) (T1.C) ++(-9,0) \pincoord(C2)
229 (T1.B) \odotpincoord(A2,blue,225)
230 ;
231 %% And that's all, a few crossing lines
232 %%
233 \pathcross{A1}{A2}{base circ}[4pt] \draw (Y) +(0,1.7) node(){N.cross A:\crossT};
234 \pathcross*{B1}{B2}{base circ}[3pt] \draw (Y) +(0,1.3) node(){N.cross B:\crossT};
235 \pathcross*[sec]{C1}{C2}{base circ}[6pt] \draw (Y) +(0,0.9) node(){N.cross C:\secT};
236
237 \end{tikzpicture}
238 }
239 \end{codestore}
240
241 %\tsdemo*[emph={draw,node,ncoord,pincoord,dotcoord,odotcoord},emph2={pathcross},emph3={name,path},basicstyle={\scriptsize\ttfamily},numbers=left]{crossdemoA}
242 \tscode*[dotncross keys]{crossdemoA}
243 \newpage
244 A first example with \tsobj{\showcoords{true}} (showing all coordinates defined with \tsobj{\ncoord}):
245
246 \tsresult*[dotncross keys]{crossdemoA}
247 And the same with \tsobj{\showcoords{false}}
248 %\showcoordsfalse
249 \showcoords{false}
250
251 %%\tsresult*[emph={draw,node,ncoord,pincoord,dotcoord,odotcoord},emph2={pathcross},emph3={name,path},basicstyle={\scriptsize\ttfamily},numbers=left]{crossdemoA}
252 \tsresult*[dotncross keys]{crossdemoA}
253
254 %%%\begin{tabular}{lr}\hline\\
255 %%%\showcoords{true} \tsexec{crossdemoA} & \showcoords{false} \tsexec{crossdemoA} \\
256 %%%\hline
257 %%%\end{tabular}\\
258
259 The main limitation (derived from how \tsobj[pkg]{intersections} works) is that crossings between the line and nodes might not be detected at all. For example, if someone tries to connect the nodes \tsobj[key]{D1,D2}, it will, unfortunately, fail detecting the node (pnp transistor) entirely:
260
261 %\showcoordstrue
262 %\setpindefaults{coordcolor=cyan,pincolor=red}
263 \begin{codestore}[crossdemoC]
264 \resizebox{0.5\textwidth}{!}{
265 \begin{tikzpicture}
266 %% This is the reference, named path
267 %%
268 \draw[name path=base circ]
269 (0,0) \dotcoord(A) to[V,invert,l=$v_i(t)$] ++(0,2) -- ++(0,1) \ncoord(Y)
270 to[R=$R_i$] ++(2,0)
271 to[C] ++(1,0) \pincoord(A1) ++(1,0) \ncoord(B)
272 ++(1,0) node[pnp,anchor=B] (T1){}
273 (A) -- (A -| B) to[R=$R_{b_2}$] ++(0,2) \ncoord(Bb) (B) ++(0,1) \ncoord(Cb) to[R=$R_{b_1}$] ++(0,2) \ncoord(C)
274 (T1.C) to[R,l_=$R_c$] (T1.C |- A) -- (A)
275 (T1.E) to[R,l=$R_e$] (T1.E |- C) -- (C -| A) -- ++(-2,0) \ncoord(X) to[V,l=$V_{cc}$] (X |- A) -- (A)
276 (T1.C) -- ++(1,0) node[ocirc]{} \ncoord(k) to[open,v=$v_o(t)$] (k |- A) node[ocirc]{} -- (A)
277 (Bb) -- (Cb)
278 ;
279 %% These are just a few, marked, coords (they could be part of the previous path
280 %%
281 \path (T1.E) ++(1,0) \pincoord(B1) ++(-10,2) \pincoord(B2)
282 (B1) ++(0,-1) \pincoord(D1) (B2) ++(0,-1) \pincoord(D2)
283 (T1.C) ++(0.5,-0.5) \pincoord(C1) (T1.C) ++(-9,0) \pincoord(C2)
284 (T1.B) \pincoord(A2,blue,225)
285 ;
286 %% And that's all, a few crossing lines
287 %%
288 \pathcross{A1}{A2}{base circ}[4pt] \draw (Y) +(0,2) node(){N.cross A:\crossT};
289 \pathcross[sec]{D2}{D1}{base circ}[6pt] \draw (Y) +(0,1.6) node(){N.cross D:\secT};
290 \end{tikzpicture}
291 }
292 \end{codestore}
293
294 %\tsdemo*[emph={draw,node,ncoord,pincoord,dotcoord,odotcoord},emph2={pathcross},emph3={name,path},basicstyle={\scriptsize\ttfamily},numbers=left]{crossdemoC}
295 \tsdemo*[dotncross keys]{crossdemoC}
296
297 \printbibliography
298
299 \end{document}