summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/circuitikz/doc/ctikzmanutils.sty
blob: 8d364404f0c71f67d29a9da611034a825d02f63b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
% Copyright 2018-2020 by Romano Giannetti
% Copyright 2015-2020 by Stefan Lindner
% Copyright 2013-2020 by Stefan Erhardt
% Copyright 2007-2020 by Massimo Redaelli
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ctikzmanutils}[2019/07/26 utilities for formatting circuitikz manual]
\RequirePackage{ifthen}
\RequirePackage{xparse}
\RequirePackage{showexpl}
\RequirePackage{ragged2e}
% for some example we need them...
\usetikzlibrary{calc,fit}
\RequirePackage{upgreek}
%
% The following trick is used to silence showexpl a bit, so that the
% logs are readable...
%
\makeatletter
\let\SX@Info=\relax % silence showexpl a bit...
\makeatother
%
\lstset{pos=l,width=-99pt, overhang=0pt,hsep=\columnsep,vsep=\bigskipamount,
    rframe=single,numbers=left,numberstyle=\tiny,numbersep=.3em, xleftmargin=1em,
    columns=flexible, language=[LaTeX]TEX,breaklines=true,
    basicstyle=\normalsize\ttfamily,tabsize=3}

%
% draw the shape without affecting anything
\newcommand{\drawphantomshape}[1] {%
    {\tikz [overlay, color=blue] \path (0,0) node[#1]{};}
}
%% New circuit description macros
\newcommand{\twopartbox}[2]{%
    \leavevmode\null\par\noindent\fbox{\parbox[c]{0.3\linewidth}{#1} \parbox[c]{0.6\linewidth}{\raggedright #2}\par\noindent}%
}
% filling color for filled-enabled component
\colorlet{fillcol}{cyan!30!white}
% find the class for the element. Thanks to Symbol 1
% https://tex.stackexchange.com/a/501389/38080
\def\checkclass#1{%
    \csname pgf@sh@ma@#1\endcsname
    \ifdefined\ctikzclass
        Class: \texttt{\ctikzclass}.%
    \else
        No class.%
    \fi
}
% description of a node component:
% optional star for fillable
% optional: scale of the component in the entry
% mandatory  shape name, description, node text:
% optional between (): anchor specification list
% optional between []: internal nodes specification list
\NewDocumentCommand{\circuitdesc}{s O{1} m m m d() d[]}
{
    \twopartbox{%
        \begin{circuitikz}[]
            \IfBooleanTF{#1}{%
                \draw (0,0) node[#3,scale=#2, fill=fillcol](N){#5};
                }{
                \draw (0,0) node[#3,scale=#2](N){#5};
            }
            \IfValueT{#6}{%
                \foreach \n/\a/\d in {#6} \path(N.\n) \showcoord(\n)<\a:\d>;
            }
            \IfValueT{#7}{%
                \foreach \n/\a/\d in {#7} \path(N-\n) \showcoordb(N-\n)<\a:\d>;
            }
        \end{circuitikz}%
        }{\sloppy%
        {#4, type: node\IfBooleanT{#1}{, fillable}%
        } (\texttt{node[\detokenize{#3}]\IfValueT{#7}{(N)}\{\detokenize{#5}\}}). \index{#3}%
        \checkclass{N}%
    }%
}
% description of a path-style component:
% optional: main name, if different from above
% mandatory component name, description, comma separated alias
% optional between (): anchor specification list
% optional between []: internal nodes specification list
\NewDocumentCommand{\circuitdescbip}{s o m m m d() d[]}
{
\index{#3} \tikz\foreach \i in {#5} {\index{\i|see{#3}} };
    \twopartbox{%
        \begin{circuitikz}
        \IfBooleanTF{#1}{%
            \draw (0,0) to[#3, name=B, fill=fillcol] (2,0);
            }{
            \draw (0,0) to[#3, name=B] (2,0);
        }
        \IfValueT{#6}{%
                \foreach \n/\a/\d in {#6} \path(B.\n) \showcoord(\n)<\a:\d>;
            }
            \IfValueT{#7}{%
                \foreach \n/\a/\d in {#7} \path(B-\n) \showcoordb(B-\n)<\a:\d>;
            }
        \end{circuitikz}%
        }{\sloppy%
        \texttt{\textbf{#3}}: #4, \texttt{type: path-style\IfBooleanT{#1}{, fillable}%
            \IfValueT{#7}{, \texttt{name=B}}%
            \IfValueTF{#2}{, nodename: #2shape.%\drawphantomshape{#2shape}%
            }{, nodename: #3shape.%\drawphantomshape{#3shape}%
            }%
        }%
        \ifthenelse{\equal{#5}{}}{ }{%
        Aliases: \texttt{#5}. }\checkclass{B}%
    }%
}

%new environment for grouping descriptions
\newenvironment{groupdesc}{\medskip\begingroup}{\endgroup\par\medskip\par\noindent}

% command to show anchors: (name)<angle>
% usage in path: \path (anchor) \coord(anchor)<60>
\makeatletter % we use the internal circuitikz base length
\def\showcoord(#1)<#2:#3>{%
    node[circle, red, draw, inner sep=1pt,pin={%
        [red, inner sep=0.5pt, font=\small,
        pin distance=#3\pgf@circ@Rlen, pin edge={red, }%
    ]#2:#1}](#1){}}
\def\showcoordb(#1)<#2:#3>{%
    node[circle, blue, draw, inner sep=1pt,pin={%
        [blue, inner sep=0.5pt, font=\small,
        pin distance=#3\pgf@circ@Rlen, pin edge={blue, }%
    ]#2:#1}](#1){}}
\makeatother
% show anchors of a node component:
% optional: options of the circuitikz environment
% mandatory  node spec, node text
% optional between (): anchor specification list
\NewDocumentCommand{\showanchors}{O{} m m d()}
{
        \begin{circuitikz}[#1]
                \draw (0,0) node[#2](N){#3};
            \IfValueT{#4}{%
                \foreach \n/\a/\d in {#4} \path(N.\n) \showcoord(\n)<\a:\d>;
            }
        \end{circuitikz}%
}


\newcommand{\geolrcoord}[2][]{\showanchors[#1]{#2}{text}(north/90/0.4, north east/45/0.4, east/0/0.4,
    south east/-45/0.4,
    south/-90/0.4, south west/-135/0.4, west/180/0.4, north west/135/0.4,
    left/160/0.4, right/30/0.4, center/-120/0.3
    )
}

\newcommand{\geocoord}[2][]{\showanchors[#1]{#2}{text}(north/90/0.4, north east/45/0.4, east/0/0.4,
    south east/-45/0.4,
    south/-90/0.4, south west/-135/0.4, west/180/0.4, north west/135/0.4,
    center/-120/0.3
    )
}