是否可以使用 circuitikz 实现多个输入逻辑端口?

是否可以使用 circuitikz 实现多个输入逻辑端口?

如果 TikZ 有它们,那不可能是全部难的。

\documentclass{standalone}
\usepackage{circuitikz}
\makeatother
\begin{document}
\begin{circuitikz}
\node[american and port] at (0,0) {};
\node[american nand port] at (0,-2) {};
\node[american or port] at (2,0) {};
\node[american nor port] at (2,-2) {};
\node[american xor port] at (4,0) {};
\node[american xnor port] at (4,-2) {};
\end{circuitikz}
\end{document}

姆韦

答案1

TikZ 用于\pgfutil@g@addto@macro创建锚点,这些锚点可能以某种未记录的命名约定保存为全局宏。关键似乎是编写一个宏 ( ),它将仅使用s 和一个输入 ( )\pgf@circ@logicport@input来定位锚点。\savedanchor\pgfmathcounter

另一个问题是各个端口的左侧都是弯曲的,因此需要能够计算给定值的边缘位置y。为了简化这些计算,我使用圆弧代替\pgfpathcurveto。我还替换了外曲线。新形状不是完美匹配,但它们非常接近。为了定义左侧圆弧,我添加了两个新参数,angleinnerangle是起始角度,inner是从外边缘到曲线中间的距离。x 和 y 半径是使用计算的\pgfmath。(最终我用完了长度寄存器,不得不使用宏。)另一方面,所有aaa通过ddd参数都不再使用。

inputs按照 Circuitikz 的惯例,可以使用 为每种类型的门设置输入数量 ( ) \ctikzset。我添加了一个节点参数 ( number inputs),可以根据每个节点进行设置。此外,这个数字绝不能小于 2 或大于 16。

我添加了origin参数。设置origin=0将中心锚点置于节点的中心。默认设置为 0.8,以实现向后兼容。我修复了锚点,text以便可以在端口内写入零件编号等(如果合适)。

\documentclass{standalone}
\usepackage{circuitikz}

\ctikzset{tripoles/american and port/origin/.initial=0.8}
\ctikzset{tripoles/american and port/inputs/.initial=2}

\ctikzset{tripoles/american nand port/origin/.initial=0.8}
\ctikzset{tripoles/american nand port/inputs/.initial=2}

\ctikzset{tripoles/american nor port/origin/.initial=0.8}
\ctikzset{tripoles/american nor port/inputs/.initial=2}
\ctikzset{tripoles/american nor port/angle/.initial=70}
\ctikzset{tripoles/american nor port/inner/.initial=0.3}

\ctikzset{tripoles/american or port/origin/.initial=0.8}
\ctikzset{tripoles/american or port/inputs/.initial=2}
\ctikzset{tripoles/american or port/angle/.initial=70}
\ctikzset{tripoles/american or port/inner/.initial=0.3}

\ctikzset{tripoles/american xor port/origin/.initial=0.8}
\ctikzset{tripoles/american xor port/inputs/.initial=2}
\ctikzset{tripoles/american xor port/angle/.initial=70}
\ctikzset{tripoles/american xor port/inner/.initial=0.3}

\ctikzset{tripoles/american xnor port/origin/.initial=0.8}
\ctikzset{tripoles/american xnor port/inputs/.initial=2}
\ctikzset{tripoles/american xnor port/angle/.initial=70}
\ctikzset{tripoles/american xnor port/inner/.initial=0.3}

\pgfkeys{/tikz/number inputs/.initial=0}
\pgfkeys{/tikz/number inputs/.default=0}

\makeatletter
\newcount{\pgf@circ@res@count}% reserve global register

\newcommand{\pgf@circ@logicport@input}[1]% #1 = \pgfmathcounter
{%
  \pgfextracty{\pgf@circ@res@up}{\northeast}%
  \step
  \pgf@circ@res@step=\dimexpr 2\pgf@y -2\pgf@circ@res@up\relax
  \advance\pgf@y by -#1\pgf@circ@res@step\relax
}%
\long\def\pgfcircdeclarelogicport#1#2{%
    \pgfdeclareshape{american #1 port}%
    {%
    \savedmacro\resize{% automatic
      \pgf@circ@res@up = \pgfkeysvalueof{/tikz/circuitikz/tripoles/american #1 port/height}\pgf@circ@Rlen
      \pgf@circ@res@up = .5\pgf@circ@res@up
      \pgf@circ@res@down = -\pgf@circ@res@up
      \pgf@circ@res@right = \pgfkeysvalueof{/tikz/circuitikz/tripoles/american #1 port/width}\pgf@circ@Rlen
      \pgf@circ@res@right = .5\pgf@circ@res@right
      \pgf@circ@res@left = -\pgf@circ@res@right
    }%
    \savedmacro\inputs{% get number of inputs
      \pgf@circ@res@count=\pgfkeysvalueof{/tikz/number inputs}\relax%
      \ifnum\pgf@circ@res@count=0
        \pgf@circ@res@count=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american #1 port/inputs}\relax%
      \fi
      \ifnum\pgf@circ@res@count<2 \pgf@circ@res@count=2\fi
      \ifnum\pgf@circ@res@count>16 \pgf@circ@res@count=16\fi
      \def\inputs{\the\pgf@circ@res@count}%
    }%
    \savedanchor\step{% 1/2 gap at edges
      \pgf@circ@res@step = \pgfkeysvalueof{/tikz/circuitikz/tripoles/american #1 port/height}\pgf@circ@Rlen
      \divide\pgf@circ@res@step by \pgf@circ@res@count
      \pgfpoint{\pgf@circ@res@left}{\dimexpr\pgf@circ@res@up+0.5\pgf@circ@res@step}%
    }%
      \savedanchor\northeast{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \savedanchor\southwest{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \savedanchor\left{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american #1 port/port width}\pgf@circ@res@left}{0pt}}
    \savedanchor\right{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american #1 port/port width}\pgf@circ@res@right}{0pt}}
    \savedanchor\origin{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american #1 port/origin}\pgf@circ@res@right}{0pt}}

    \anchor{center}{\origin}% for backwards compatibility
    \anchor{text}{\pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}}

% create input anchors
    \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@american #1 port\endcsname{%
      \pgfmathloop%
      \ifnum\pgfmathcounter>\pgf@circ@res@count%
      \else%
        %\pgfutil@ifundefined{pgf@anchor@american #1 port@in \pgfmathcounter}{%
          \expandafter\xdef\csname pgf@anchor@american #1 port@in \pgfmathcounter\endcsname{%
            \noexpand\pgf@circ@logicport@input{\pgfmathcounter}% defined above
          }%
        %}{}%
      \repeatpgfmathloop%
    }

      \anchor{out}{\pgfpoint{\pgf@circ@res@right}{0pt}}

    \anchor{left}{\left}% edges of component mius leads
    \anchor{right}{\right}

    \anchor{north east}{\northeast}% see \Compass macro
    \anchor{south west}{\southwest}
    \anchor{north}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
      \pgfpoint{0cm}{\pgf@circ@res@up}}
    \anchor{north west}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
      \pgfextractx{\pgf@circ@res@left}{\southwest}%
      \pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \anchor{west}{\pgfextractx{\pgf@circ@res@left}{\sosuthwest}%
      \pgfpoint{\pgf@circ@res@left}{0cm}}
    \anchor{south}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
      \pgfpoint{0cm}{\pgf@circ@res@down}}
    \anchor{south east}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
      \pgfextractx{\pgf@circ@res@right}{\northeast}%
      \pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \anchor{east}{\pgfextractx{\pgf@circ@res@right}{\northeast}%
      \pgfpoint{\pgf@circ@res@right}{0cm}}

      \backgroundpath{          
            \pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}   
            #2
      }
    }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% and %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{and}{
  \pgfextracty{\pgf@circ@res@temp}{\step}%
  \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
  \pgf@circ@res@count = \inputs\relax
  \loop\ifnum\pgf@circ@res@count>0
    \advance\pgf@circ@res@temp by -\pgf@circ@res@step
      \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@left}
        {\pgf@circ@res@temp}}
    \advance\pgf@circ@res@count by -1
  \repeat

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@right}
        {0pt}}

    \pgfusepath{draw}

    \pgfsetlinewidth{2\pgflinewidth}
  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american and port/port width}\pgf@circ@res@left

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
  \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@down}}
  \pgfpatharc{-90}{90}{-2\pgf@circ@res@other and \pgf@circ@res@up}
  \pgfpathclose
    \pgfusepath{draw}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nand %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{nand}{
    \pgfextracty{\pgf@circ@res@temp}{\step}%
  \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
  \pgf@circ@res@count = \inputs\relax
  \loop\ifnum\pgf@circ@res@count>0
    \advance\pgf@circ@res@temp by -\pgf@circ@res@step
      \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american nand port/port width}\pgf@circ@res@left}
        {\pgf@circ@res@temp}}
    \advance\pgf@circ@res@count by -1
  \repeat

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint
        {\pgfkeysvalueof{/tikz/circuitikz/tripoles/american nand port/port width}\pgf@circ@res@right}
        {0pt}}

    \pgfusepath{draw}

    \pgfsetlinewidth{2\pgflinewidth}
    \pgf@circ@res@step = \pgfkeysvalueof{/tikz/circuitikz/tripoles/american nand port/circle width}\pgf@circ@res@right
    \pgf@circ@res@other = \pgfkeysvalueof{/tikz/circuitikz/tripoles/american nand port/port width}\pgf@circ@res@right
  \pgf@circ@res@temp = \dimexpr 2\pgf@circ@res@other - \pgf@circ@res@step\relax

    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@down}}
  \pgfpatharc{-90}{90}{\pgf@circ@res@temp and \pgf@circ@res@up}
  \pgfpathclose

    \pgfpathellipse
        {\pgfpoint{\pgf@circ@[email protected]\pgf@circ@res@step}{0pt}}
        {\pgfpoint{.5\pgf@circ@res@step}{0pt}}
        {\pgfpoint{0pt}{.5\pgf@circ@res@step}}

    \pgfusepath{draw}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{nor}{
  \edef\pgf@circ@math@angle{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american nor port/angle}}%
  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american nor port/inner}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
  \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up /sin(\pgf@circ@math@angle)}%
  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american nor port/port width}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%

    \pgfextracty{\pgf@circ@res@temp}{\step}%
  \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
  \pgf@circ@res@count = \inputs\relax
  \loop\ifnum\pgf@circ@res@count>0
    \advance\pgf@circ@res@temp by -\pgf@circ@res@step
      \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
    \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp/\pgf@circ@math@yradius)}%
    \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradius*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@temp}}%
    \advance\pgf@circ@res@count by -1
  \repeat

  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american nor port/port width}\pgf@circ@res@right
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}

  \pgfusepath{draw}

  \pgfsetlinewidth{2\pgflinewidth}

  \edef\pgf@circ@math@angle{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american nor port/angle}}%
    \pgf@circ@res@step = \pgfkeysvalueof{/tikz/circuitikz/tripoles/american nor port/circle width}\pgf@circ@res@right
  \pgf@circ@res@temp = \dimexpr 2\pgf@circ@res@other - \pgf@circ@res@step\relax
  \advance\pgf@circ@res@other by -\pgf@circ@res@step

  \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}% for symmetry
  \pgfpatharc{0}{90}{\pgf@circ@res@temp and \pgf@circ@res@up}%
  \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
  \pgfpatharc{-90}{0}{\pgf@circ@res@temp and \pgf@circ@res@up}%
  \pgfpathclose

    \pgfpathellipse
        {\pgfpoint{\pgf@circ@res@other+.5\pgf@circ@res@step}{0pt}}
        {\pgfpoint{.5\pgf@circ@res@step}{0pt}}
        {\pgfpoint{0pt}{.5\pgf@circ@res@step}}

    \pgfusepath{draw}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% or %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{or}{
    \edef\pgf@circ@math@angle{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/angle}}%
  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/inner}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
  \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up /sin(\pgf@circ@math@angle)}%
  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/port width}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%

    \pgfextracty{\pgf@circ@res@temp}{\step}%
  \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
  \pgf@circ@res@count = \inputs\relax
  \loop\ifnum\pgf@circ@res@count>0
    \advance\pgf@circ@res@temp by -\pgf@circ@res@step
      \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
    \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp/\pgf@circ@math@yradius)}%
    \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradius*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@temp}}%
    \advance\pgf@circ@res@count by -1
  \repeat

  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/port width}\pgf@circ@res@right
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}

  \pgfusepath{draw}

  \pgfsetlinewidth{2\pgflinewidth}

  \edef\pgf@circ@math@angle{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american or port/angle}}%

  \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}% for symmetry
  \pgfpatharc{0}{90}{2\pgf@circ@res@other and \pgf@circ@res@up}%
  \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
  \pgfpatharc{-90}{0}{2\pgf@circ@res@other and \pgf@circ@res@up}%
  \pgfpathclose

    \pgfusepath{draw}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% xor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{xor}{
  \pgfkeysgetvalue{/tikz/circuitikz/tripoles/american xor port/angle}{\pgf@circ@math@angle}%
  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xor port/inner}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
  \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up / sin(\pgf@circ@math@angle))}%
  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xor port/port width}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%
  \pgf@circ@res@temp=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xor port/distance}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@distance}{\pgf@circ@res@temp}
% this compensates for the effect of the line width on the gap between the arcs
  \pgfmathsetlengthmacro{\pgf@circ@math@yradiusA}{\pgf@circ@math@yradius -2\pgflinewidth}%
  \pgfmathsetlengthmacro{\pgf@circ@math@xradiusA}{\pgf@circ@math@xradius -2\pgflinewidth}%

    \pgfextracty{\pgf@circ@res@temp}{\step}%
  \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
  \pgf@circ@res@count = \inputs\relax
  \loop\ifnum\pgf@circ@res@count>0
    \advance\pgf@circ@res@temp by -\pgf@circ@res@step
      \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
    \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp  / \pgf@circ@math@yradiusA)}%
    \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradiusA*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
    \advance\pgf@circ@res@other by -\pgf@circ@math@distance
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@temp}}%
    \advance\pgf@circ@res@count by -1
  \repeat

    \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xor port/port width}\pgf@circ@res@right
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}

    \pgfusepath{draw}

  \pgfsetlinewidth{2\pgflinewidth}

  \edef\pgf@circ@math@angle{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xor port/angle}}%

  \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}% for symmetry
  \pgfpatharc{0}{90}{2\pgf@circ@res@other and \pgf@circ@res@up}%
  \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
  \pgfpatharc{-90}{0}{2\pgf@circ@res@other and \pgf@circ@res@up}%
  \pgfpathclose

  \pgfmathsetlength{\pgf@circ@res@temp}{(\pgf@circ@math@yradiusA)*sin(\pgf@circ@math@angle)}%

  \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other-\pgf@circ@math@distance}{\pgf@circ@res@temp}}% first arc
  \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradiusA and \pgf@circ@math@yradiusA}%

    \pgfusepath{draw}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% xnor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{xnor}{
  \pgfkeysgetvalue{/tikz/circuitikz/tripoles/american xnor port/angle}{\pgf@circ@math@angle}%
  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xnor port/inner}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
  \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up / sin(\pgf@circ@math@angle))}%
  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xnor port/port width}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%
  \pgf@circ@res@temp=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xor port/distance}\pgf@circ@res@right
  \pgfmathsetlengthmacro{\pgf@circ@math@distance}{\pgf@circ@res@temp}
% this compensates for the effect of the line width on the gap between the arcs
  \pgfmathsetlengthmacro{\pgf@circ@math@yradiusA}{\pgf@circ@math@yradius -2\pgflinewidth}%
  \pgfmathsetlengthmacro{\pgf@circ@math@xradiusA}{\pgf@circ@math@xradius -2\pgflinewidth}%

    \pgfextracty{\pgf@circ@res@temp}{\step}%
  \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
  \pgf@circ@res@count = \inputs\relax
  \loop\ifnum\pgf@circ@res@count>0
    \advance\pgf@circ@res@temp by -\pgf@circ@res@step
      \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
    \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp  / \pgf@circ@math@yradiusA)}%
    \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradiusA*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
    \advance\pgf@circ@res@other by -\pgf@circ@math@distance
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@temp}}%
    \advance\pgf@circ@res@count by -1
  \repeat

    \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xnor port/port width}\pgf@circ@res@right
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}

    \pgfusepath{draw}

  \pgfsetlinewidth{2\pgflinewidth}

  \edef\pgf@circ@math@angle{\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xnor port/angle}}%
  \pgf@circ@res@step = \pgfkeysvalueof{/tikz/circuitikz/tripoles/american xnor port/circle width}\pgf@circ@res@right
  \pgf@circ@res@temp = \dimexpr 2\pgf@circ@res@other - \pgf@circ@res@step\relax
  \advance\pgf@circ@res@other by -\pgf@circ@res@step

  \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}% for symmetry
  \pgfpatharc{0}{90}{\pgf@circ@res@temp and \pgf@circ@res@up}%
  \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
  \pgfpatharc{-90}{0}{\pgf@circ@res@temp and \pgf@circ@res@up}%
  \pgfpathclose

    \pgfpathellipse
        {\pgfpoint{\pgf@circ@res@other+.5\pgf@circ@res@step}{0pt}}
        {\pgfpoint{.5\pgf@circ@res@step}{0pt}}
        {\pgfpoint{0pt}{.5\pgf@circ@res@step}}

  \pgf@circ@res@other=\pgfkeysvalueof{/tikz/circuitikz/tripoles/american xnor port/port width}\pgf@circ@res@left
  \pgfmathsetlength{\pgf@circ@res@temp}{(\pgf@circ@math@yradiusA)*sin(\pgf@circ@math@angle)}%

  \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other-\pgf@circ@math@distance}{\pgf@circ@res@temp}}% first arc
  \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradiusA and \pgf@circ@math@yradiusA}%

    \pgfusepath{draw}
}
\makeatother
\begin{document}
\begin{circuitikz}
\node[american and port] at (0,0) {};
\node[american nand port,number inputs=3] at (0,-2) {};
\node[american or port,number inputs=4] at (2,0) {};
\node[american nor port,number inputs=5] at (2,-2) {};
\node[american xor port,number inputs=6] at (4,0) {};
\node[american xnor port,number inputs=7] at (4,-2) {};
\end{circuitikz}
\end{document}

演示

答案2

这是我的欧洲门版本。由于大小原因,我将其作为单独的答案输入。与美国答案有些重复:\pgf@circ@res@count\pgf@circ@logicport@inputpgfkey /tikz/number inputs

\documentclass{standalone}
\tracingmacros=1
\usepackage{circuitikz}

\ctikzset{tripoles/european and port/origin/.initial=0.8}
\ctikzset{tripoles/european and port/inputs/.initial=2}

\ctikzset{tripoles/european nand port/origin/.initial=0.8}
\ctikzset{tripoles/european nand port/inputs/.initial=2}

\ctikzset{tripoles/european or port/origin/.initial=0.8}
\ctikzset{tripoles/european or port/inputs/.initial=2}

\ctikzset{tripoles/european nor port/origin/.initial=0.8}
\ctikzset{tripoles/european nor port/inputs/.initial=2}

\ctikzset{tripoles/european xor port/origin/.initial=0.8}
\ctikzset{tripoles/european xor port/inputs/.initial=2}

\ctikzset{tripoles/european xnor port/origin/.initial=0.8}
\ctikzset{tripoles/european xnor port/inputs/.initial=2}

\ctikzset{tripoles/european not port/origin/.initial=0.8}
\ctikzset{tripoles/european not port/inputs/.initial=1}

\pgfkeys{/tikz/number inputs/.initial=0}
\pgfkeys{/tikz/number inputs/.default=0}

\makeatletter
\newcount{\pgf@circ@res@count}% reserve global register

\newcommand{\pgf@circ@logicport@input}[1]% #1 = \pgfmathcounter
{%
  \pgfextracty{\pgf@circ@res@up}{\northeast}%
  \step
  \pgf@circ@res@step=\dimexpr 2\pgf@y -2\pgf@circ@res@up\relax
  \advance\pgf@y by -#1\pgf@circ@res@step\relax
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% #1 - name
% #2 - text inside
% #3 - number of inputs
% #4 = is it a not?

\long\def\pgfcircdeclareeurologicport#1#2#3#4{
    \pgfdeclareshape{european #1 port}
    {
    \savedmacro\resize{% automatic
      \pgf@circ@res@up = \pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/height}\pgf@circ@Rlen
      \pgf@circ@res@up = .5\pgf@circ@res@up
      \pgf@circ@res@down = -\pgf@circ@res@up
      \pgf@circ@res@right = \pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/width}\pgf@circ@Rlen
      \pgf@circ@res@right = .5\pgf@circ@res@right
      \pgf@circ@res@left = -\pgf@circ@res@right
    }%
    \savedmacro\inputs{% get number of inputs
      \pgf@circ@res@count=\pgfkeysvalueof{/tikz/number inputs}\relax%
      \ifnum\pgf@circ@res@count=0
        \pgf@circ@res@count=\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/inputs}\relax%
      \fi
      \ifnum\pgf@circ@res@count<2 \pgf@circ@res@count=2\fi
      \ifnum\pgf@circ@res@count>16 \pgf@circ@res@count=16\fi
      \def\inputs{\the\pgf@circ@res@count}%
    }%
    \savedanchor\step{% 1/2 gap at edges
      \pgf@circ@res@step = \pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/height}\pgf@circ@Rlen
      \divide\pgf@circ@res@step by #3
      \pgfpoint{\pgf@circ@res@left}{\dimexpr\pgf@circ@res@up+0.5\pgf@circ@res@step}%
    }%
    \savedanchor\northeast{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}%
    \savedanchor\southwest{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}%
    \savedanchor\left{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@left}{0pt}}%
    \savedanchor\right{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@right}{0pt}}%
    \savedanchor\origin{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/origin}\pgf@circ@res@right}{0pt}}%

    \anchor{center}{\origin}% for backwards compatibility
    % the text anchor overlaps the logic symbol
    \anchor{text}{\pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}}%
    % create input anchors
    \ifnum#3=1\relax
      \anchor{in}{\pgfpoint{\pgf@circ@res@left}{0pt}}% or \step
    \else 
      \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@european #1 port\endcsname{%
      \pgfmathloop%
        \ifnum\pgfmathcounter>#3%
        \else%
          %\pgfutil@ifundefined{pgf@anchor@european #1 port@in \pgfmathcounter}{% redundant
            \expandafter\xdef\csname pgf@anchor@european #1 port@in \pgfmathcounter\endcsname{%
              \noexpand\pgf@circ@logicport@input{\pgfmathcounter}% defined above
            }%
          %}{}%
        \repeatpgfmathloop%
      }
    \fi
    \anchor{out}{\pgfpoint{\pgf@circ@res@right}{0pt}}

    \anchor{left}{\left}% edges of component minus leads
    \anchor{right}{\right}

    \anchor{north east}{\northeast}% see \Compass macro
    \anchor{south west}{\southwest}
    \anchor{north}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
      \pgfpoint{0cm}{\pgf@circ@res@up}}
    \anchor{north west}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
      \pgfextractx{\pgf@circ@res@left}{\southwest}%
      \pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \anchor{west}{\pgfextractx{\pgf@circ@res@left}{\sosuthwest}%
      \pgfpoint{\pgf@circ@res@left}{0cm}}
    \anchor{south}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
      \pgfpoint{0cm}{\pgf@circ@res@down}}
    \anchor{south east}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
      \pgfextractx{\pgf@circ@res@right}{\northeast}%
      \pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \anchor{east}{\pgfextractx{\pgf@circ@res@right}{\northeast}%
      \pgfpoint{\pgf@circ@res@right}{0cm}}

      \backgroundpath{          
            \pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}   
            \ifnum#3=1\relax
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}%
        \pgfpathlineto{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@left}{0pt}}%
      \else
        \pgfextracty{\pgf@circ@res@temp}{\step}%
        \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
        %\pgf@circ@res@count = #3\relax% redundant
        \loop\ifnum\pgf@circ@res@count>0
          \advance\pgf@circ@res@temp by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
          \pgfpathlineto{\pgfpoint
              {\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@left}
              {\pgf@circ@res@temp}}
          \advance\pgf@circ@res@count by -1
        \repeat
            \fi
            %
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
            \pgfpathlineto{%
                \pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@right}{0pt}}
            %
            \edef\pgf@temp{not}
            \edef\pgf@circ@temp{#4}
            \ifx\pgf@temp\pgf@circ@temp % is a not
                \pgfpathmoveto{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/not width}\pgf@circ@res@right}{0pt}}
                \pgfpathlineto{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@right}%
          {\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/not height}\pgf@circ@res@up}}
            \fi
            %
            \pgfusepath{draw}
            %
            \pgfpathmoveto{\pgfpointorigin}
            \pgftext{#2}
            %
            \pgfsetlinewidth{2\pgflinewidth}
            \pgfpathrectanglecorners
                {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@left}{\pgf@circ@res@up}}
                {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfusepath{draw}
%
%
      }
    }
}
\pgfcircdeclareeurologicport{and}{$\&$}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{or}{$\ge 1$}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{xor}{$=1$}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{not}{$1$}{1}{not}
\pgfcircdeclareeurologicport{nand}{$\&$}{\pgf@circ@res@count}{not}
\pgfcircdeclareeurologicport{nor}{$\ge 1$}{\pgf@circ@res@count}{not}
\pgfcircdeclareeurologicport{xnor}{$=1$}{\pgf@circ@res@count}{not}
\makeatother

\begin{document}
\begin{circuitikz}
\node[european and port] (A) at (0,0) {};
\node[european nand port,number inputs=3] at (0,-2) {};
\node[european or port,number inputs=4] at (2,0) {};
\node[european nor port,number inputs=5] at (2,-2) {};
\node[european xor port,number inputs=6] at (4,0) {};
\node[european xnor port,number inputs=7] at (4,-2) {};
\node[european not port] (B) at (0,-4) {};
\draw[red] (A.center) -- (B.center);

\end{circuitikz}
\end{document}

演示

答案3

对于那些对欧洲港口感兴趣的人,这里是对美国港口的改编,由约翰·科米洛(我希望我没有把它完全搞砸)。

欧洲港口

\documentclass{standalone}
\usepackage{circuitikz}

\ctikzset{tripoles/european and port/origin/.initial=0.8}
\ctikzset{tripoles/european and port/inputs/.initial=2}

\ctikzset{tripoles/european nand port/origin/.initial=0.8}
\ctikzset{tripoles/european nand port/inputs/.initial=2}

\ctikzset{tripoles/european nor port/origin/.initial=0.8}
\ctikzset{tripoles/european nor port/inputs/.initial=2}

\ctikzset{tripoles/european or port/origin/.initial=0.8}
\ctikzset{tripoles/european or port/inputs/.initial=2}

\ctikzset{tripoles/european xor port/origin/.initial=0.8}
\ctikzset{tripoles/european xor port/inputs/.initial=2}

\ctikzset{tripoles/european xnor port/origin/.initial=0.8}
\ctikzset{tripoles/european xnor port/inputs/.initial=2}

\pgfkeys{/tikz/number inputs/.initial=0}
\pgfkeys{/tikz/number inputs/.default=0}

\makeatletter
\newcount{\pgf@circ@res@count}% reserve global register
\newcommand{\pgf@circ@logicport@input}[1]% #1 = \pgfmathcounter
{%
  \pgfextracty{\pgf@circ@res@up}{\northeast}%
  \step
  \pgf@circ@res@step=\dimexpr 2\pgf@y -2\pgf@circ@res@up\relax
  \advance\pgf@y by -#1\pgf@circ@res@step\relax
}

\long\def\pgfcircdeclareeurologicport#1#2#3#4{
    \pgfdeclareshape{european #1 port}
    {
    \savedmacro\resize{% automatic
      \pgf@circ@res@up = \pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/height}\pgf@circ@Rlen
      \pgf@circ@res@up = .5\pgf@circ@res@up
      \pgf@circ@res@down = -\pgf@circ@res@up
      \pgf@circ@res@right = \pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/width}\pgf@circ@Rlen
      \pgf@circ@res@right = .5\pgf@circ@res@right
      \pgf@circ@res@left = -\pgf@circ@res@right
    }%
    \savedmacro\inputs{% get number of inputs
      \pgf@circ@res@count=\pgfkeysvalueof{/tikz/number inputs}\relax%
      \ifnum\pgf@circ@res@count=0
        \pgf@circ@res@count=\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/inputs}\relax%
      \fi
      \ifnum\pgf@circ@res@count<2 \pgf@circ@res@count=2\fi
      \ifnum\pgf@circ@res@count>16 \pgf@circ@res@count=16\fi
      \def\inputs{\the\pgf@circ@res@count}%
    }%
    \savedanchor\step{% 1/2 gap at edges
      \pgf@circ@res@step = \pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/height}\pgf@circ@Rlen
      \divide\pgf@circ@res@step by \pgf@circ@res@count
      \pgfpoint{\pgf@circ@res@left}{\dimexpr\pgf@circ@res@up+0.5\pgf@circ@res@step}%
    }%
    \savedanchor\northwest{%
      \pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/height}\pgf@circ@Rlen
      \pgf@y=.5\pgf@y
      \pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/width}\pgf@circ@Rlen
      \pgf@x=.5\pgf@x
    } 
    \savedanchor\northeast{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \savedanchor\southwest{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \savedanchor\left{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@left}{0pt}}
    \savedanchor\right{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@right}{0pt}}
    \savedanchor\origin{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/origin}\pgf@circ@res@right}{0pt}}
      %
    \anchor{center}{\origin}% for backwards compatibility
    \anchor{text}{\pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}}
        %
      \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@european #1 port\endcsname{%
      \pgfmathloop%
      \ifnum\pgfmathcounter>\pgf@circ@res@count%
      \else%
        %\pgfutil@ifundefined{pgf@anchor@american #1 port@in \pgfmathcounter}{%
          \expandafter\xdef\csname pgf@anchor@european #1 port@in \pgfmathcounter\endcsname{%
            \noexpand\pgf@circ@logicport@input{\pgfmathcounter}% defined above
          }%
        %}{}%
      \repeatpgfmathloop%
    }
    %
    \anchor{out}{\pgfpoint{\pgf@circ@res@right}{0pt}}
        %
    \anchor{left}{\left}% edges of component mius leads
    \anchor{right}{\right}
        %
    \anchor{north east}{\northeast}% see \Compass macro
    \anchor{south west}{\southwest}
    \anchor{north}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
      \pgfpoint{0cm}{\pgf@circ@res@up}}
    \anchor{north west}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
      \pgfextractx{\pgf@circ@res@left}{\southwest}%
      \pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \anchor{west}{\pgfextractx{\pgf@circ@res@left}{\sosuthwest}%
      \pgfpoint{\pgf@circ@res@left}{0cm}}
    \anchor{south}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
      \pgfpoint{0cm}{\pgf@circ@res@down}}
    \anchor{south east}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
      \pgfextractx{\pgf@circ@res@right}{\northeast}%
      \pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \anchor{east}{\pgfextractx{\pgf@circ@res@right}{\northeast}%
      \pgfpoint{\pgf@circ@res@right}{0cm}}
      \backgroundpath{          
            \pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}   
            \northwest
            \pgf@circ@res@up = \pgf@y 
            \pgf@circ@res@down = -\pgf@y
            \pgf@circ@res@right = -\pgf@x
            \pgf@circ@res@left = \pgf@x
            \def\pgf@temp{1}
            \def\pgf@circ@temp{#3}
            \pgfextracty{\pgf@circ@res@temp}{\step}%
          \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
          \pgf@circ@res@count = \inputs\relax
          \loop\ifnum\pgf@circ@res@count>0
            \advance\pgf@circ@res@temp by -\pgf@circ@res@step
          \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
            \pgfpathlineto{\pgfpoint
                {\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@left}
              {\pgf@circ@res@temp}}
            \advance\pgf@circ@res@count by -1
          \repeat
            %
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
            \pgfpathlineto{
                \pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@right}{0pt}}
            %
            \edef\pgf@temp{not}
            \edef\pgf@circ@temp{#4}
            \ifx\pgf@temp\pgf@circ@temp % is a not
                \pgfpathmoveto{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/not width}\pgf@circ@res@right}{0pt}}
                \pgfpathlineto{\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@right}{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/not height}\pgf@circ@res@up}}
            \fi
            %
            \pgfusepath{draw}
            %
            \pgfpathmoveto{\pgfpointorigin}
            \pgftext{#2}
            %
            \pgfsetlinewidth{2\pgflinewidth}
            \pgfpathrectanglecorners
                {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@left}{\pgf@circ@res@up}}
                {\pgfpoint{\pgfkeysvalueof{/tikz/circuitikz/tripoles/european #1 port/reserved}\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfusepath{draw}
      }
    }
}

\pgfcircdeclareeurologicport{and}{$\&$}{2}{}
\pgfcircdeclareeurologicport{or}{$\ge 1$}{2}{}
\pgfcircdeclareeurologicport{xor}{$=1$}{2}{}
\pgfcircdeclareeurologicport{not}{$1$}{1}{not}
\pgfcircdeclareeurologicport{nand}{$\&$}{2}{not}
\pgfcircdeclareeurologicport{nor}{$\ge 1$}{2}{not}
\pgfcircdeclareeurologicport{xnor}{$=1$}{2}{not}
\makeatother
\begin{document}
\begin{circuitikz}
\node[european and port] at (0,0) {};
\node[european nand port,number inputs=3] at (0,-2) {};
\node[european or port,number inputs=4] at (2,0) {};
\node[european nor port,number inputs=5] at (2,-2) {};
\node[european xor port,number inputs=6] at (4,0) {};
\node[european xnor port,number inputs=7] at (4,-2) {};
\end{circuitikz}
\end{document}

相关内容