2

I can draw the european style current source as in this example:

\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}[european]
 \draw (0,0) to[current source] (2,0);
\end{circuitikz}
\end{document}

enter image description here

I would like to redefine the current source in circuitikz following the book:

enter image description here

The double arrowhead indicates the direction of the current thus it can have two directions. I would like to invoke the symbol specifying mystyle. I would like to store my symbols in a separate file mysymbols.tex.

As a first step I try to create a shape named isourcex reusing the code for isource contained in pgfcircbipoles.tex

\documentclass[margin=1cm]{standalone}
\usepackage{circuitikz}
\makeatletter
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/isource/height}}
{isourcex}
{\ctikzvalof{bipoles/isource/height}}
{\ctikzvalof{bipoles/isource/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@down}}
    \pgf@circ@draworfill
}

\pgfcirc@activate@bipole@opt{i}{isourcex}{isourcex}{my current source}{%                                                                                                                                   
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@style@to@style{current source}{isourcex}

\makeatother
\begin{document}

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

\end{document}

It produces isourcex (red):

enter image description here

Now what is left is to change `isourcex.

Could you please help.

4
  • Please add a MWE to your question. Commented Jun 5, 2023 at 13:13
  • @samcarter_is_at_topanswers.xyz I can try to produce one but the question is above my technical level
    – Viesturs
    Commented Jun 5, 2023 at 13:21
  • You could easily add a circuit with a normal source so people wouldn't have to start from scratch. Commented Jun 5, 2023 at 13:23
  • 1
    This is basically the same question as tex.stackexchange.com/questions/686656/… (just a different symbol to draw, but it should be straightforward)
    – Rmano
    Commented Jun 5, 2023 at 13:27

1 Answer 1

5

Update

You have almost done it! A couple of tricks when designing components:

  1. the default position is from left to right, so put the component in that direction while doing the drawing;

  2. the linewidth of the wires is stored in \pgfstartlinewidth, and it's in force when starting the drawing;

  3. the reference dimensions of the component are marked by the upper-right corner \pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up} and the lower left \pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}; in this case (but not for every component) they are symmetric around \pgfpoint{0pt}{0pt}

  4. You go with \pgfpathmoveto{...}, \pgfpathlineto{...} and the other primitives you can find here, and then you stroke or fill the path (you need to do that every time you want to change the style of the line).

The rest of the changes are marked in the code:

\documentclass[margin=1cm]{standalone}
\usepackage{circuitikz}
\makeatletter
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/isource/height}}
{isourcex}
{\ctikzvalof{bipoles/isource/height}}
{\ctikzvalof{bipoles/isource/width}}
{
    % \draw the "across" line with the basic width
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
    % draw the circle
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    % fill if needed
    \pgf@circ@draworfill
    % it seems that your "arrows" should be  thicker. You can add
    % a parameter, but for now let do that the easy way
    \pgfsetlinewidth{1.5\pgflinewidth}
    % \draw the first "caret"
    \pgfpathmoveto{\pgfpoint{0.1\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.6\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{0.1\pgf@circ@res@right}{-0.5\pgf@circ@res@up}}
    % and the second one
    \pgfpathmoveto{\pgfpoint{-0.4\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.1\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{-0.4\pgf@circ@res@right}{-0.5\pgf@circ@res@up}}
    % stroke the path
    \pgfusepath{draw}
}

\pgfcirc@activate@bipole@opt{i}{isourcex}{isourcex}{my current source}{%
    \circuitikzbasekey/bipole/is current=true}
% This must be the name of the bipole declaration above...
\pgfcirc@style@to@style{my current source}{isourcex}

\makeatother
\begin{document}

\begin{circuitikz}
 \draw (0,0) to[isource] ++(2,0);
 \draw (3,0) to[isourcex] ++(2,0);
 \draw (6,0) to[isourcex, invert] ++(2,0);
\end{circuitikz}

\end{document}

enter image description here

original answer

To have a symbol like this completely integrated into the library, you can either:

  1. follow the instruction on the circuitikz manual, chapter 9, "Defining new components". It's not so difficult, but you need a basic knowledge of the basic layer of pgf.

  2. find a standard that uses this symbol and advocate for a feature request; notice that the package has a lot (probably even too many) symbols, so I'll add only well-supported ones.

I can offer a solution which is basically a self-plagiarism of this one, but you can do this:

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[siunitx, RPvoltages]{circuitikz}
\newcommand{\drawda}[2][0]{% draw a double arrow inside an empty source
    \begin{scope}[rotate=#1]
    \draw (#2.left) -- (#2.right);
    \draw [thick] (#2.center) ++(-2mm,0) -- ++(2mm,3mm) -- ++(2mm,-3mm);
    \draw [thick] (#2.center) ++(-2mm,-2mm) -- ++(2mm,3mm) -- ++(2mm,-3mm);
    \end{scope}
}
\begin{document}
\begin{tikzpicture}[american]
    \draw (0,0) to [esource, name=pulse1, l=$I_v$] ++(0,2)
        to[esource, name=pulse2, l=$I_h$] ++(2,0)
        to[esource, name=pulse3, l=$-I_h$] ++(2,0);
    \drawda{pulse1}
    \drawda[-90]{pulse2}
    \drawda[90]{pulse3}
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .