summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/steinmetz/steinmetz.dtx
blob: af24d035cefb73b8da952e6326d4fe73b3d0bddd (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
% \iffalse meta-comment
%
% Copyright (C) 2009 by Enrico Gregorio
% <Enrico dot Gregorio (at) univr dot it>
% ---------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX 
% version 2005/12/01 or later.
%
% This work consists of the files steinmetz.dtx and steinmetz.ins
% and the derived files steinmetz.sty and steinmetz-test.tex
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{steinmetz.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{steinmetz}
%<*package>
    [2009/06/14 v1.0 Steinmetz symbol for electrotechnics]
%</package>
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\IfFileExists{steinmetz.sty}{\usepackage{steinmetz}}{}
\newcommand{\cmdname}[1]{\texttt{\char`\\#1}}
\newcommand{\bigstrut}{\vphantom{\vrule height 1.5\normalbaselineskip
    width 0pt}}
\providecommand{\phase}[2][]{\mbox{?}}
\EnableCrossrefs         
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{steinmetz.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{166}
% 
% \catcode`\@=12
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.0}{2009/06/04}{Initial version}
%
% \GetFileInfo{steinmetz.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment,\advance,\begin,\box,\dimen@}
% \DoNotIndex{\displaystyle,\textstyle,\scriptstyle,\scriptscriptstyle}
% \DoNotIndex{\dp,\edef,\end,\fi,\hbox,\ht,\ifcase,\newlength,\newsavebox}
% \DoNotIndex{\or,\raise,\relax,\RequirePackage,\sbox,\setbox,\setlength}
% \DoNotIndex{\vbox,\vss,\wd,\z@}
%
%
% \title{The \textsf{steinmetz}
%   package\thanks{This document corresponds to
%     \textsf{steinmetz}~\fileversion, dated \filedate.}}
% 
% \author{Enrico Gregorio \\
%   \texttt{Enrico dot Gregorio (at) univr dot it}}
% 
% \date{\filedate}
%
% \maketitle
%
% \section{Introduction}
%
% In electrotechnics it is common a notation for variables taking on
% complex values. First of all any nonzero complex number $z$ admits a
% unique representation as
% \[
% z=\varrho(\cos\alpha+i\sin\alpha)
% \]
% where $\varrho$ is a positive real number and $\alpha$ is a real
% number in the interval $[0,2\pi)$. In technical applications $\alpha$
% is expressed in degrees, with figures such as $30^{\circ}$. The
% conversion is very easy by considering $^{\circ}$ as the
% multiplicative constant $\pi/180$. By Euler formulas, we can write
% \[
% z=\varrho(\cos\alpha+i\sin\alpha)=\varrho e^{i\alpha}
% \]
% but Steinmetz, in the nineteenth century, started to express this in a
% simplified form:
% \[
% z=\varrho\angle\alpha
% \]
% which has however the disadvantage to be difficult to interpret when
% the angle is the result of some algebraic expression. This is where
% this package helps: indeed we can write
% \iffalse
%<*verb>
% \fi
\begin{verbatim}
z=\varrho\phase{\alpha+\beta}
\end{verbatim}
% \iffalse
%</verb>
% \fi
% which gives
% \[
% z=\varrho\phase{\alpha+\beta}
% \]
% making it clear what is the angle to consider. Some textbooks in
% electrotechnics use this notation and some users asked how to
% produce it in {\LaTeX}.
%
%
% \subsection*{Dependencies}
%
% Note that this package requires \textsf{pict2e}, so a fairly recent
% version of {\LaTeX} is needed. In order to typeset this document,
% you have to generate the package file, by running {\LaTeX} on
% \texttt{steinmetz.ins}, unless it's already in your distribution.
%
% \section{Commands}
%
% \DescribeMacro{\phase}
% This package provides only one command, \cmdname{phase}, which takes
% as argument the angle to be enclosed in the Steinmetz symbol. It may
% receive also an optional argument, an integer number from $0$ to $3$
% (default~$1$). This optional argument tells {\LaTeX} to typeset the
% angle in the various mathematical styles, as exemplified in
% table~\ref{optional}.
%
% \begin{table}
% \caption{Results from the various choices of the optional argument
%   to \protect\cmdname{phase}}\label{optional}
% \medskip\centering\let\?\bigstrut
% \begin{tabular}{ll}
% \hline
% Command & Result\\
% \hline
% \?\verb|A\phase{\alpha}| & $\phase{\alpha}$ \\
% \?\verb|A\phase{30^{\circ}}| & $A\phase{30^{\circ}}$ \\
% \?\verb|A\phase[0]{\alpha}| & $A\phase[0]{\alpha}$ \\
% \?\verb|A\phase[1]{\alpha}| & $A\phase[1]{\alpha}$ \\
% \?\verb|A\phase[2]{\alpha}| & $A\phase[2]{\alpha}$ \\
% \?\verb|A\phase[3]{\alpha}| & $A\phase[3]{\alpha}$ \\
% \?\verb|A\phase[0]{\frac{\alpha}{2}}| &
% $A\phase[0]{\frac{\alpha}{2}}$ \\
% \?\verb|A\phase[1]{\frac{\alpha}{2}}| &
% $A\phase[1]{\frac{\alpha}{2}}$ \\
% \?\verb|A\phase[2]{\frac{\alpha}{2}}| &
% $A\phase[2]{\frac{\alpha}{2}}$ \\
% \?\verb|A\phase[3]{\frac{\alpha}{2}}| &
% $A\phase[3]{\frac{\alpha}{2}}$ \\
% \hline
% \end{tabular}
% \end{table}
%
% Recall that the command \cmdname{phase} should be given only in math
% mode. Since the command is usually written in display or text style,
% it should be uncommon to need the optional argument, unless you have
% to force a particular style for fractions.
%
% If you have more than one of these symbols in a row, it can help
% alignment to put \cmdname{mathstrut} in the argument.
%
% \section{Acknowledgments}
%
% The macro has been developed based on ideas of Stefano Di Gennaro
% (Universit\`a dell'Aquila, Italy) and his student Andrea
% Tonelli. Both have suffered from the earthquake of April~5, 2009: I
% wish them, their families and their university a prompt recover.
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% \section{Implementation}
% \iffalse
%<*package>
% \fi
%    \begin{macrocode}
\RequirePackage{pict2e}[2004/07/06]
%    \end{macrocode}
% \iffalse
%</package>
% \fi
% We need the extended slopes provided by \textsf{pict2e}.
%
% \begin{macro}{\stm@phasebox}
% \begin{macro}{\stm@phasedp}
% \begin{macro}{\stm@phaseht}
% \begin{macro}{\stm@phasetot}
% \begin{macro}{\stm@phasewd}
% We reserve some registers.
% \iffalse
%<*package>
% \fi
%    \begin{macrocode}
\newsavebox{\stm@phasebox}
\newlength{\stm@phasedp}
\newlength{\stm@phaseht}
\newlength{\stm@phasetot}
\newlength{\stm@phasewd}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\phase}
% This is the main (and unique) command provided at user level.
%    \begin{macrocode}
\newcommand\phase[2][1]{%
  \sbox\stm@phasebox{%
    $\ifcase#1\relax
      \displaystyle\or\textstyle\or\scriptstyle\or\scriptscriptstyle
     \fi#2$}
%    \end{macrocode}
% We set the box register to a formula containing the argument in the
% style chosen by the optional argument (default is text style).
%    \begin{macrocode}
  \stm@phaseht=\ht\stm@phasebox
  \stm@phasedp=\dp\stm@phasebox
  \stm@phasetot=\stm@phasedp \advance\stm@phasetot .35ex
    \advance\stm@phasetot\stm@phaseht
  \stm@phasewd=\wd\stm@phasebox
    \advance\stm@phasewd .5\stm@phasetot
%    \end{macrocode}
% We do some measuring; the name of the registers should be
% self-explaining.
%    \begin{macrocode}
  \setbox\stm@phasebox=\vbox to\stm@phaseht{
    \hbox{\setlength{\unitlength}{1pt}\linethickness{.6pt}%
    \edef\ph@x{\strip@pt\stm@phasewd}\edef\ph@y{\strip@pt\stm@phasetot}%
    \dimen@ .5\stm@phasetot \edef\ph@dx{\strip@pt\dimen@}%
%    \end{macrocode}
% In the reserved box register we put a vbox and set inside it the
% unit length for the picture environment to $1\,$pt; since we have to
% use pure numbers, we strip the unit from the lengths.
%    \begin{macrocode}
  \begin{picture}(\ph@x,\ph@y)
    \put(0,0){\circle*{.4}}
    \put(0,0){\line(1,0){\ph@x}}\put(0,0){\line(1,2){\ph@dx}}
    \put(\ph@dx,1.5){\raise\stm@phasedp\vbox{\box\stm@phasebox}}
  \end{picture}%
%    \end{macrocode}
% The picture environment draws the angle. In its vertex we put a
% small circle to masquerade the connections. Inside the angle we
% print the expression given as argument, freeing the box register so
% that it can be used again (by the macro itself).
%    \begin{macrocode}
  }\vss}%
  \advance\stm@phasedp .35ex \advance\stm@phasedp .6pt
  \dp\z@=\stm@phasedp \box\stm@phasebox}
%    \end{macrocode}
% \iffalse
%</package>
% \fi
% We close the vbox, correct its depth and print it.
% \end{macro}
%
%
% \section{An example}
% The following will generate an example file.
% \iffalse
%<*example>
% \fi
%    \begin{macrocode}
\documentclass[a4paper]{article}
\usepackage{steinmetz}

\begin{document} 

We will indicate the amplitude and phase relationship through the use
of complex notation: a complex number is used to indicate only the
amplitude and phase of voltages and currents in the circuit (since the
sinusoidal time variation factor is common to all terms).  For
example, a circuit described by the equation
\[
i(t)=I_{0}\cos(\omega t+\theta)
\]
can be written in complex exponential form as
\[
i(t)=\Re\{I_{0}e^{j(\omega t+\theta)}\}=
\Re\{I_{0}e^{j\theta}e^{j\omega t}\},
\]
and in polar complex form as
\[
i(t)=\Re\{I_{0}\phase{\theta}e^{j\omega t}\}.
\]
Finally, we can simplify the notation by dropping the implied
$e^{j\omega t}$ term and the $\Re\{~\}$ operator, leaving the phasor
notation:
\[
\mathbf{I}=I_{0}\phase{\theta}=I_{0}e^{j\theta}=
I_{0}(\cos\theta+j\sin\theta),
\]
where the boldface $\mathbf{I}$ reminds us that the phasor quantity
$\mathbf{I}$ is a complex number.  The important advantage of this
approach is that the mathematics involves mostly simple algebraic
operations on the magnitudes and phases.

It is interesting to look at the complex ratio of phasor voltage and
phasor current, $\mathbf{V}\!/\mathbf{I}$, which is called the
\emph{impedance}~$\mathbf{Z}$.  For the basic circuit elements we
find:
\begin{itemize}
\item Resistor, $R$: $\mathbf{Z}=R$,
\item Inductor, $L$: $\mathbf{Z}=j\omega L=
  \omega L\phase{90^{\circ}}$,
\item Capacitor, $C$: $\displaystyle\mathbf{Z}=\frac{1}{j\omega C}=
  -j\frac{1}{\omega C}=\frac{1}{\omega C}\phase{-90^{\circ}}$.
\end{itemize}
\end{document}
%    \end{macrocode}
% \iffalse
%</example>
% \fi
%
% \Finale
\endinput