# How to affect label position in DEFINITION of CircuiTikZ component

I need to represent diodes using an obscure symbol that CircuiTikZ does not provide. I have managed to hack together the following.

\makeatletter

\pgfcircdeclarebipole{}
{\ctikzvalof{bipoles/diode/height}}
{fauxled}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope
\pgftransformxshift{\pgf@circ@res@left}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
\pgfusepath{draw}
\endpgfscope
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
\pgfpathcircle{\pgfpointorigin}{1.7*\pgf@circ@res@right}
\pgfusepath{draw}
}

\def\pgf@circ@fauxled@path#1{\pgf@circ@bipole@path{fauxled}{#1}}
\compattikzset{faux led/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@fauxled@path}}

\makeatother


This does the job (of creating a new CircuiTikZ component faux led) to a first-order approximation, however, if a label is attached to the component with \draw (0,0) to [faux led, label=LED] (4,0); the label is a bit closer to the symbol than would be ideal.

How can I change the definition of the component, so that the label is placed further away from the symbol by default?

I don't have the opportunity to use TikZ very often, and have never done any low-level stuff or drawn anything with the primitives before, so general comments on how to do a better job of writing components such as the above, would be most welcome.

Edit: Where can I find documentation for pgfcircdeclarebipole? I'm clearly misunderstanding something about the meaning of its first few arguments.

• You don't have to hack the symbols to get the label more distant, but the code of the labels. See Set label name on two lines in CircuiTikZ for a proof of concept. May 17, 2018 at 10:48
• @ClaudioFiandrino Are you suggesting that I create another kind of label? I would simply like the client to use the same labels that are available in all components, and have the label appear at a reasonable distance from the symbol. The current problem seems to be that I am not correctly specifying the size of my component.
– jacg
May 18, 2018 at 7:11

## 1 Answer

Here is a solution I have come up with. I'm not proud of it, but it works. (I would hope that a cleaner approach exists.) The trick I used is

• Shrink the drawing of the symbol with \pgftransformscale. This moves the edges of the symbol away from the label, but also has the undesirable effect of leaving a gap between the inner part of the symbol (the triangle and vertical line which represent the diode) and the circuit lines coming in.
• Fill in the gaps in these lines by drawing lines inside the symbol.

The code:

\makeatletter

\ctikzset{bipoles/faux led/height/.initial=\ctikzvalof{bipoles/diode/height}}
\ctikzset{bipoles/faux led/width/.initial=\ctikzvalof{bipoles/diode/width}}

\pgfcircdeclarebipole{}
{\ctikzvalof{bipoles/faux led/height}}
{fauxled}
{\ctikzvalof{bipoles/faux led/height}}
{\ctikzvalof{bipoles/faux led/width}}
{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope
\pgftransformscale{0.8}
\pgfscope
% triangle
\pgftransformxshift{\pgf@circ@res@left}
% right tip
\pgfpathmoveto{\pgfpoint {\pgf@circ@res@right-\pgf@circ@res@left}  {0pt}}
% top left
\pgfpathlineto{\pgfpoint {0pt}                      {\pgf@circ@res@up  }}
% bottom left
\pgfpathlineto{\pgfpoint {0pt}                      {\pgf@circ@res@down}}
% close path to the right tip
\pgfpathlineto{\pgfpoint {\pgf@circ@res@right-\pgf@circ@res@left}  {0pt}}
\endpgfscope
% vertical line
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
% circle
\pgfpathcircle{\pgfpointorigin}{1.9\pgf@circ@res@right}
\pgfusepath{draw}
% complete gaps in circuit wires
\pgfsetlinewidth{.8\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfpathmoveto{\pgfpoint {   \pgf@circ@res@right} {0pt}}
\pgfpathlineto{\pgfpoint {1.3\pgf@circ@res@right} {0pt}}
\pgfpathmoveto{\pgfpoint {   \pgf@circ@res@left } {0pt}}
\pgfpathlineto{\pgfpoint {1.3\pgf@circ@res@left } {0pt}}
\pgfusepath{draw}
\endpgfscope
}

\def\pgf@circ@fauxled@path#1{\pgf@circ@bipole@path{fauxled}{#1}}
\compattikzset{faux led/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@fauxled@path, label=#1}}

\makeatother


So it seems that both the label, and the ends of the incoming circuit lines are positioned according to the size of the symbol. Shrinking the symbol fixes the problem with the label, but causes a new problem with the lines.

Suggestions for a better solution most welcome.