summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/sfg
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/sfg
Initial commit
Diffstat (limited to 'macros/latex/contrib/sfg')
-rw-r--r--macros/latex/contrib/sfg/Changes4
-rw-r--r--macros/latex/contrib/sfg/README7
-rw-r--r--macros/latex/contrib/sfg/sfg-doc.pdfbin0 -> 384147 bytes
-rw-r--r--macros/latex/contrib/sfg/sfg-doc.tex285
-rw-r--r--macros/latex/contrib/sfg/sfg.sty499
-rw-r--r--macros/latex/contrib/sfg/sfg_test.tex35
6 files changed, 830 insertions, 0 deletions
diff --git a/macros/latex/contrib/sfg/Changes b/macros/latex/contrib/sfg/Changes
new file mode 100644
index 0000000000..32dc83a528
--- /dev/null
+++ b/macros/latex/contrib/sfg/Changes
@@ -0,0 +1,4 @@
+0.91 2007-08-22 - add LPPL license
+ - change \scalebox to \psscalebox to prevent
+ a conflict with package graphicx (hv)
+0.90 1998-07-19 first CTAN version (hps)
diff --git a/macros/latex/contrib/sfg/README b/macros/latex/contrib/sfg/README
new file mode 100644
index 0000000000..6c395602a2
--- /dev/null
+++ b/macros/latex/contrib/sfg/README
@@ -0,0 +1,7 @@
+%@(#) sfg.sty: Signal flow graphs
+% This is the style file sfg.sty for drawing signal flow graphs in LaTeX2e.
+
+You'll find a short documentation at the end of the style file
+
+----
+hv 2007/08/22
diff --git a/macros/latex/contrib/sfg/sfg-doc.pdf b/macros/latex/contrib/sfg/sfg-doc.pdf
new file mode 100644
index 0000000000..58e72a7e8b
--- /dev/null
+++ b/macros/latex/contrib/sfg/sfg-doc.pdf
Binary files differ
diff --git a/macros/latex/contrib/sfg/sfg-doc.tex b/macros/latex/contrib/sfg/sfg-doc.tex
new file mode 100644
index 0000000000..e126cfa129
--- /dev/null
+++ b/macros/latex/contrib/sfg/sfg-doc.tex
@@ -0,0 +1,285 @@
+\documentclass[pagesize=auto, parskip=half]{scrartcl}
+
+\usepackage{fixltx2e}
+\usepackage{etex}
+\usepackage{lmodern}
+\usepackage[T1]{fontenc}
+\usepackage{textcomp}
+\usepackage{amstext}
+\usepackage[utf8]{inputenc}
+\usepackage[svgnames]{xcolor}
+\usepackage{listings}
+\usepackage{microtype}
+\usepackage{hyperref}
+
+\newcommand*{\mail}[1]{\href{mailto:#1}{\texttt{#1}}}
+\newcommand*{\pkg}[1]{\textsf{#1}}
+\newcommand*{\cs}[1]{\texttt{\textbackslash#1}}
+\makeatletter
+\newcommand*{\cmd}[1]{\cs{\expandafter\@gobble\string#1}}
+\makeatother
+\newcommand*{\meta}[1]{\text{\textlangle\textsl{#1}\textrangle}}
+\newcommand*{\marg}[1]{\texttt{\{}\meta{#1}\texttt{\}}}
+
+\addtokomafont{title}{\rmfamily}
+
+\lstset{%
+ language=[LaTeX]TeX,%
+ columns=flexible,%
+ upquote=true,%
+ numbers=left,%
+ basicstyle=\ttfamily,%
+ keywordstyle=\color{Navy},%
+ commentstyle=\color{DimGray},%
+ stringstyle=\color{SeaGreen},%
+ numberstyle=\scriptsize\color{SlateGray}%
+}
+
+\title{The \pkg{sfg} package\thanks{This manual corresponds to \pkg{sfg}~v0.91, dated~22.\,08.\,2007.}}
+\author{Hanspeter Schmid\thanks{\mail{schmid@isi.ee.ethz.ch}, \url{http://www.isi.ee.ethz.ch/\~schmid/}}\and Herbert Voß}
+\date{22.\,08.\,2007}
+
+
+\begin{document}
+
+\maketitle
+
+
+\section{Documentation}
+
+This style file defines some commands to draw signal flow graphs using
+\LaTeXe\@. Signal flow graphs (\textsc{sfg}) are used by electrical and
+electronics engineers and graph theorists. If you haven't heard of
+\textsc{sfg}s before, then \pkg{sfg.sty} is probably not useful for you.
+
+If you really want to know what a signal flow graph is, you might read
+one of the references given below.
+
+The package sfg requires the packages `\pkg{pstricks}' and `\pkg{fp}'. It
+therefore requires \LaTeXe\ and a reasonably fast machine.
+
+To draw a signal flow graph, you should proceed as follows:
+%
+\begin{enumerate}
+\item Insert \verb|\usepackage{pstricks,sfg}| in your \LaTeXe-file.
+\item Draw your \textsc{sfg} on graph paper\footnote{I mean the paper with a 4\,mm, 5\,mm or 1/8\,in grid on it\dots} and determine the size of the
+ picture in units (squares).
+\item Set the unitlength using \cmd{\sfgsetunit}.
+\item Set the arrowlength, node radius and label offsets using \cmd{\sfgsetsize}.
+\item In a \LaTeX\ picture environment of the size you determined above,
+ \begin{itemize}
+ \item first draw all paths using \cmd{\sfgbranch} and \cmd{\sfgcurve},
+ \item then draw all nodes using \cmd{\sfgnode} and \cmd{\sfgtermnode}.
+ \end{itemize}
+\end{enumerate}
+
+
+\section{Setting the Controlling Parameters}
+
+\begin{description}
+\item[\cmd{\sfgsetunit}\marg{length}]
+ sets \cmd{\unitlength} and the PS unit to \meta{length}, and
+ defines the default \pkg{pstricks} linewidth as 0.4\,pt. This has an
+ influence on \emph{all} ps-tricks commands that are used afterwards.
+
+\item[\cmd{\sfgsetsize}\marg{nr}\marg{al}\marg{no}\marg{ao}]
+ sets the node radius to \meta{nr} units, the
+ arrow\-length to \meta{al} units, the offset of the nodes' labels to
+ \meta{no} units and the offset of the arrows' labels to \meta{ao} units.
+ All four parameters are numbers.
+
+\item[\cmd{\sfgsetangle}\marg{an}]
+ sets the incidence angle of sfgcurves \meta{an} degrees.
+ Default value: 60 degrees.
+
+\item[\cmd{\sfgsetarrowloc}\marg{mid}]
+ sets the location of the sfgbranch's arrow. 0.5
+ means in the middle, 0.1 means 10\,\% of the branch length from
+ the first node.
+ Default value: 0.5
+
+\item[\cmd{\sfgsetlines}\marg{li\_len}\marg{lii}\marg{liii}]
+ sets the line thickness \cmd{\sfg@Li} (used
+ for all lines) to \meta{li\_len}, the thickness \cmd{\sfg@Lii} (used for
+ terminal nodes) to $\meta{lii} \times \meta{li\_len}$, and the thickness \cmd{\sfg@Liii}
+ to $\meta{liii} \times \meta{li\_len}$. It also resets the default pstricks
+ linewidth to the new \cmd{\sfg@Li}.
+
+ Default values:
+ \begin{tabular}[t]{l@{~=~}l}
+ \cmd{\sfg@Li} & 0.40\,pt \\
+ \cmd{\sfg@Lii} & $1.80 \times \cmd{\sfg@Li}$ \\
+ \cmd{\sfg@Liii} & $3 \times \cmd{\sfg@Li}$ \\
+ \end{tabular}
+\end{description}
+
+
+\section{Drawing signal flow graph (SFG) branches}
+
+\begin{description}
+\item[\cmd{\sfgbranch}\marg{dx}\marg{dy}\marg{pos}\marg{text}]
+ draws a straight \textsc{sfg} branch from $(0,0)$
+ to $(\meta{dx},\meta{dy})$. An arrow is placed in the middle of the branch,
+ and a label \meta{text} is typeset near the arrow. The parameter
+ \meta{pos} is explained below (see \cmd{\sfgnode}).
+
+ The distance of the label from the arrow's centre as well as
+ the arrow's length can be set using \cmd{\sfgsetsize}.
+
+ The location of the arrow can be changed using
+ \cmd{\sfgsetarrowloc}.
+
+\item[\cmd{\sfgcurve}\marg{dx}\marg{dy}\marg{off}\marg{pos}\marg{text}]
+ draws a curved \textsc{sfg} path from $(0,0)$
+ to $(\meta{dx},\meta{dy})$. The arrow's position is \meta{off} units left of the
+ middle of the path (\meta{off} can be negative to put the arrow
+ right of the path). The curve leaves the endpoints in an angle
+ of 60~degrees (this value can be changed using \cmd{\sfgsetangle})
+ if possible. If the arrow is too far away from the straight
+ path, the angle is increased to guarantee a ``nice'' curve,
+ and a warning message is issued.
+\end{description}
+
+
+\section{Drawing Nodes}
+
+\begin{description}
+\item[\cmd{\sfgnode}\marg{pos}\marg{text}]
+ draws a node with label \meta{text}. \meta{pos} decides
+ where the label is typeset. It is a number between~0 and~7.
+ After the command
+%
+\begin{verbatim}
+\sfgsetcompass
+\end{verbatim}
+%
+ eight macros named after compass directions can be used.
+
+ \begin{tabular}{rcl}
+ 3 & 2 & 1 \\
+ 4 & . & 0 \\
+ 5 & 6 & 7
+ \end{tabular}
+ %
+ \quad or\quad
+ %
+ \begin{tabular}{rcl}
+ \cmd{\NW} & \cmd{\N} & \cmd{\NE} \\
+ \cmd{\W} & . & \cmd{\E} \\
+ \cmd{\SW} & \cmd{\S} & \cmd{\SE}
+ \end{tabular}
+
+ The distance of the label from the node's centre as well as the
+ node's radius can be set using \cmd{\sfgsetsize}.
+
+\item[\cmd{\sfgtermnode}\marg{pos}\marg{text}]
+ draws a terminal node (black circle filled white).
+\end{description}
+
+
+\section{Example:}
+
+\begin{lstlisting}
+\documentclass[11pt,a4paper]{article}
+\usepackage{pstricks,sfg}
+\pagestyle{empty}
+\setlength{\parindent}{0pt}
+
+\begin{document}
+\sfgsetunit{0.5cm}
+\sfgsetsize{0.12}{0.4}{0.5}{0.3}
+\sfgsetcompass
+\begin{picture}(27,4)
+ % branches related to node 2
+ \put(6,2){\sfgbranch{3}{0}\S{$\frac{1}{R_1}$}}
+ \put(9,2){\sfgbranch{3}{0}\N{\boldmath $Z_2$}}
+ \put(18,2){\sfgcurve{-9}{0}{2}\S{$\frac{1}{R_2}$}}
+ \put(24,2){\sfgcurve{-15}{0}{-2}\N{$sC_1$}}
+ % branches related to node 3
+ \put(12,2){\sfgbranch{3}{0}\N{$\frac{1}{R_2}$}}
+ \put(15,2){\sfgbranch{3}{0}\N{\boldmath $Z_3$}}
+ % input, voltage gain, output
+ \put(0,2){\sfgcurve{6}{0}{2}\N{$1$}}
+ \put(18,2){\sfgcurve{6}{0}{-2}\S{$\alpha_{\mathrm{V}}$}}
+ \put(24,2){\sfgbranch{3}{0}\S{$1$}}
+ % nodes
+ \put(0,2){\sfgtermnode\S{$V_{\mathrm{in}}$}}
+ \put(3,2){\sfgnode\S{$I_1$}}
+ \put(6,2){\sfgnode\S{$V_1$}}
+ \put(9,2){\sfgnode\S{$I_2$}}
+ \put(12,2){\sfgnode\S{$V_2$}}
+ \put(15,2){\sfgnode\S{$I_3$}}
+ \put(18,2){\sfgnode\S{$V_3$}}
+ \put(21,2){\sfgnode\S{$I_4$}}
+ \put(24,2){\sfgnode\S{$V_4$}}
+ \put(27,2){\sfgtermnode\S{$V_{\mathrm{out}}$}}
+\end{picture}
+\end{document}
+\end{lstlisting}
+
+
+\section{References}
+
+\setlength{\leftmargini}{1em}
+\addtokomafont{descriptionlabel}{\normalfont}
+
+\begin{description}
+\item[{[Chen, 1995, Chapters 7, 8 and 18]}]\leavevmode\\
+ Wai-Kai Chen. The Circuits and Filters Handbook. CRC Press,
+ Inc.,\ 1995.
+\end{description}
+%
+or have a look at the original papers by Samuel Mason:
+%
+\begin{description}
+\item[{[119]}]\leavevmode\\
+ Samuel J. Mason. Feedback theory --- some properties of signal
+ flow graphs. Proceedings of the Institute of Radio Engineers,
+ 41(9):1144--1156, September 1953.
+
+\item[{[120]}]\leavevmode\\
+ Samuel J. Mason. Feedback theory --- further properties of
+ signal flow graphs. Proceedings of the Institute of Radio
+ Engineers, 44(7):920--926, July 1956.
+\end{description}
+
+\end{document}
+
+
+
+%@(#) sfg.sty: Signal flow graphs
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% This is the style file sfg.sty for drawing signal flow graphs in LaTeX2e.
+%
+% Version 0.9, 1.7.1998, Hanspeter Schmid
+% Version 0.91, 22.08.2007 hv scalebox->\psscalebox
+%
+% If you find an error, or if you want me to implement some more
+% functions, want me to include more references to books on sfgs,
+% or if you just want to say `hello thank you, I find you package
+% useful', please don't hesitate and contact me:
+%
+% Hanspeter Schmid, schmid@isi.ee.ethz.ch,
+% http://www.isi.ee.ethz.ch/~schmid/
+%
+%% This program can be redistributed and/or modified under the terms
+%% of the LaTeX Project Public License Distributed from CTAN
+%% archives in directory macros/latex/base/lppl.txt.
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% History: (Version numbers are going towards 3/pi.
+% sfg.sty is not good enough yet to be called v1.0)
+%
+% created: 26.1.96, hps, (v0)
+% modified for submission to CTAN: 1.7.98, hps, (v0.9)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Plans: - make a proper dtx-file out of this mess. I'll do this if
+% and when I find the time to do it.
+% - include an sfg branch which has snake form, e.g. \sfgsnake
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% SEE DESCRIPTION AFTER THE \endinput
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+
+
diff --git a/macros/latex/contrib/sfg/sfg.sty b/macros/latex/contrib/sfg/sfg.sty
new file mode 100644
index 0000000000..8398b2c6c3
--- /dev/null
+++ b/macros/latex/contrib/sfg/sfg.sty
@@ -0,0 +1,499 @@
+%@(#) sfg.sty: Signal flow graphs
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% This is the style file sfg.sty for drawing signal flow graphs in LaTeX2e.
+%
+% Version 0.9, 1.7.1998, Hanspeter Schmid
+% Version 0.91, 22.08.2007 hv scalebox->\psscalebox
+%
+% If you find an error, or if you want me to implement some more
+% functions, want me to include more references to books on sfgs,
+% or if you just want to say `hello thank you, I find you package
+% useful', please don't hesitate and contact me:
+%
+% Hanspeter Schmid, schmid@isi.ee.ethz.ch,
+% http://www.isi.ee.ethz.ch/~schmid/
+%
+%% This program can be redistributed and/or modified under the terms
+%% of the LaTeX Project Public License Distributed from CTAN
+%% archives in directory macros/latex/base/lppl.txt.
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% History: (Version numbers are going towards 3/pi.
+% sfg.sty is not good enough yet to be called v1.0)
+%
+% created: 26.1.96, hps, (v0)
+% modified for submission to CTAN: 1.7.98, hps, (v0.9)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Plans: - make a proper dtx-file out of this mess. I'll do this if
+% and when I find the time to do it.
+% - include an sfg branch which has snake form, e.g. \sfgsnake
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% SEE DESCRIPTION AFTER THE \endinput
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\NeedsTeXFormat{LaTeX2e}
+\RequirePackage[nomessages]{fp}
+\RequirePackage{pstricks}
+\ProvidesPackage{sfg}[2007/08/22]
+\typeout{Style sfg, by Hanspeter Schmid, version 0.91}%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Line thicknesses:
+\newdimen\sfg@Li \sfg@Li=0.40pt % normal lines (LaTeX `thin')
+\newdimen\sfg@Lii \sfg@Lii=1.80\sfg@Li % thick lines (`thick') (hacked)
+\newdimen\sfg@Liii \sfg@Liii=3\sfg@Li % thickness of heavy lines
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% internal functions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\def\sfg@degtorad{0.01745329252}% conversion factor deg -> rad
+\def\sfg@radtodeg{57.2957795132}% conversion factor rad -> deg
+
+\def\sfg@curvescale{0.577350269}% standard sfgcurve angle, cot(60 deg)
+
+\def\sfg@arrowloc{0.5} % standard location of the arrow is in
+ % the middle of an sfg branch
+
+ % calculate the angle of vector (#1,#2)
+ % in degrees, given that #1
+ % is positive, ...
+ % ... and finally add #3.
+\def\sfg@angleadd#1#2#3{{% % formula: arcsin(#3/sqrt(#1^2+#2^2))
+ \FPmul\sfg@xx{#1}{#1}\FPmul\sfg@yy{#2}{#2}%
+ \FPadd\sfg@rr\sfg@xx\sfg@yy\FProot\sfg@len\sfg@rr{2}%
+ % calculate length of vector
+ \FPdiv\sfg@sin{#2}\sfg@len\FParcsin\sfg@result\sfg@sin% angle
+ \FPmul\sfg@resultb\sfg@result\sfg@radtodeg%
+ \FPadd\sfg@result\sfg@resultb{#3}%
+ \FPtrunc\sfg@angle\sfg@result{2}\global\let\sfg@angle\sfg@angle}}%
+
+ % ... and finally subtract from #3.
+\def\sfg@anglesub#1#2#3{{%
+ \FPmul\sfg@xx{#1}{#1}\FPmul\sfg@yy{#2}{#2}%
+ \FPadd\sfg@rr\sfg@xx\sfg@yy\FProot\sfg@len\sfg@rr{2}%
+ % calculate length of vector
+ \FPdiv\sfg@sin{#2}\sfg@len\FParcsin\sfg@result\sfg@sin% angle
+ \FPmul\sfg@resultb\sfg@result\sfg@radtodeg%
+ \FPsub\sfg@result{#3}\sfg@resultb%
+ \FPtrunc\sfg@angle\sfg@result{2}\global\let\sfg@angle\sfg@angle}}%
+
+
+\def\sfg@arrow#1{% % rotateable bezier-curve based arrow
+ \begin{picture}(0,0){% % zero-dimensional
+ \rput{#1}(0,0){% % rotate counter-clockwise by #1 degrees
+ \psscalebox{\sfg@arrowlen}{% scale by factor \sfg@arrowlen
+ \pscustom*[linetype=1,linewidth=\sfg@Li]{% draw arrow
+ \psbezier(0.5,0)(0.15,-0.0825)(-0.075,-0.1625)(-0.5,-0.375)%
+ \psline(-0.5,0.375)%
+ \psbezier(-0.075,0.1625)(0.15,0.0825)(0.5,0)}}}}%
+ \end{picture}}%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% functions to configure the signal flow graphs
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % set the package's numerical parameters
+
+\def\sfgsetunit#1{% % unitlength
+ \setlength{\unitlength}{#1}%
+ \psset{unit=#1, linewidth=\sfg@Li}}%
+
+\def\sfgsetangle#1{% % incidence angle of sfgcurves
+ {\FPmul\sfg@tmp\sfg@degtorad{#1}%
+ \FPcot\sfg@curvescale\sfg@tmp%
+ \global\let\sfg@curvescale\sfg@curvescale}}%
+
+\def\sfgsetarrowloc#1{% % location of the arrow on sfgbranches
+ \def\sfg@arrowloc{#1}}%
+
+\def\sfgsetsize#1#2#3#4{% % size of arrows and nodes ...
+ \gdef\sfg@noderad{#1}\gdef\sfg@arrowlen{#2}%
+ \gdef\sfg@nlabel{#3}\gdef\sfg@alabel{#4}%
+ % label distances for \NW, \NE, \SW, \SE
+ \FPmul\sfg@nlabeld{#3}{0.707106781188}% multiply with 1/sqrt(2)
+ \global\let\sfg@nlabeld\sfg@nlabeld%
+ \FPmul\sfg@alabeld{#3}{0.707106781188}%
+ \global\let\sfg@alabeld\sfg@alabeld%
+ }%
+
+\def\sfgsetlines#1#2#3{% % line thicknesses
+ \sfg@Li=#1\sfg@Lii=#2\sfg@Li\sfg@Liii=#3\sfg@Li%
+ \psset{linewidth=\sfg@Li}}
+
+\def\sfgsetcompass{% % define macros for label placement
+ \gdef\E{0}\gdef\NE{1}\gdef\N{2}\gdef\NW{3}%
+ \gdef\W{4}\gdef\SW{5}\gdef\S{6}\gdef\SE{7}}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% drawing signal flow graphs
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\def\sfgtermnode#1#2{% % terminal node (white with black line}
+ \begin{picture}(0,0){% % zero-size pictures make life easier
+ \put(0,0){%
+ % circle, radius \sfg@noderad
+ \pscircle*[linecolor=white,dimen=outer](0,0){\sfg@noderad}%
+ \pscircle[linewidth=\sfg@Lii](0,0){\sfg@noderad}}%
+ % label placement
+ \ifcase#1 % E (east)
+ % text #2 in a distance of \sfg@nlabel
+ \put(\sfg@nlabel,0){\makebox(0,0)[l]{#2}}%
+ \or % NE (north-east)
+ \put(\sfg@nlabeld,\sfg@nlabeld){\makebox(0,0)[bl]{#2}}%
+ \or % N (...)
+ \put(0,\sfg@nlabel){\makebox(0,0)[b]{#2}}%
+ \or % NW (\sfg@tmp := -\sfg@nlabel)
+ \FPneg\sfg@tmp{\sfg@nlabeld}%
+ \put(\sfg@tmp,\sfg@nlabeld){\makebox(0,0)[br]{#2}}%
+ \or % W
+ \FPneg\sfg@tmp{\sfg@nlabel}%
+ \put(\sfg@tmp,0){\makebox(0,0)[r]{#2}}%
+ \or % SW
+ \FPneg\sfg@tmp{\sfg@nlabeld}%
+ \put(\sfg@tmp,\sfg@tmp){\makebox(0,0)[tr]{#2}}%
+ \or % S
+ \FPneg\sfg@tmp{\sfg@nlabel}%
+ \put(0,\sfg@tmp){\makebox(0,0)[t]{#2}}%
+ \or % SE
+ \FPneg\sfg@tmp{\sfg@nlabeld}%
+ \put(\sfg@nlabeld,\sfg@tmp){\makebox(0,0)[tl]{#2}}%
+ \else % no label
+ \PackageWarning{sfg}%
+ {sfgtermnode: label placement option #1 unknown}%
+ \fi%
+ }\end{picture}}%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\def\sfgnode#1#2{% % normal node (just black)
+ \begin{picture}(0,0){%
+ \put(0,0){%
+ \pscircle*[linewidth=0pt](0,0){\sfg@noderad}}% filled circle
+ % label placement, comments -> sfgtermnode
+ \ifcase#1 \put(\sfg@nlabel,0){\makebox(0,0)[l]{#2}}%
+ \or\put(\sfg@nlabeld,\sfg@nlabeld){\makebox(0,0)[bl]{#2}}%
+ \or\put(0,\sfg@nlabel){\makebox(0,0)[b]{#2}}%
+ \or\FPneg\sfg@tmp{\sfg@nlabeld}%
+ \put(\sfg@tmp,\sfg@nlabeld){\makebox(0,0)[br]{#2}}%
+ \or\FPneg\sfg@tmp{\sfg@nlabel}%
+ \put(\sfg@tmp,0){\makebox(0,0)[r]{#2}}%
+ \or\FPneg\sfg@tmp{\sfg@nlabeld}%
+ \put(\sfg@tmp,\sfg@tmp){\makebox(0,0)[tr]{#2}}%
+ \or\FPneg\sfg@tmp{\sfg@nlabel}%
+ \put(0,\sfg@tmp){\makebox(0,0)[t]{#2}}%
+ \or\FPneg\sfg@tmp{\sfg@nlabeld}%
+ \put(\sfg@nlabeld,\sfg@tmp){\makebox(0,0)[tl]{#2}}%
+ \else\PackageWarning{sfg}%
+ {sfgnode: label placement option #1 unknown}%
+ \fi%
+ }\end{picture}}%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\def\sfgbranch#1#2#3#4{% % straight sfg branch
+ \begin{picture}(0,0){%
+ % determine in which quadrant the vector's
+ % end point (x,y) lies (x=#1, y=#2)
+ \FPset\sfg@flag{0}% % use a bit-flag
+ \FPifzero{#1}\FPadd\sfg@flag\sfg@flag{1}\fi% % x=0 -> bit 0
+ \FPifneg{#1}\FPadd\sfg@flag\sfg@flag{2}\fi% % x<0 -> bit 1
+ \FPifzero{#2}\FPadd\sfg@flag\sfg@flag{4}\fi% % y=0 -> bit 2
+ \FPifneg{#2}\FPadd\sfg@flag\sfg@flag{8}\fi% % y<0 -> bit 3
+ % case-distinction: correct the main values
+ % of arcsin
+ % #2#1
+ % -0-0
+ \ifcase\sfg@flag % 0000 first quadrant
+ \sfg@angleadd{#1}{#2}{0}%
+ \or % 0001 positive y-axis
+ \FPset\sfg@angle{90}%
+ \or % 0010 second quadrant
+ \sfg@anglesub{#1}{#2}{180}%
+ \or % 0011 impossible
+ \or % 0100 positive x-axis
+ \FPset\sfg@angle{0}%
+ \or % 0101 zero vector
+ \FPset\sfg@angle{0}%
+ \PackageWarning{sfg}{sfgbranch: zero-length branch drawn.}%
+ \or % 0110 negative x-axis
+ \FPset\sfg@angle{180}%
+ \or % 0111 impossible
+ \or % 1000 third quadrant
+ \sfg@angleadd{#1}{#2}{0}%
+ \or % 1001 negative y-axis
+ \FPset\sfg@angle{-90}%
+ \or % 1010 fourth quadrant
+ \sfg@anglesub{#1}{#2}{180}%
+ \else % every other bit pattern is impossible.
+ \fi % % now draw the line
+ \put(0,0){\psline[linewidth=\sfg@Li,arrows=C-C](0,0)(#1,#2)}%
+ % calculate centre of arrow and label
+ \FPmul\sfg@dx{#1}\sfg@arrowloc\FPmul\sfg@dy{#2}\sfg@arrowloc%
+ \put(\sfg@dx,\sfg@dy){% % place arrow and label
+ \sfg@arrow{\sfg@angle}%
+ % label placement (see sfgtermnode)
+ \ifcase#3\put(\sfg@alabel,0){\makebox(0,0)[l]{#4}}%
+ \or\put(\sfg@alabeld,\sfg@alabeld){\makebox(0,0)[bl]{#4}}%
+ \or\put(0,\sfg@alabel){\makebox(0,0)[b]{#4}}%
+ \or\FPneg\sfg@tmp{\sfg@alabeld}%
+ \put(\sfg@tmp,\sfg@alabeld){\makebox(0,0)[br]{#4}}%
+ \or\FPneg\sfg@tmp{\sfg@alabel}%
+ \put(\sfg@tmp,0){\makebox(0,0)[r]{#4}}%
+ \or\FPneg\sfg@tmp{\sfg@alabeld}%
+ \put(\sfg@tmp,\sfg@tmp){\makebox(0,0)[tr]{#4}}%
+ \or\FPneg\sfg@tmp{\sfg@alabel}%
+ \put(0,\sfg@tmp){\makebox(0,0)[t]{#4}}%
+ \or\FPneg\sfg@tmp{\sfg@alabeld}%
+ \put(\sfg@alabeld,\sfg@tmp){\makebox(0,0)[tl]{#4}}%
+ \else\PackageWarning{sfg}%
+ {sfgbranch: label placement option #3 unknown}%
+ \fi %
+ } %
+ }\end{picture}}%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\def\sfgcurve#1#2#3#4#5{% % curved sfg branch
+ \begin{picture}(0,0){% % qadrant ... (see sfgbranch)
+ \FPset\sfg@flag{0}%
+ \FPifzero{#1}\FPadd\sfg@flag\sfg@flag{1}\fi%
+ \FPifneg{#1}\FPadd\sfg@flag\sfg@flag{2}\fi%
+ \FPifzero{#2}\FPadd\sfg@flag\sfg@flag{4}\fi%
+ \FPifneg{#2}\FPadd\sfg@flag\sfg@flag{8}\fi%
+ \ifcase\sfg@flag\sfg@angleadd{#1}{#2}{0}%
+ \or\FPset\sfg@angle{90}%
+ \or\sfg@anglesub{#1}{#2}{180}%
+ \or\or\FPset\sfg@angle{0}%
+ \or\FPset\sfg@angle{0}%
+ \or\FPset\sfg@angle{180}%
+ \or\or\sfg@angleadd{#1}{#2}{0}%
+ \or\FPset\sfg@angle{-90}%
+ \or\sfg@anglesub{#1}{#2}{180}%
+ \else\fi %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ {% % calculate path shift and new
+ % arrow location:
+ % mid: vector to the straight
+ % path's arrow midpoint
+ \FPmul\sfg@midx{#1}{0.5}\FPmul\sfg@midy{#2}{0.5}%
+ % p: rotate mid 90 degrees counterclockwise
+ \FPneg\sfg@px\sfg@midy\FPset\sfg@py\sfg@midx%
+ % len: length of p (and therefore mid)
+ \FPmul\sfg@xx\sfg@px\sfg@px\FPmul\sfg@yy\sfg@py\sfg@py%
+ \FPadd\sfg@rr\sfg@xx\sfg@yy\FProot\sfg@len\sfg@rr{2}%
+ % scale: #3/len
+ \FPdiv\sfg@scale{#3}\sfg@len%
+ % a: p scaled to the absolute length #3
+ \FPmul\sfg@ax\sfg@px\sfg@scale\FPmul\sfg@ay\sfg@py\sfg@scale%
+ % d: mid+a; vector to the arrow centre
+ \FPadd\sfg@dx\sfg@ax\sfg@midx\FPadd\sfg@dy\sfg@ay\sfg@midy%
+ % export this value
+ \global\let\sfg@dx\sfg@dx\global\let\sfg@dy\sfg@dy% exported
+ % now calculate the four additional
+ % bezier points. Two of them are at the
+ % intersections of the tangents and
+ % the line parallel to mid through
+ % the point (dx,dy).
+ % Their distance from arrow centre:
+ % dist = len-(|#3|*cot(alpha))
+ \FPabs\sfg@three{#3}\FPmul\sfg@tmp{\sfg@three}\sfg@curvescale%
+ \FPsub\sfg@dist\sfg@len\sfg@tmp%
+ % now compare this to 2*arrowlength,
+ % which is the minimum allowed value if
+ % sfg paths shouldn't look crippled
+ \FPmul\sfg@limit\sfg@arrowlen{2}%
+ \FPiflt\sfg@dist\sfg@limit%
+ \PackageWarning{sfg}%
+ {sfgcurve: incidence angle has been made steeper}%
+l \FPset\sfg@dist\sfg@limit%
+ \fi%
+ % calculate the new scalefactor:
+ \FPdiv\sfg@scale\sfg@dist\sfg@len%
+ % a: mid scaled to length dist
+ \FPmul\sfg@ax\sfg@midx\sfg@scale\FPmul\sfg@ay\sfg@midy\sfg@scale%
+ % d.b = mid+a
+ \FPadd\sfg@dxb\sfg@ax\sfg@dx\FPadd\sfg@dyb\sfg@ay\sfg@dy%
+ % d.a = mid-a
+ \FPsub\sfg@dxa\sfg@dx\sfg@ax\FPsub\sfg@dya\sfg@dy\sfg@ay%
+ % Two more bezier points lie in between
+ % these points and the curves end points
+ % .i = (d.a)/2
+ \FPdiv\sfg@xi\sfg@dxa{2}\FPdiv\sfg@yi\sfg@dya{2}%
+ % .iv = (d.b + (#1,#2) )/2
+ \FPadd\sfg@tmpx\sfg@dxb{#1}\FPadd\sfg@tmpy\sfg@dyb{#2}%
+ \FPdiv\sfg@xiv\sfg@tmpx{2}\FPdiv\sfg@yiv\sfg@tmpy{2}%
+ % and now draw the path with bezier lines
+ \put(0,0){\psbezier[linewidth=\sfg@Li]{-}%
+ (0,0)(\sfg@xi,\sfg@yi)(\sfg@dxa,\sfg@dya)(\sfg@dx,\sfg@dy)}%
+ \put(0,0){\psbezier[linewidth=\sfg@Li]{-}%
+ (#1,#2)(\sfg@xiv,\sfg@yiv)(\sfg@dxb,\sfg@dyb)(\sfg@dx,\sfg@dy)}%
+ }%
+ \put(\sfg@dx,\sfg@dy){%
+ \sfg@arrow{\sfg@angle}%
+ % label placement (see sfgtermnode)
+ \ifcase#4\put(\sfg@alabel,0){\makebox(0,0)[l]{#5}}%
+ \or\put(\sfg@alabeld,\sfg@alabeld){\makebox(0,0)[bl]{#5}}%
+ \or\put(0,\sfg@alabel){\makebox(0,0)[b]{#5}}%
+ \or\FPneg\sfg@tmp{\sfg@alabeld}%
+ \put(\sfg@tmp,\sfg@alabeld){\makebox(0,0)[br]{#5}}%
+ \or\FPneg\sfg@tmp{\sfg@alabel}%
+ \put(\sfg@tmp,0){\makebox(0,0)[r]{#5}}%
+ \or\FPneg\sfg@tmp{\sfg@alabeld}%
+ \put(\sfg@tmp,\sfg@tmp){\makebox(0,0)[tr]{#5}}%
+ \or\FPneg\sfg@tmp{\sfg@alabel}%
+ \put(0,\sfg@tmp){\makebox(0,0)[t]{#5}}%
+ \or\FPneg\sfg@tmp{\sfg@alabeld}%
+ \put(\sfg@alabeld,\sfg@tmp){\makebox(0,0)[tl]{#5}}%
+ \else\PackageWarning{sfg}%
+ {sfgcurve: label placement option #4 unknown}%
+ \fi %
+ }}\end{picture}}%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\endinput % That's it. I Hope you have a fast computer.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+Documentation
+~~~~~~~~~~~~~
+This style file defines some commands to draw signal flow graphs using
+LaTeX2e. Signal flow graphs (sfg) are used by electrical and
+electronics engineers and graph theorists. If you haven't heard of
+sfgs before, then sfg.sty is probably not useful for you.
+
+If you really want to know what a signal flow graph is, you might read
+one of the references given below.
+
+The package sfg requires the packages `pstricks' and `fp'. It
+therefore requires LaTeX2e and a reasonably fast machine.
+
+To draw a signal flow graph, you should proceed as follows:
+
+1. Insert \usepackage{pstricks,sfg} in your LaTeX2e-file.
+2. Draw your sfg on graph paper (*) and determine the size of the
+ picture in units (squares).
+ (*) I mean the paper with a 4mm, 5mm or 1/8in grid on it ...
+3. Set the unitlength using \sfgsetunit.
+4. Set the arrowlength, node radius and label offsets using \sfgsetsize.
+5. In a LaTeX picture environment of the size you determined above,
+ - first draw all paths using \sfgbranch and \sfgcurve,
+ - then draw all nodes using \sfgnode and \sfgtermnode.
+
+
+Setting the Controlling Parameters
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+\sfgsetunit{length} sets \unitlength and the PS unit to `length', and
+ defines the default pstricks linewidth as 0.4pt. This has an
+ influence on ALL ps-tricks commands that are used afterwards.
+
+\sfgsetsize{nr}{al}{no}{ao} sets the node radius to `nr' units, the
+ arrowlength to `al' units, the offset of the nodes' labels to
+ `no' units and the offset of the arrows' labels to `ao' units.
+ All four parameters are numbers.
+
+\sfgsetangle{an} sets the incidence angle of sfgcurves `an' degrees.
+ Default value: 60 degrees.
+
+\sfgsetarrowloc{mid} sets the location of the sfgbranch's arrow. 0.5
+ means in the middle, 0.1 means 10% of the branch length from
+ the first node.
+ Default value: 0.5
+
+\sfgsetlines{li_len}{lii}{liii} sets the line thickness \sfg@Li (used
+ for all lines) to `li_len', the thickness \sfg@Lii (used for
+ terminal nodes) to `lii'*`li_len', and the thickness \sfg@Liii
+ to `liii'*`li_len'. It also resets the default pstricks
+ linewidth to the new \sfg@Li.
+
+ Default values: \sfg@Li=0.40pt
+ \sfg@Lii=1.80\sfg@Li
+ \sfg@Liii=3\sfg@Li
+
+
+Drawing signal flow graph (sfg) branches
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+\sfgbranch{dx}{dy}{pos}{text} draws a straight sfg branch from (0,0)
+ to (dx,dy). An arrow is placed in the middle of the branch,
+ and a label `text' is typeset near the arrow. The parameter
+ `pos' is explained below (see \sfgnode).
+
+ The distance of the label from the arrow's centre as well as
+ the arrow's length can be set using \sfgsetsize.
+
+ The location of the arrow can be changed using
+ \sfgsetarrowloc.
+
+\sfgcurve{dx}{dy}{off}{pos}{text} draws a curved sfg path from (0,0)
+ to (dx,dy). The arrow's position is `off' units left of the
+ middle of the path (`off' can be negative to put the arrow
+ right of the path). The curve leaves the endpoints in an angle
+ of 60 degrees (this value can be changed using \sfgsetangle)
+ if possible. If the arrow is too far away from the straight
+ path, the angle is increased to guarantee a ``nice'' curve,
+ and a warning message is issued.
+
+
+Drawing Nodes
+~~~~~~~~~~~~~
+\sfgnode{pos}{text} draws a node with label `text'. `pos' decides
+ where the label is typeset. It is a number between 0 and 7.
+ After the command
+
+ \sfgsetcompass
+
+ eight macros named after compass directions can be used.
+
+
+ 3 2 1 \NW \N \NE
+
+ 4 . 0 or \W . \E
+
+ 5 6 7 \SW \S \SE
+
+ The distance of the label from the node's centre as well as the
+ node's radius can be set using \sfgsetsize.
+
+\sfgtermnode{pos}{text} draws a terminal node (black circle filled white).
+
+
+Example:
+~~~~~~~~
+\documentclass[11pt,a4paper]{article}
+\usepackage{pstricks,sfg}
+\pagestyle{empty}
+\setlength{\parindent}{0pt}
+
+\begin{document}
+\sfgsetunit{0.5cm}
+\sfgsetsize{0.12}{0.4}{0.5}{0.3}
+\sfgsetcompass
+\begin{picture}(27,4)
+ % branches related to node 2
+ \put(6,2){\sfgbranch{3}{0}\S{$\frac{1}{R_1}$}}
+ \put(9,2){\sfgbranch{3}{0}\N{\boldmath $Z_2$}}
+ \put(18,2){\sfgcurve{-9}{0}{2}\S{$\frac{1}{R_2}$}}
+ \put(24,2){\sfgcurve{-15}{0}{-2}\N{$sC_1$}}
+ % branches related to node 3
+ \put(12,2){\sfgbranch{3}{0}\N{$\frac{1}{R_2}$}}
+ \put(15,2){\sfgbranch{3}{0}\N{\boldmath $Z_3$}}
+ % input, voltage gain, output
+ \put(0,2){\sfgcurve{6}{0}{2}\N{$1$}}
+ \put(18,2){\sfgcurve{6}{0}{-2}\S{$\alpha_{\mathrm{V}}$}}
+ \put(24,2){\sfgbranch{3}{0}\S{$1$}}
+ % nodes
+ \put(0,2){\sfgtermnode\S{$V_{\mathrm{in}}$}}
+ \put(3,2){\sfgnode\S{$I_1$}}
+ \put(6,2){\sfgnode\S{$V_1$}}
+ \put(9,2){\sfgnode\S{$I_2$}}
+ \put(12,2){\sfgnode\S{$V_2$}}
+ \put(15,2){\sfgnode\S{$I_3$}}
+ \put(18,2){\sfgnode\S{$V_3$}}
+ \put(21,2){\sfgnode\S{$I_4$}}
+ \put(24,2){\sfgnode\S{$V_4$}}
+ \put(27,2){\sfgtermnode\S{$V_{\mathrm{out}}$}}
+\end{picture}
+\end{document}
+
+
+References
+~~~~~~~~~~
+ [Chen, 1995, Chapters 7, 8 and 18]
+ Wai-Kai Chen. The Circuits and Filters Handbook. CRC Press,
+ Inc., 1995.
+
+or have a look at the original papers by Samuel Mason:
+
+ [119]
+ Samuel J. Mason. Feedback theory --- some properties of signal
+ flow graphs. Proceedings of the Institute of Radio Engineers,
+ 41(9):1144-1156, September 1953.
+ [120]
+ Samuel J. Mason. Feedback theory --- further properties of
+ signal flow graphs. Proceedings of the Institute of Radio
+ Engineers, 44(7):920-926, July 1956.
diff --git a/macros/latex/contrib/sfg/sfg_test.tex b/macros/latex/contrib/sfg/sfg_test.tex
new file mode 100644
index 0000000000..f9a1cc2f3d
--- /dev/null
+++ b/macros/latex/contrib/sfg/sfg_test.tex
@@ -0,0 +1,35 @@
+\documentclass[11pt,a4paper]{article}
+\usepackage{graphics,pstricks,sfg}
+\pagestyle{empty}
+\setlength{\parindent}{0pt}
+
+\begin{document}
+\sfgsetunit{0.5cm}
+\sfgsetsize{0.12}{0.4}{0.5}{0.3}
+\sfgsetcompass
+\begin{picture}(27,4)
+ % branches related to node 2
+ \put(6,2){\sfgbranch{3}{0}\S{$\frac{1}{R_1}$}}
+ \put(9,2){\sfgbranch{3}{0}\N{\boldmath $Z_2$}}
+ \put(18,2){\sfgcurve{-9}{0}{2}\S{$\frac{1}{R_2}$}}
+ \put(24,2){\sfgcurve{-15}{0}{-2}\N{$sC_1$}}
+ % branches related to node 3
+ \put(12,2){\sfgbranch{3}{0}\N{$\frac{1}{R_2}$}}
+ \put(15,2){\sfgbranch{3}{0}\N{\boldmath $Z_3$}}
+ % input, voltage gain, output
+ \put(0,2){\sfgcurve{6}{0}{2}\N{$1$}}
+ \put(18,2){\sfgcurve{6}{0}{-2}\S{$\alpha_{\mathrm{V}}$}}
+ \put(24,2){\sfgbranch{3}{0}\S{$1$}}
+ % nodes
+ \put(0,2){\sfgtermnode\S{$V_{\mathrm{in}}$}}
+ \put(3,2){\sfgnode\S{$I_1$}}
+ \put(6,2){\sfgnode\S{$V_1$}}
+ \put(9,2){\sfgnode\S{$I_2$}}
+ \put(12,2){\sfgnode\S{$V_2$}}
+ \put(15,2){\sfgnode\S{$I_3$}}
+ \put(18,2){\sfgnode\S{$V_3$}}
+ \put(21,2){\sfgnode\S{$I_4$}}
+ \put(24,2){\sfgnode\S{$V_4$}}
+ \put(27,2){\sfgtermnode\S{$V_{\mathrm{out}}$}}
+\end{picture}
+\end{document}