4

The following MCVE code originates a Runaway argument? error during compilation time (using pdfLaTeX).

If the last line before ending tikzpicture (that is,(errtest.center) to[kinky cross=(nmos9.drain) -- ([xshift=10mm] nmos9.drain), kinky crosses=right] (nmos9.gate);) is replaced by a simple (errtest.center) -- (nmos9.gate);, the error dissapears.

I have several vertical and horizontal crossings, but only this one produces the error. What am I missing that generates the error?

The kinky cross code used is from this answer.

\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}
  • 2
    I think the problem are the nested [ ] arguments. Does it help if you wrap the [xshift=10mm] part into a pair of braces? – siracusa Jun 8 at 13:00
  • 1
    In addition to what @siracusa is saying you cannot have spaces around -- in kinky cross=.... The following works: \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);. @siracusa could you write an answer? – user121799 Jun 8 at 13:47
  • @marmot I'm fine if you add an answer, I do not even understand what your code does or how it works :p – siracusa Jun 8 at 14:22
7

The main point is made by siracusa: the parser gets confused by the [...] which are nested in the trouble-making line. This can be resolved by making the respective coordinate a symbolic coordinate via

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

In addition you cannot have spaces around -- in kinky cross=.... This is because it is not an ordinary path, where spaces would have been indeed allowed, but some style defined via 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}

enter image description here

  • Now that it was mentioned, all other kinky crosses that were present in my document did not have nested [...]. Appreciated. – Syphirint Jun 8 at 15:36
2

Just for fun, I redrew the entire circuit without using a single xshift or 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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.