爱好:使用点处的切线信息绘制路径时,出现 TeX 容量超出(参数堆栈大小?)错误

爱好:使用点处的切线信息绘制路径时,出现 TeX 容量超出(参数堆栈大小?)错误

运行以下示例代码时,出现 TeX 容量超出错误(来自这个问题的答案

\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{calc, hobby}
\tikzset{tangent/.style = \tikzset{
        tangent/.style = {
            in angle={(180+#1)},
            Hobby finish,
            designated Hobby path=next,
            out angle=#1
        }
    }}

\begin{document}
    \begin{figure}[htbp]
        \centering
        \begin{tikzpicture}

        \coordinate (y) at (0,3);
        \coordinate (x) at (5,0);

        \coordinate (sp0) at (1.5, 0);
        \coordinate (ep0) at (3.5, 2);
        \coordinate (csp0) at (2.5, 1);
        \coordinate (cep0) at (2.75, 0);

        \coordinate (sp1) at (ep0);
        \coordinate (ep1) at (4.5, 3);
        \coordinate (csp1) at (4.25, 4);
        \coordinate (cep1) at (4.25, 2);

        \coordinate (sp2) at (sp0);
        \coordinate (ep2) at (0, -1);
        \coordinate (csp2) at (0.5, -1);
        \coordinate (cep2) at (0.5, -1);

        \draw[<->] (y) node[left] {$f(x)$} -- (0,0) --  (x) node[below] {$x$};

        % Using \pgfmathanglebetweenpoints to calculate the angle for tangent
        % tangent takes a degree unit angle
        \pgfmathanglebetweenpoints{\pgfpointanchor{cep0}{center}}{\pgfpointanchor{ep0}{center}}
        \let\angle=\pgfmathresult
        \draw (ep2) to [curve through ={(sp0) .. ([tangent=\angle]ep0)}] (ep1) ;

        \draw[dashed] (cep0) -- (csp1);
        \draw[dotted] let \p1 = (ep0) in (ep0) -- (0, \y1);
        \draw[dotted] let \p1 = (ep0) in (ep0)-- (\x1, 0);

        \draw let \p1 = (ep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_0$};
        \draw let \p1 = (cep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_1$};
        \draw let \p1 = (ep0) in (1pt, \y1) -- (-3pt, \y1) node [anchor=east] {$f(x_0)$};
        \end{tikzpicture}
        \caption{Newton's method in action: diagram drawn using the \texttt{hobby} package.}
        \label{fig:newton_method_2}
    \end{figure}
\end{document}

日志中的完整错误如下:

! TeX capacity exceeded, sorry [parameter stack size=10000].
\pgfkeys@@qset #1#2#3->
                       \def \pgfkeysdefaultpath {#2/}\pgfkeys@parse #3,\pgfk...
l.85 ...h ={(sp0) .. ([tangent=\angle]ep0)}] (ep1)
                                                   ;
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.

搜索此错误后,我发现解决方案有时非常晦涩难懂……所以我完全不确定问题出在哪里。我能按照错误消息的建议简单地“增加容量”吗?

答案1

您正在尝试将样式设置为该样式定义的一部分。因此 TiKZ 陷入困境,因为设置是恶性递归的。

\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{calc, hobby}
\tikzset{
        tangent/.style = {
            in angle={(180+#1)},
            Hobby finish,
            designated Hobby path=next,
            out angle=#1
        }
    }

\begin{document}
    \begin{figure}[htbp]
        \centering
        \begin{tikzpicture}

        \coordinate (y) at (0,3);
        \coordinate (x) at (5,0);

        \coordinate (sp0) at (1.5,0);
        \coordinate (ep0) at (3.5,2);
        \coordinate (csp0) at (2.5,1);
        \coordinate (cep0) at (2.75,0);

        \coordinate (sp1) at (ep0);
        \coordinate (ep1) at (4.5,3);
        \coordinate (csp1) at (4.25,4);
        \coordinate (cep1) at (4.25,2);

        \coordinate (sp2) at (sp0);
        \coordinate (ep2) at (0,-1);
        \coordinate (csp2) at (0.5,-1);
        \coordinate (cep2) at (0.5,-1);

        \draw[<->] (y) node[left] {$f(x)$} -- (0,0) --  (x) node[below] {$x$};

        % Using \pgfmathanglebetweenpoints to calculate the angle for tangent
        % tangent takes a degree unit angle
        \pgfmathanglebetweenpoints{\pgfpointanchor{cep0}{center}}{\pgfpointanchor{ep0}{center}}
        \let\angle=\pgfmathresult
        \draw (ep2) to [curve through ={(sp0) .. ([tangent=\angle]ep0)}] (ep1) ;

        \draw[dashed] (cep0) -- (csp1);
        \draw[dotted] let \p1 = (ep0) in (ep0) -- (0,\y1);
        \draw[dotted] let \p1 = (ep0) in (ep0)-- (\x1,0);

        \draw let \p1 = (ep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_0$};
        \draw let \p1 = (cep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_1$};
        \draw let \p1 = (ep0) in (1pt,\y1) -- (-3pt,\y1) node [anchor=east] {$f(x_0)$};
        \end{tikzpicture}
        \caption{Newton's method in action: diagram drawn using the \texttt{hobby} package.}
        \label{fig:newton_method_2}
    \end{figure}
\end{document}

我不知道它们是否在这里造成了问题,但请注意,TiKZ/PGF 也对空格敏感,因此在使用时要注意一致性。

牛顿重现

相关内容