4

I want to use the SCR symbol in a circuit drawn with TikZ library circuit. I'm able to write a tikzpicture similar to the image below but I don't know how to draw a TikZ circuit symbol (with anchors and so on).

Is there any manual that has guidelines to follow in creating symbols or at least indicating the minimum requirements it should have? I haven't found too much on the pgfmanual.

Note that I don't want a solution involving CircuiTikZ. The library circuit of TikZ is based on CircuiTikZ but the two of them are pretty much incompatibles and cannot be used (without some efforts) in the same document.

Here some picture of an SCR symbol, but I think that the best solution is to use the diode symbol (that is already present in the circuit tikzlibrary):

SCR

Edit: Looking at the comments I think that my exposition of the problem was the best possible. Sorry for that, I'll try to explain better in the following lines.

First of all, I'm looking for a symbol in the circuit TikZ sense. This means that I'm not looking for a simple tikz image but for something that I could use in a tikzpicture like

\documentclass[tikz]{standalone}
\usetikzlibrary{circuits.ee.IEC}
\begin{document}
\begin{tikzpicture}[circuit ee IEC]
\draw(0,1)to [diode] (2,1)to[inductor] (4,1);
\draw(0,2)to [thyristor] (2,2)to[inductor] (4,2);
\end{tikzpicture}
\end{document}

Note that in the image are displayed two diode, not a diode and a thyristor.

example

I also need to have the right anchors. This is an example of the zener diode anchors.

\documentclass[tikz]{standalone}
\usetikzlibrary{circuits.ee.IEC}
\tikzset{shape example/.style= {  
  color=black!30,
  draw,
  fill=yellow!30,
  line width=.5cm,
  inner xsep=2.5cm,
  inner ysep=0.5cm}
}
\begin{document}
\begin{tikzpicture}
\node[
  name=s,
  shape=breakdown diode IEC,
  shape example,
  minimum width=6cm,
  minimum height=4cm] {};
\foreach\anchor/\placement in {
  center/above,
  30/above right,
  north/above, 
  south/below, 
  east/left, 
  west/right,
  north east/above, 
  south east/below, 
  south west/below, 
  north west/above,
  input/left,
  output/right}
\draw [shift=(s.\anchor)] 
  plot [mark=x] coordinates{(0,0)} 
  node [\placement] {\scriptsize\texttt{(s.\anchor)}};
\end{tikzpicture}
\end{document}

zener

In my case, obv the shape should be different from a diode and a zener, but it should also have another anchor: instead of s.input I should have s.input1 and s.input2. Even if it would better to have the three anchors named s.anode,s.cathode and s.gate.

Any answer that cover this requirements is appreciated but if you could also give me some reference, like where did you find the definition of these symbols or what are the preferred steps in defining a new circuit symbol will be appreciated (in this way I don't need to ask again an help for each new circuit symbol).

2
  • Yeah, I should have been more clear: I don't know where the symbol is defined.
    – gvgramazio
    Commented May 5, 2018 at 18:06
  • I like to use a search engine (Find in File... with TeXnicCenter) over all the sty files stored admin, which in my case is C:\Program files\MiKTeX 2.9/tex. Actually, circuitikz tends to distribute the definition over more than one file. I have a tutorial on creating your own components on my web site elfsoft2000.com/projects/index.htm Commented May 5, 2018 at 18:37

2 Answers 2

7

OK, I learned a very nice trick from Torbjørn T.: pics that behave like nodes. Most likely I am reinventing something, but anyway here comes a thyristor pic whose elements you can access from outside, but you can also reference the whole thing.

\documentclass[tikz,border=3.14mm]{standalone}
\makeatletter % https://tex.stackexchange.com/a/241737/121799
\tikzset{pics/named scope code/.style={code={\tikz@fig@mustbenamed%
  \begin{scope}[local bounding box/.expanded=\tikz@fig@name]#1\end{scope}%
}}}
\makeatother
\tikzset{pics/.cd,
  pic thyristor/.style={named scope code={
  \begin{scope}[line join=round,font=\sffamily,line width=1.5pt]
    \draw (0,0) coordinate(-Anode) node[above]{Anode}-- ++(1.5,0) 
    -- ++(0,0.5) -- ++ (0.5,-0.5) coordinate(tip) 
    -- ++(-0.5,-0.5) -- ++(0,0.5);
    \draw (tip) -- ++ (0,0.5) -- ++ (0,-1) coordinate[pos=0.75] (branch);
    \draw (tip) -- ++ (1.5,0) coordinate(-Cathode) node[above]{Cathode};
    \draw (branch) -- ++(0.25,-0.25) -- ++ (0,-0.25) coordinate(-Gate)
    node[below]{Gate};
   \end{scope}
  }}
}
\begin{document}
\begin{tikzpicture}
\pic (thyr1) at (0,0) {pic thyristor};
\draw[blue,latex-latex] (thyr1-Anode) to[out=-90,in=180] (thyr1-Gate);
\pic (thyr2) at (7,0) {pic thyristor};
\draw[ultra thick,red,-latex] (thyr1) -- (thyr2);
\end{tikzpicture}
\end{document}

enter image description here

I added illustrations of how you may use it.

ADDENDUM: I went a little bit along the path outlined and paved by @percusse, and also shamelessly stole from his code. So here is what I have at the moment. In do not think it is particularly pretty but may potentially serve as a starting point. What I did is to look up the definitions in pgflibraryshapes.gates.ee.IEC.code.tex and slightly modified them. But I confess that I do not really know what I am doing, so there is certainly a lot of room for improvement.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\makeatletter
\pgfdeclareshape{thyristor}
{ \inheritsavedanchors[from=rectangle ee]
  \inheritanchor[from=rectangle ee]{center}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}
  \inheritanchorborder[from=rectangle ee]

  \savedanchor\gatepoint{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgf@x=4.8\pgf@xa%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
    \pgf@y=-3.2\pgf@ya%
    \advance\pgf@y by-.5\pgf@yb%
  }
  \anchor{gate}{\gatepoint}

  \backgroundpath{
    \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgf@xc=.5\pgf@xa \advance\pgf@xc by.5\pgf@xb
    \pgf@yc=.5\pgf@ya
    \advance\pgf@yc by .5\pgf@yb
    % Triangle:
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathclose
  }


  \beforebackgroundpath{
    {
      \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
      \pgf@xa=\pgf@x \pgf@ya=\pgf@y
      \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
      \pgf@xb=\pgf@x \pgf@yb=\pgf@y
      \pgf@yc=.5\pgf@ya
      \advance\pgf@yc by.5\pgf@yb
      \pgfpathmoveto{\pgfpointorigin} %
      \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yc}}
      \pgfusepathqstroke
      \pgf@xc=.5\pgf@xa
      \advance\pgf@xc by.5\pgf@xb
      \pgftransformshift{\pgfqpoint{\pgf@xc}{\pgf@yc}}  
      \pgf@yc=.5\pgf@yb
      \advance\pgf@yc by-.5\pgf@ya
      \pgftransformscale{\pgf@sys@tonumber{\pgf@yc}} 
      % the following is from @percusses answer
      \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}%
      \pgfpathlineto{\pgfqpoint{0pt}{-1pt}}%
      \pgfpathlineto{\pgfqpoint{0pt}{1pt}}%
      \pgfpathmoveto{\pgfpoint{0pt}{-0.5pt}}%
      \pgfpathlineto{\pgfpoint{0.6pt}{-0.9pt}}%
      \pgfpathlineto{\pgfpoint{0.6pt}{-1.4pt}}%      
      \pgfusepathqstroke%     
    }
  }
}
\pgfkeys{
  /pgf/thyristor/before background/.initial=,
}

\makeatother
\tikzset{
  thyristor IEC graphic/.style={circuit symbol size=width 3 height 2,
    shape=thyristor,
    transform shape,draw
    }}
\tikzset{
  circuit declare symbol = thyristor
    }
\tikzset{
  circuit ee IEC/.append style=
  {set thyristor graphic              = thyristor IEC graphic}}

\begin{document}
\begin{tikzpicture}[circuit ee IEC]
\draw(0,1)to [diode] (2,1)to[inductor] (4,1);
\draw(0,2)to [thyristor] (2,2)to[inductor] (4,2);
\end{tikzpicture}
\tikzset{shape example/.style= {  
  color=black!30,
  draw,
  fill=yellow!30,
  line width=.5cm,
  inner xsep=2.5cm,
  inner ysep=0.5cm}
}
\begin{tikzpicture}
\node[
  name=s,
  shape=thyristor,
  shape example,
  minimum width=6cm,
  minimum height=4cm] {};
\foreach\anchor/\placement in {gate/below,
  center/above,
  30/above right,
  north/above, 
  south/below, 
  east/left, 
  west/right,
  north east/above, 
  south east/below, 
  south west/below, 
  north west/above,
  input/left,
  output/right}
\draw [shift=(s.\anchor)] 
  plot [mark=x] coordinates{(0,0)} 
  node [\placement] {\scriptsize\texttt{(s.\anchor)}};
\end{tikzpicture}
\end{document}

enter image description here

UPDATE: After digging through some of the libraries, I believe to understand things slightly better now. Notice that I did not adjust the border to also go around the gate.

5
  • I appreciate your answer but the main problem is that it's not usable like other circuit symbols.
    – gvgramazio
    Commented May 5, 2018 at 22:51
  • @giusva If you explain in your question how you want to use it (in an MWE), I may perhaps be able to adjust it.
    – user121799
    Commented May 6, 2018 at 2:34
  • I edited the question. I hope that now are more clear what I'm looking for. The answer from @percusse is a good starting point but I don't understand how to choose the values that it gives to \pgfpoint. Should I go by trial and error or there is a way to see how the diode graphic is defined?
    – gvgramazio
    Commented May 6, 2018 at 11:01
  • @giusva I updated my answer to include something that might go into the direction of what you want to achieve.
    – user121799
    Commented May 6, 2018 at 18:53
  • 1
    I'm very sorry to not have accepted your answer before. You did a very good job and I was sure to have already accepted it. Today, when I was scrolling my questions, I realize that I forgot to accept your answer.
    – gvgramazio
    Commented Nov 25, 2018 at 11:59
6

I don't really use this library but here is a definition based on the existing Zener diode shape. I made up the distances so bettercheck the standards. And the gate anchor is missing.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\tikzset{
  thrystor IEC graphic/.style={
    diode IEC graphic,
    /pgf/generic diode IEC/before background={
      \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}%
      \pgfpathlineto{\pgfqpoint{0pt}{-1pt}}%
      \pgfpathlineto{\pgfqpoint{0pt}{1pt}}%
      \pgfpathmoveto{\pgfpoint{0pt}{-0.5pt}}%
      \pgfpathlineto{\pgfpoint{0.6pt}{-0.9pt}}%
      \pgfpathlineto{\pgfpoint{0.6pt}{-1.4pt}}%
      \pgfusepathqstroke%
    },
  },
  var thrystor IEC graphic/.style={
    diode IEC graphic,
    circuit symbol filled
  }
}
\tikzset{circuit declare symbol = thrystor,
         circuit ee IEC/.append style={set thrystor graphic = thrystor IEC graphic}
}
\begin{document}
\begin{tikzpicture}[circuit ee IEC]
\draw(0,0) to[thrystor] (2,2);
\draw(0,0) to[thrystor] (2,-2);
\end{tikzpicture}
\end{document}

I hope you can make something out of this.

enter image description here

7
  • apparently I also got the name wrong.
    – percusse
    Commented May 5, 2018 at 19:27
  • surely it's a good starting point.
    – gvgramazio
    Commented May 5, 2018 at 22:50
  • I was able to draw a decent shape modifying your code but I don't understand two things. The first one is how I choose the values of \pgfpoints: should I go by trial and error? There is a way to look for the definition of the diode graphic? The second one is how to add a new anchor and how to redefine old ones.
    – gvgramazio
    Commented May 6, 2018 at 11:04
  • 1
    @giusva You can't define the anchors with this method. You have to define a new shape other than generic diode shape. The relevant part is in the manual see the last sentence
    – percusse
    Commented May 6, 2018 at 11:18
  • 1
    Similarly to the generic circle IEC shape, when a node of shape generic diode IEC is created, the current setting of this key is used as the “before background path.” When the hcodei is executed, the coordinate system will have been transformed in such a way that the origin is at the “tip” of the diode’s triangle, the point (0pt,1pt) is exactly half the diode’s height above this origin, and the point (1pt,0pt) is half the diode’s height to the right of the origin. The idea is that you use this key to draw different kinds of diode endings
    – percusse
    Commented May 6, 2018 at 11:18

You must log in to answer this question.

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