使用 circuitikz 可能失控的论点

使用 circuitikz 可能失控的论点

以下 MCVE 代码Runaway argument?在编译时(使用pdfLaTeX)产生错误。

如果将结束之前的最后一行tikzpicture(即(errtest.center) to[kinky cross=(nmos9.drain) -- ([xshift=10mm] nmos9.drain), kinky crosses=right] (nmos9.gate);)替换为简单的(errtest.center) -- (nmos9.gate);,则错误消失。

我有几个垂直和水平交叉,但只有这一个产生错误。我遗漏了什么导致产生错误?

使用的奇异交叉代码来自这个答案

\documentclass[tikz]{standalone}
\usepackage[compatibility]{circuitikz}
\ctikzset{bipoles/length=1cm}

\tikzset{
    declare function={% in case of CVS which switches the arguments of atan2
    atan3(\a,\b)=ifthenelse(atan2(0,1)==90, atan2(\a,\b), atan2(\b,\a));},
    kinky cross radius/.initial=+.125cm,
    @kinky cross/.initial=+, kinky crosses/.is choice,
    kinky crosses/left/.style={@kinky cross=-},kinky crosses/right/.style={@kinky cross=+},
    kinky cross/.style args={(#1)--(#2)}{
        to path={
            let \p{@kc@}=($(\tikztotarget)-(\tikztostart)$),
            \n{@kc@}={atan3(\p{@kc@})+180} in
            -- ($(intersection of \tikztostart--{\tikztotarget} and #1--#2)!%
            \pgfkeysvalueof{/tikz/kinky cross radius}!(\tikztostart)$)
            arc [ radius =\pgfkeysvalueof{/tikz/kinky cross radius},
            start angle=\n{@kc@},
            delta angle=\pgfkeysvalueof{/tikz/@kinky cross}180 ]
            -- (\tikztotarget)
        }
    }
}

\begin{document}
    \begin{tikzpicture}[every text node part/.style={align=right}]
        \def\fourthlx{9}
        \node[nmos, xscale=-1] (nmos7) at (\fourthlx,0) {};
        \node[nmos, xscale=-1] (nmos8) at (\fourthlx,1.1) {};
        \node[nmos, xscale=-1] (nmos9) at (\fourthlx,2.2) {};
        \node[circ] (topresreplica) at ([yshift=15mm] nmos9.drain) {};
        \draw (topresreplica.center) to[*R] ([yshift=2mm] nmos9.drain) -- (nmos9.drain);

        \def\fifthlx{15.5}
        \node[nmos] (nmos10) at (\fifthlx,0) {};
        \node[nmos] (nmos11) at (\fifthlx-1,1.1) {};
        \node[nmos, xscale=-1] (nmos12) at (\fifthlx+1,1.1) {};
        \node[nmos, xscale=-1] (nmos13) at (\fifthlx-1,2.2) {};
        \node[nmos] (nmos14) at (\fifthlx+1,2.2) {};
        \node[circ] (topres1) at ([yshift=15mm] nmos13.drain) {};
        \node[circ] (topres2) at ([yshift=15mm] nmos14.drain) {};
        \draw (topres1.center) to[*R] ([yshift=2mm] nmos13.drain) -- (nmos13.drain);
        \draw (topres2.center) to[*R] ([yshift=2mm] nmos14.drain) -- (nmos14.drain);

        \draw (nmos7.gate) -- (nmos10.gate);
        \draw let \p{A} = ([xshift=20mm] nmos7.gate), \p{B} = (nmos9.drain) in
            node (temp) at (\x{A},\y{B}) {}
            ($(\p{A})!0.5!(temp)$) to[*R] (\p{A}) node[circ] {}
            (temp) to[*C] ($(\p{A})!0.5!(temp)$)
            (temp) to[*short,-*] (\p{B})
        ;

        \draw (nmos11.source) to[*short,-*] (nmos10.drain) to[*short] (nmos12.source);
        \draw (nmos13.gate) -- (nmos14.gate);

        \node (errtest) at ([yshift=8mm] nmos9.gate) {};
        \draw ($(nmos13.gate)!0.5!(nmos14.gate)$) to[*short,*-] ([yshift=8mm] $(nmos13.gate)!0.5!(nmos14.gate)$) to[kinky cross=(nmos13.drain)--(topres1.center), kinky crosses=left] (errtest.center)
        %(errtest.center) -- (nmos9.gate);
        (errtest.center) to[kinky cross=(nmos9.drain) -- ([xshift=10mm] nmos9.drain), kinky crosses=right] (nmos9.gate);

    \end{tikzpicture}
\end{document}

答案1

重点是由锡拉库萨制造:解析器对[...]嵌套在麻烦行中的感到困惑。可以通过将相应坐标设为符号坐标来解决此问题

\path ([xshift=10mm]nmos9.drain) coordinate (aux); 

此外,--在 中不能有空格kinky cross=...。这是因为它不是普通路径,普通路径中确实允许有空格,但某种样式是通过 定义的style args

\documentclass[tikz]{standalone}
\usepackage[compatibility]{circuitikz}
\ctikzset{bipoles/length=1cm}

\tikzset{
    declare function={% in case of CVS which switches the arguments of atan2
    atan3(\a,\b)=ifthenelse(atan2(0,1)==90, atan2(\a,\b), atan2(\b,\a));},
    kinky cross radius/.initial=+.125cm,
    @kinky cross/.initial=+, kinky crosses/.is choice,
    kinky crosses/left/.style={@kinky cross=-},kinky crosses/right/.style={@kinky cross=+},
    kinky cross/.style args={(#1)--(#2)}{
        to path={
            let \p{@kc@}=($(\tikztotarget)-(\tikztostart)$),
            \n{@kc@}={atan3(\p{@kc@})+180} in
            -- ($(intersection of \tikztostart--{\tikztotarget} and #1--#2)!%
            \pgfkeysvalueof{/tikz/kinky cross radius}!(\tikztostart)$)
            arc [ radius =\pgfkeysvalueof{/tikz/kinky cross radius},
            start angle=\n{@kc@},
            delta angle=\pgfkeysvalueof{/tikz/@kinky cross}180 ]
            -- (\tikztotarget)
        }
    }
}

\begin{document}
    \begin{tikzpicture}[every text node part/.style={align=right}]
        \def\fourthlx{9}
        \node[nmos, xscale=-1] (nmos7) at (\fourthlx,0) {};
        \node[nmos, xscale=-1] (nmos8) at (\fourthlx,1.1) {};
        \node[nmos, xscale=-1] (nmos9) at (\fourthlx,2.2) {};
        \node[circ] (topresreplica) at ([yshift=15mm] nmos9.drain) {};
        \draw (topresreplica.center) to[*R] ([yshift=2mm] nmos9.drain) -- (nmos9.drain);

        \def\fifthlx{15.5}
        \node[nmos] (nmos10) at (\fifthlx,0) {};
        \node[nmos] (nmos11) at (\fifthlx-1,1.1) {};
        \node[nmos, xscale=-1] (nmos12) at (\fifthlx+1,1.1) {};
        \node[nmos, xscale=-1] (nmos13) at (\fifthlx-1,2.2) {};
        \node[nmos] (nmos14) at (\fifthlx+1,2.2) {};
        \node[circ] (topres1) at ([yshift=15mm] nmos13.drain) {};
        \node[circ] (topres2) at ([yshift=15mm] nmos14.drain) {};
        \draw (topres1.center) to[*R] ([yshift=2mm] nmos13.drain) -- (nmos13.drain);
        \draw (topres2.center) to[*R] ([yshift=2mm] nmos14.drain) -- (nmos14.drain);

        \draw (nmos7.gate) -- (nmos10.gate);
        \draw let \p{A} = ([xshift=20mm] nmos7.gate), \p{B} = (nmos9.drain) in
            node (temp) at (\x{A},\y{B}) {}
            ($(\p{A})!0.5!(temp)$) to[*R] (\p{A}) node[circ] {}
            (temp) to[*C] ($(\p{A})!0.5!(temp)$)
            (temp) to[*short,-*] (\p{B})
        ;

        \draw (nmos11.source) to[*short,-*] (nmos10.drain) to[*short] (nmos12.source);
        \draw (nmos13.gate) -- (nmos14.gate);

        \node (errtest) at ([yshift=8mm] nmos9.gate) {};
        \path ([xshift=10mm]nmos9.drain) coordinate (aux);
        \draw ($(nmos13.gate)!0.5!(nmos14.gate)$) to[*short,*-] ([yshift=8mm] $(nmos13.gate)!0.5!(nmos14.gate)$) to[kinky cross=(nmos13.drain)--(topres1.center), kinky crosses=left] (errtest.center)
        (errtest.center) to[kinky cross=(nmos9.drain)--(aux), kinky crosses=right] (nmos9.gate);

    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

只是为了好玩,我重新绘制了整个电路,没有使用单个 xshift 或 yshift。

\documentclass[tikz]{standalone}
\usepackage[compatibility]{circuitikz}
\ctikzset{bipoles/length=1cm}

\tikzset{
    declare function={% in case of CVS which switches the arguments of atan2
    atan3(\a,\b)=ifthenelse(atan2(0,1)==90, atan2(\a,\b), atan2(\b,\a));},
    kinky cross radius/.initial=+.125cm,
    @kinky cross/.initial=+, kinky crosses/.is choice,
    kinky crosses/left/.style={@kinky cross=-},kinky crosses/right/.style={@kinky cross=+},
    kinky cross/.style args={(#1)--(#2)}{%
        to path={
            let \p{@kc@}=($(\tikztotarget)-(\tikztostart)$),
            \n{@kc@}={atan3(\p{@kc@})+180} in
            -- ($(intersection of {\tikztostart}--{\tikztotarget} and #1--#2)!%
            \pgfkeysvalueof{/tikz/kinky cross radius}!(\tikztostart)$)
            arc [ radius =\pgfkeysvalueof{/tikz/kinky cross radius},
            start angle=\n{@kc@},
            delta angle=\pgfkeysvalueof{/tikz/@kinky cross}180 ]
            -- (\tikztotarget)
        }
    }
}

\begin{document}
    \begin{tikzpicture}[every text node part/.style={align=right}]
        \def\fourthlx{9}
        \node[nmos, xscale=-1] (nmos7) at (\fourthlx,0) {};
        \node[nmos, xscale=-1] (nmos8) at (\fourthlx,1.1) {};
        \node[nmos, xscale=-1] (nmos9) at (\fourthlx,2.2) {};
        \path (nmos9.drain) ++(0,15mm) coordinate (topresreplica);
        \draw (nmos9.drain) -- ++(0,2mm) to[*R,-*] (topresreplica);

        \def\fifthlx{15.5}
        \node[nmos] (nmos10) at (\fifthlx,0) {};
        \node[nmos] (nmos11) at (\fifthlx-1,1.1) {};
        \node[nmos, xscale=-1] (nmos12) at (\fifthlx+1,1.1) {};
        \node[nmos, xscale=-1] (nmos13) at (\fifthlx-1,2.2) {};
        \node[nmos] (nmos14) at (\fifthlx+1,2.2) {};
        \node[circ] (topres1) at (nmos13.drain |- topresreplica) {};
        \node[circ] (topres2) at (nmos14.drain |- topresreplica) {};
        \draw (nmos13.drain) -- ++(0,2mm) to[*R] (topres1.center);
        \draw (nmos14.drain) -- ++(0,2mm) to[*R] (topres2.center);

        \draw (nmos7.gate) -- (nmos10.gate);
        \path (nmos7.gate |- nmos9.drain) -- ++(20mm,0) coordinate (topthingy);
        \path (nmos7.gate -| topthingy) coordinate (bottomthingy);
        \draw (nmos9.drain) to[*short,*-] (topthingy)
          to[*C] ($(topthingy)!0.5!(bottomthingy)$)
          to[*R,-*] (bottomthingy);


        \draw (nmos11.source) to[*short,-*] (nmos10.drain) to[*short] (nmos12.source);
        \draw (nmos13.gate) -- (nmos14.gate);

        \path (nmos9.gate) ++(0,8mm) coordinate (errtest);
        \draw ($(nmos13.gate)!0.5!(nmos14.gate)$) coordinate (midgate)
          to[*short,*-] (errtest -| midgate)
          to[kinky cross=(nmos13.drain)--(topres1), kinky crosses=left] (errtest)
          to[kinky cross=(nmos9.drain)--(topthingy), kinky crosses=right] (nmos9.gate);

    \end{tikzpicture}
\end{document}

相关内容