3

I have created my custom electric component named myIC using the circuitikz.sty library. myIC has three pins labeled PinA, PinB, PinC and a default label myIClabel. I defined this component within the pgfdeclareshape environment, allowing me to easily incorporate it into a circuitikz environment.

Question: How can I change the default label text myIClabel during the instantiation of myIC? See the output screenshot below

CODE:

\documentclass[border=0cm]{standalone}

\usepackage{circuitikz}

\pgfdeclareshape{myIC}{

% define saved anchor
% ----------------------------------------
  \anchor{center}{\pgfpointorigin}

% define Connectors relative to the center
% ----------------------------------------
  % Pin A:
  \savedanchor\myICpinA{\pgfpoint{-30}{10}}
  \anchor{PinA}{\myICpinA}
  % Pin B:
  \savedanchor\myICpinB{\pgfpoint{-30}{-10}}
  \anchor{PinB}{\myICpinB}
  % Pin C:
  \savedanchor\myICpinC{\pgfpoint{30}{0}}
  \anchor{PinC}{\myICpinC}

\foregroundpath{

    \pgfpathrectanglecorners{\pgfpoint{-30}{-30}}{\pgfpoint{30}{30}}
    \pgfusepath{draw}

    \pgftext[left,  at={\myICpinA}]{PinA}
    \pgftext[left,  at={\myICpinB}]{PinB}
    \pgftext[right, at={\myICpinC}]{PinC}

    % my static label
    \pgftext[center, at={\pgfpoint{0}{35}}]{\small\textcolor{black}{myIClabel}}

    }

}

\begin{document} \begin{circuitikz} % Instance of the custom component in red \draw (0,0) node[myIC, red] (myIC1) {}; % Another instance in green \draw (3,0) node[myIC, green] (myIC2) {}; % Yet another instance in blue \draw (6,0) node[myIC, blue] (myIC3) {}; \end{circuitikz} \end{document}

OUTPUT:

enter image description here

  • Hi Marco, what do you mean with "assigning labels"? To name a node you just do something like node [myIC](labelA){}. And again, this has no relation with circuitikz. Question: why don't you use a distributed circuitikz instead of the git version? And why not using circuititz provided chip or muxdemux components? – Rmano Oct 12 '23 at 18:55
  • Or do you want to add text at the top of the box? In that case, you need to define a text anchor and then say node[myIC]{a label} – Rmano Oct 12 '23 at 21:14
  • See https://tex.stackexchange.com/questions/372993/is-it-possible-to-implement-multiple-input-logic-ports-with-circuitikz/372996?r=SearchResults&s=3%7C33.7654#372996 which uses \anchor{text}{\pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}} – John Kormylo Oct 12 '23 at 21:25
  • @Rmano, thank you once more for your comment. When I create an instance of the myIC component inside the circuitikz environment, I want to label this node. For instance, I'd like to do this: \draw (0,0) node[myIC, red, myLabel=testLabel1] {};. Feel free to provide some code using only circuitikz instead using the git version :)? Best regards – Marco Moldenhauer Oct 13 '23 at 00:05
  • @Rmano: Just a quick update, I've switched from the circuitikzgit package to the circuitikz package since it gives me the same result. I edited my question. Thanks for your suggestion! – Marco Moldenhauer Oct 13 '23 at 00:16
  • @Rmano: Note that I clarified my question because I believe it was not well-written. Now, the question should be clearly defined. – Marco Moldenhauer Oct 13 '23 at 02:20
  • Do you just want the label to be typeset or do you want to refer to the shape later by name? I'm assuming the former, but then you mention wanting to name the node. But this can't you do that already? – cfr Oct 13 '23 at 03:16
  • @cfr: thanks for your support. The current situation is that when I create an instance of myIC, the default label myIClabel appears. So far, so good. However, some instances should have a different label other than myIClabel. – Marco Moldenhauer Oct 13 '23 at 03:40
  • @MarcoMoldenhauer I posted an answer which does what you want, as I understand it. If that's not it, I don't understand the question. I addressed both interpretations which seemed plausible, but focused on the labelling rather than naming. So ... – cfr Oct 13 '23 at 03:48
  • @cfr: I saw your answer, and it's exactly what I was looking for. The only thing is that there is no default value anymore, correct? – Marco Moldenhauer Oct 13 '23 at 03:51
  • @MarcoMoldenhauer .initial sets the default. Try it. – cfr Oct 13 '23 at 03:54
  • @MarcoMoldenhauer Or see edit. – cfr Oct 13 '23 at 04:00
  • @MarcoMoldenhauer I added (for the next version) features to muxdemux that should address all your needs. I have been thinking about it for a long time, but your question prompted me to tackle it... so thanks! https://github.com/circuitikz/circuitikz/pull/746 – Rmano Oct 18 '23 at 09:55

1 Answers1

2

I'm not sure if you're asking about labelling or naming, as you use both terms somewhere in your question/comments, and these are rather different things.

If you want the label's content to be configurable, you can just define a key using pgfkeys and use the value in place of the fixed text.

shapes with customised labels

shapes with customised and default labels

\documentclass[border=10pt]{standalone}

\usepackage{circuitikz} \usetikzlibrary{ext.paths.ortho}

\pgfdeclareshape{myIC}{ % define saved anchor \anchor{center}{\pgfpointorigin} % Pins \savedanchor\myICpinA{\pgfpoint{-30}{10}} \anchor{PinA}{\myICpinA} \savedanchor\myICpinB{\pgfpoint{-30}{-10}} \anchor{PinB}{\myICpinB} \savedanchor\myICpinC{\pgfpoint{30}{0}} \anchor{PinC}{\myICpinC} \foregroundpath{ \pgfpathrectanglecorners{\pgfpoint{-30}{-30}}{\pgfpoint{30}{30}} \pgfusepath{draw} \pgftext[left, at={\myICpinA}]{PinA} \pgftext[left, at={\myICpinB}]{PinB} \pgftext[right, at={\myICpinC}]{PinC} % my static label \pgftext[center, at={\pgfpoint{0}{35}}]{\small\textcolor{black}{\pgfkeysvalueof{/mm/myLabel}}} } } \pgfqkeys{/mm}{myLabel/.initial=myIClabel}

\begin{document} \begin{circuitikz} % Instance of the custom component in red \draw (0,0) node[myIC, red, /mm/myLabel=coch] (myIC1) {}; % Another instance in green \draw (3,0) node[myIC, green, /mm/myLabel=gwyrdd] (myIC2) {}; % Yet another instance in blue \draw (6,0) node[myIC, blue, /mm/myLabel=glas] (myIC3) {}; \end{circuitikz} \begin{circuitikz} % Instance of the custom component in red \draw (0,0) node[myIC, red, /mm/myLabel=coch] (myIC1) {}; % Another instance in green \draw (3,0) node[myIC, green, /mm/myLabel=gwyrdd] (myIC2) {}; % Yet another instance in blue \draw (6,0) node[myIC, blue, /mm/myLabel=glas] (myIC3) {}; \draw (myIC1.PinC) -|- (myIC2.PinA); \draw (9,0) node[myIC, magenta] (myIC4) {}; \end{circuitikz} \end{document}

If you want the ability to name the nodes in the PGF/TikZ sense, you already have that and are already using it. However, your shape obviously has non-standard anchors, so you can use the nodes later, but only with the anchors they actually have.

cfr
  • 198,882
  • thanks for your reply: what means /mm/myLabel? Is that a path? Best regards – Marco Moldenhauer Oct 13 '23 at 03:48
  • @MarcoMoldenhauer Yes. It's good practice to use a distinct path for custom keys. If you use /pgf/myLabel or /tikz/myLabel the chances of conflicts are obviously much higher. – cfr Oct 13 '23 at 03:59
  • 1
    ah ok :) mm stands for Marco Moldenhauer. thanks a lot – Marco Moldenhauer Oct 13 '23 at 04:00
  • @MarcoMoldenhauer Oh, yes. Sorry, I forgot to mention that. Your whole user name was too much typing ;). – cfr Oct 13 '23 at 04:02
  • by the way what is the difference 'naming' or 'labeling' a node? – Marco Moldenhauer Oct 13 '23 at 04:21
  • 2
    @MarcoMoldenhauer The names of the nodes in my example are myIC1, myIC2, myIC3 etc. The labels are separate nodes with text content coch, gwyrdd etc. The name isn't (typically) typeset. It just lets you refer to the node e.g. when you join their pins, you're using their names. The label is nothing really to do with the main node. It's just a convenience to define it at the same time, but it's a separate node. The label doesn't have a name (at least, not generally). – cfr Oct 13 '23 at 04:26
  • @cfr shouldn't the anchors like \anchor{PinA}{\myICpinaA} ... etc. ? As it is, it does not compile for me... – Rmano Oct 13 '23 at 18:50
  • 2
    @Rmano Yes, it should. I copy-pasted the second picture from my other answer about this and forgot that part of the definition had changed, too. Thanks. – cfr Oct 13 '23 at 19:24