# How can I create new components in circuitikz in order to distinguish between sinusoidal sources?

So in circuitikz, there is no distinction between a sinusoidal votage source sV and a sinusoidal voltage current source sI. The same goes for controlled sinusoidal voltage sources csV and controlled sinusoidal current sources csI.
My textbook, Engineering circuit analysis by William Hayt 8th Ed. uses their own symbols in order to distinguish them so I would be really grateful if someone can help me draw these components on the images below.

    \documentclass[border=5mm]{standalone}
\usepackage{circuitikz}[american]

%======================================================================
%My goal is to merge the two components on each line and make them one!
%======================================================================
\begin{document}
\begin{tikzpicture}\draw
(0,0) to [sI] (0,2)
(1.5,0) to [american current source] (1.5, 2)
(0,-3) to [csI] (0,-1)
(1.5,-3) to [american controlled current source] (1.5,-1)
;\end{tikzpicture}
\end{document}


• I have no idea, but I know that there are several packages to draw circuits. I would start by checking their manuals here: ctan.org/topic/diagram-circ
– Fran
Nov 4, 2018 at 10:05
• My guess is that for example the custom sinusoidal current source can be drawn starting from sI and adding the arrow in the middle (the exact arrow seen on the normal american current source. But this is advanced stuff for me at this moment of time. Nov 4, 2018 at 10:13
• @Fran I just made an exhaustive look through the manual of all the packages found at the linked you shared but neither of the packages listed there has these sinusoidal current source symbols. Not circuit-macros, not lcircuit, not any other. Nov 4, 2018 at 10:29
• It would hep if you include a a minimal working example (MWE) with some related symbols (sinusoidal/controllled current source), so some tikz expert can use it to test quickly some approach to mix the symbols. If there are no luck, you could also consider request that symbol directly to authors of circuitikz or tikz-relay (the author of this package, about modify or make new shapes: " if you need help, please do not hesitate in contacting the author").
– Fran
Nov 4, 2018 at 13:10

## 2 Answers

Defined two custom components:

• sIx - sinusoidal independent current source
• csIx - sinusoidal dependent current source

so that it can be used like any bipole. Example:

\begin{circuitikz}
\draw (0,0) to[sIx] (0,2);
\draw (2,0) to[csIx] (2,2);
\end{circuitikz}


Result:

MWE

\documentclass[margin=1cm]{standalone}
\usepackage{circuitikz}

\makeatletter
\pgfcircdeclarebipole{} % independent sinusoidal current source
{\ctikzvalof{bipoles/isourcesin/height}}
{sIx}
{\ctikzvalof{bipoles/isourcesin/height}}
{\ctikzvalof{bipoles/isourcesin/width}}
{
\pgfpointorigin
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
\pgfusepath{draw}
\pgf@circ@res@up = .5\pgf@circ@res@up
\pgfscope
\pgftransformrotate{90}
\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@up}{0cm}}
\pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
\pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
\pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
\pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
\pgfusepath{draw}
\endpgfscope

\pgfpathmoveto{\pgfpoint{.7\pgf@circ@res@left}{\pgf@circ@res@zero}}
\pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{\pgf@circ@res@zero}}
\pgfusepath{draw}
\pgfscope
\pgftransformshift{\pgfpoint{.5\pgf@circ@res@right}{\pgf@circ@res@zero}}
\pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
\endpgfscope
}

\pgfcircdeclarebipole{} % dependent sinusoidal current source
{\ctikzvalof{bipoles/cvsourcesin/height}}
{csIx}
{\ctikzvalof{bipoles/cvsourcesin/height}}
{\ctikzvalof{bipoles/cvsourcesin/width}}
{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
\pgfusepath{draw}
\endpgfscope

\pgf@circ@res@up = .5\pgf@circ@res@up
\pgfscope
\pgftransformrotate{90}
\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@up}{0cm}}
\pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
\pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
\pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
\pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
\pgfusepath{draw}
\endpgfscope
\pgfpathmoveto{\pgfpoint{.7\pgf@circ@res@left}{\pgf@circ@res@zero}}
\pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{\pgf@circ@res@zero}}
\pgfusepath{draw}
\pgfscope
\pgftransformshift{\pgfpoint{.5\pgf@circ@res@right}{\pgf@circ@res@zero}}
\pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
\endpgfscope
}

\def\pgf@circ@sIx@path#1{\pgf@circ@bipole@path{sIx}{#1}}
\def\pgf@circ@csIx@path#1{\pgf@circ@bipole@path{csIx}{#1}}
\compattikzset{sIx/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@sIx@path, label=#1}}
\compattikzset{csIx/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@csIx@path, label=#1}}
\makeatother

\begin{document}
\begin{circuitikz}
\draw (0,0) to[sIx] (0,2);
\draw (2,0) to[csIx] (2,2);
\end{circuitikz}
\end{document}


Made by editing code from circuitkz.

How about the following?

\documentclass[border=5mm]{standalone}
\usepackage{circuitikz}[american]

% ======================================================================
% My goal is to merge the two components on each line and make them one!
% ======================================================================
\begin{document}
\begin{tikzpicture}
\draw (0,0) to [sI] (0,2)
(0,0) to [american current source] (0, 2)
(1.5,0) to [csI] (1.5,2)
(1.5,0) to [american controlled current source] (1.5,2);
\end{tikzpicture}
\end{document}


Update: An alternative to simplify input, as requested in the comments:

\documentclass[border=5mm]{standalone}
\usepackage{circuitikz}[american]

% ======================================================================
% My goal is to merge the two components on each line and make them one!
% ======================================================================

\newcommand{\mandresybillycsIarrow}[4]{
\draw (#1,#2) to [csI] (#3,#4)
(#1,#2) to [american controlled current source] (#3,#4);
}

\newcommand{\mandresybillysIarrow}[4]{
\draw (#1,#2) to [sI] (#3,#4)
(#1,#2) to [american current source] (#3,#4);
}

\begin{document}
\begin{circuitikz}
\mandresybillysIarrow{0}{0}{0}{2}
\mandresybillycsIarrow{1.5}{0}{1.5}{2}
\end{circuitikz}
\end{document}

• Yes, indeed! This is exactly the output I was talking about. Can you create custom new component for these two? I am no tikz expert. Nov 15, 2018 at 1:09
• @mandresybilly I don't get it. I understood you wanted this output. What do you mean by "custom new component"? Nov 15, 2018 at 1:12
• Ok so I mean for instance, can you create a new component, let's say: csIarrow which combines csI and american controlled current source? That way, it would be easer to type to only call one component instead of typing the csIand american controlled source` everytime. Nov 15, 2018 at 1:21
• @mandresybilly Mmh, I see. I wouldn't know how to do that. But what I did here is overlap two components with the same pair of coordinates, which is simple enough I think. Nov 15, 2018 at 1:26
• @mandresybilly It is not the same thing as creating a new component, but you can use macros to pack both of them together. See if the updated answer fits your bill. Nov 15, 2018 at 1:44