3

I am trying to create an AO logic gate, which consists of three predefined shapes, as via \declarepgfshape. So far, I was able to define the shape in \backgroundpath. However, I want to have some anchors for my new figure. These shall be inherited anchors from the three predefined shapes. However, I did not manage to transfer the location of the anchors from figures I defined in \backgroundpath to somewhere outside this section. Is there any way to save coordinates inside backgroundpath or some way to define the three subshapes outside of it? To go a bit more into detail, I would like to inherit the output of the lower subshape to be the output of my new shape and something similar for the inputs of the upper subshapes. Since their definition is non-trivial, I do not want to define all the anchors by hand. So far, I only achieved to create an \edef\@temp{} environment which makes it possible to access the subfigures defined in the backgroundpath from outside the shape definition. However, I can still not correctly use them inside \savedanchor. In my code below, The anchor, which should be at the bottom of the bottom gate, is directly in the origin.

I read about redefining the subfigures in \edef\@temp{} in order to access them from outside the backgroundpath but redefining them and using them instead of \tikz@fig@name-bottom does not help either. Do you have a suggestion how to solve the problem? I know that I can access the anchors I need via a-bottom.output but I want a similar structure to access the output as for the usual AND- or OR-gates, which would be via a.output.

Here you can see the outcome of the code I wrote.

enter image description here

Here is the code which should attach the horizontal line at the bottom of the figure. Thanks a lot for your help!

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.gates.logic.US,shapes.gates.logic.IEC}
\makeatletter

\pgfdeclareshape{dumbbell}{ \savedanchor{\center}{% \pgfpointorigin} \anchor{center}{\center} \backgroundpath{ \edef@temp{% \noexpand\node[outer sep=0pt, or gate US, draw, rotate=270] at (0,0) (\tikz@fig@name-bottom){}; \noexpand\node[outer sep=0pt, and gate US, draw, logic gate inputs=nn, rotate=270, scale=0.8, anchor=east] at (\tikz@fig@name-bottom.north west) (\tikz@fig@name-right){}; \noexpand\node[outer sep=0pt, and gate US, draw, logic gate inputs=nn, rotate=270, scale= 0.8, anchor=east] at (\tikz@fig@name-bottom.south west) (\tikz@fig@name-left){}; } @temp
} \savedanchor{\output}{\tikz@fig@name-bottom.output} \anchor{output}{\output} }

\begin{document} \begin{tikzpicture} \node[dumbbell] (a) at (0,0) {}; \draw (a.output) -- (1,0); \end{tikzpicture} \end{document}

cfr
  • 198,882
  • Welcome to TeX.SE! – Mensch Nov 25 '21 at 14:32
  • Is this question still relevant? You will get to a solution much easier and faster by defining a pic that way. What you're trying to do might work with the right setup and a few calculations … but not this way. \tikzset{dumbbell/.pic={\node[…](-bottom){} node[…] (-right) {} node[…] (-left) {};. If this is den used like pic (a) {dumbbell} the coordinate specification (a-bottom.output) can be used. – Qrrbrbirlbel Nov 11 '23 at 20:56
  • @Qrrbrbirlbel Is https://tex.stackexchange.com/questions/18400/can-a-shape-be-composed-out-of-subshapes-in-tikz?rq=1 a duplicate, do you think? – cfr Nov 12 '23 at 06:27
  • @cfr It looks like the source for OP's code which would make this a follow-up question. Ah, I see the recent answer uses pics … oh well. – Qrrbrbirlbel Nov 12 '23 at 15:12

0 Answers0