1

I think my question is quite similar to this and this, however I didn't manage to modify the provided solutions to fit my problem.

In the following MWE I am trying to define 8 pin anchors in a \foreach loop. What I am doing is obviously wrong, as I am getting an "Undefined control sequence" error when I try to reference one of this pins.

Can someone provide a minimal example for a defining anchors in a loop?

\documentclass[tikz,border=1cm]{standalone}

\usepackage{circuitikz}

% BEGIN myic definition
\def\w{3cm}
\def\h{4.5cm}

\pgfdeclareshape{myic}{
    \anchor{center}{\pgfpointorigin}
    \anchor{text}
    {\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}

    % PIN ANCHORS
    % The following code does not work as expected.
    % I am looking for a way to define \n anchors in a loop.
    \foreach \n in {0,...,7}
        {\anchor{in\n}{\pgfpoint{.5*\w}{7*.25cm-\n*.5cm}}}

    \foregroundpath{
        % RECTANGLE
        \pgfsetlinewidth{0.025cm}
        \pgfpathrectanglecorners{\pgfpoint{.5*\w}{.5*\h}}{\pgfpoint{-.5*\w}{-.5*\h}}
        \pgfusepath{draw}

        % PIN NAMES
        \foreach \n in {0,...,7}
            {\pgftext[right,at={\pgfpoint{.5*\w-.1cm}{7*.25cm-\n*.5cm}}]{\scriptsize IN\n}}
    }
}
% END myic definition

\begin{document}

\begin{circuitikz}
    \draw (0,0) node[myic] (u0) {U0};
    \draw (u0.in0) to[short,-o] ++(1,0); % <- ERROR: Undefined control sequence.
\end{circuitikz}

\end{document}

Here is what I have so far, the red line with a circle is what I am not able to create:

tikzcircuit ic

sergej
  • 6,461
  • 32
  • 62
  • How about this http://tex.stackexchange.com/questions/65192/how-to-generate-many-anchors-inside-pgfdeclareshape ? – percusse Jun 28 '14 at 14:34
  • @percusse Many thanks. It's one of the links in my question -- and I finally figured out how to modify your answer to fit my problem. – sergej Jun 28 '14 at 15:30
  • Oh must have clicked the link twice and confused myself. – percusse Jun 28 '14 at 18:59

1 Answers1

1

I have finally managed to apply percusee's answer (here) to my problem. It works with the following loop:

\makeatletter
\foreach \n in {0,...,7}{
    \xdef\doanchor{
        \noexpand\anchor{in\n}{
            \noexpand\pgfpoint{.5*\w}{7*.25cm-\n*.5cm}
        }
    }
    \doanchor
}
\makeatother
sergej
  • 6,461
  • 32
  • 62