Tikz has a bunch of useful digital circuit components, basic or complex. Here, I need some of my own, not necessarily even one of the convenient ones. But let's take one, rather convenient example: A magnitude comparator.
I would like to have this magnitude comparator component for my task, with its signal ports defined as anchors. I can make a box with labels on ports and a name on it, but that is not enough!
I need to show what's on the inside, as well. Details shall not go beyond the gates, I don't want the transistors around, but I do need the gates.
Here's what I have on my hands so far, most of which is just copied/mimicked from this (famous?) data flip-flop example:
\makeatletter
% Magnitude Comparator (magn comparator) shape
\pgfdeclareshape{magn comparator}
{
% The 'minimum width' and 'minimum height' keys, not the content, determine
% the size
\savedanchor\northeast
{%
\pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
\pgfmathsetlength\pgf@y{\pgfshapeminheight}%
\pgf@x=0.5\pgf@x
\pgf@y=0.5\pgf@y
}
% This is redundant, but makes some things easier:
\savedanchor\southwest
{%
\pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
\pgfmathsetlength\pgf@y{\pgfshapeminheight}%
\pgf@x=-0.5\pgf@x
\pgf@y=-0.5\pgf@y
}
% Inherit from rectangle
\inheritanchorborder[from=rectangle]
% Define same anchor a normal rectangle has
\anchor{center}{\pgfpointorigin}
\anchor{north}{\northeast \pgf@x=0pt}
\anchor{east}{\northeast \pgf@y=0pt}
\anchor{south}{\southwest \pgf@x=0pt}
\anchor{west}{\southwest \pgf@y=0pt}
\anchor{north east}{\northeast}
\anchor{north west}{\northeast \pgf@x=-\pgf@x}
\anchor{south west}{\southwest}
\anchor{south east}{\southwest \pgf@x=-\pgf@x}
\anchor{text}
{
\pgfpointorigin
\advance\pgf@x by -.5\wd\pgfnodeparttextbox%
\advance\pgf@y by -.5\ht\pgfnodeparttextbox%
\advance\pgf@y by +.5\dp\pgfnodeparttextbox%
}
% Define anchors for input signal ports
\anchor{input gt}
{
\pgf@process{\southwest}%
\pgf@y=-.5\pgf@y%
}
\anchor{input eq}
{
\pgf@process{\southwest}%
\pgf@y=0pt%
}
\anchor{input lt}
{
\pgf@process{\southwest}%
\pgf@y=.5\pgf@y%
}
\anchor{input a}
{
\pgf@process{\northeast}%
\pgf@x=-.3\pgf@x%
}
\anchor{input b}
{
\pgf@process{\northeast}%
\pgf@x=.3\pgf@x%
}
% Define anchors for output signal ports
\anchor{output gt}
{
\pgf@process{\northeast}%
\pgf@y=.5\pgf@y%
}
\anchor{output eq}
{
\pgf@process{\northeast}%
\pgf@y=0pt%
}
\anchor{output lt}
{
\pgf@process{\northeast}%
\pgf@y=-.5\pgf@y%
}
% Draw the rectangle box and the port labels
\backgroundpath
{
% Rectangle box
\pgfpathrectanglecorners{\southwest}{\northeast}
% \node [and gate] (kek) at (0, 0) {};
}
}
% Define default style for this node
\tikzset
{
every magn comparator node/.style =
{
draw,
minimum width = 2cm,
minimum height = 2cm,
thick,
inner sep = 1mm,
outer sep = 0pt,
cap = round
}
}
\makeatother
This is in a separate file which I include in the preamble of my main LaTeX file.
There are no gates here, it just draws the box. I attempted to simply put down a random AND gate in the usual way I do outside this \pgfdeclareshape thing, which of course did not work. I commented that out, that attempt.
There should be a way for me to define further shapes on top of the existing shapes. What is it?
Edit: I am expecting to have something like this in my hands, which I should be able to place and ports of which I can easily reach as anchors, similar to how it is with an AND/OR/NOR/XOR/NAND gate:

Note that the inside of the box doesn't really function as a magnitude comparator, it's just a dummy example of what I expect.


\nodeinside a\backgroundpathwon't work in any way. Can you show us how your "magnitude comparator" should look like? For additionl (pseudo-)anchors on a rectangular box there are very easy ways to do this, e.g.: Making FFT Figure using LaTeX Tikz, Tikz surrounding box with automatically drawn border “ports”. There is also the possibility to do this with proper anchors and a well-defined shape if needed. – Qrrbrbirlbel May 03 '15 at 18:20path pictureand/or aappend after command(possibly modified, see [1]/[2]). The anchors are relative easy to place. Are the positions fixed or should they be varied? Also, do you have a lot of shapes with different anchors? Than it might be easier to use pseudo-anchors (see comment above). – Qrrbrbirlbel May 03 '15 at 19:29pic(see TikZ' manual). – Qrrbrbirlbel May 03 '15 at 19:35\pgfnodeinside a\(before)backgroundpathwhich will need various keys (height, width, etc) re-set to appropriate values. Again, this is all dependent on the variety of your needed shapes. (This will also need the connections to be drawn in PGF, mind you.) Related: Can a shape be composed out of “subshapes” in TikZ? – Qrrbrbirlbel May 03 '15 at 21:08