!TeX 容量超出,抱歉 [主内存大小=5000000]。for foreach

!TeX 容量超出,抱歉 [主内存大小=5000000]。for foreach

我在这一点上遇到了阻碍,我将编写一个代码,在其中使用命令foreach

\pgfmathtruncatemacro{\iar}{{\RodLength*\iBngle/180}}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\pgfmathtruncatemacro{\tar}{{(\RodLength*\iBngle/360)-\iar}}
\foreach \jar in {\iar, \tar, ...,\tar}{
....
}

当我编译此代码时出现以下错误:

 Runaway argument? {\pgfkeysvalueof {/pgf/inner ! TeX capacity
 exceeded, sorry [main memory size=5000000]. <argument> ...pgf@xc
 {\pgfkeysvalueof {/pgf/inner 
                                                   xsep}}\advance \pgf@x by 2... l.98 }
        !  ==> Fatal error occurred, no output PDF file produced!
 Transcript written on fig_serie_2.log.

她是我的代码

\documentclass[border=5pt]{standalone}
\usepackage{tikz,tikz-3dplot}
\usepackage{animate}
\usepackage{ifthen}
\usetikzlibrary{patterns}% 
\def\relRad{0.3}
\def\RodLength{1.65}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{animateinline}[loop, poster = first, controls=false]{24}
%\foreach \iBngle in {0,2,...,100}{
\multiframe{100}{iBngle=0+2}{
\pgfmathsetmacro{\iAngle}{140}%35
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\useasboundingbox[tdplot_screen_coords] (-2.05,-1.2) rectangle 
(2.5,1.5);
\coordinate (O) at (0,0,0);
\node[red, left] at (O) {$O$};
\draw[thick,->] (O) -- (2,0,0) node[anchor=north]{$x_0$};
\draw[thick,->] (O) -- (0,1.5,0) node[anchor=west]{$y_0$};
\draw[thick,->] (O) -- (0,0,1.5) node[anchor=south]{$z_0$};
\draw[thick,->] (O) -- (0.3,0,0) node[anchor=north, left]{$\vec i_0$};
\draw[thick,->] (O) -- (0,0.3,0) node[near end, below]{$\vec j_0$};
\draw[thick,->] (O) -- (0,0,0.3) node[anchor=south, right]{$\vec 
k_0$};
\draw[thick, opacity=0.3] (-2,-1.5,0) -- (2,-1.5,0) -- (2,1.5,0) --(-2,1.5,0) -- cycle;
\fill[red,opacity=0.2](-2,-1.5,0) -- (2,-1.5,0) -- (2,1.5,0) --(-2,1.5,0) -- cycle;
\tdplotdrawarc[thick, color=red]{(2,-1.5,0)}{-0.3}{-90}{0}{anchor=180}
{$\pi/2$}% <-
\tdplotdrawarc[thick, color=red, ->]{(O)}{0.5}{0}{\iAngle+\iBngle}
{anchor=180, below}{$\omega\cdot t$}%
\tdplotdrawarc[thick,dotted, color=violet, ->]{(O)}{0.55}{90}
{90+\iAngle+\iBngle}{anchor=180,above}{$\omega\cdot t$}
\tdplotdrawarc[thick, color=purple, dashed]{(O)}
{\RodLength*\iBngle/180}{0}{360}{anchor=180}{} %%changed
\tdplotsetrotatedcoords{\iAngle+\iBngle}{00}{0}%%changed
\begin{scope}[tdplot_rotated_coords]
\draw[thick, dashed, opacity=1, ->] (0,0,0) -- (2.5,0,0)node[above]
{$x_1$};
\draw[thick, dashed, opacity=1, ->] (0,0,0) -- (0,2.5,0)node[above] 
{$y_1$};
\draw[thick,->] (O) -- (0.3,0,0) node[anchor=north, above left]{$\vec 
i_1$};
\draw[thick,->] (O) -- (0,0.3,0) node[near end, above]{$\vec j_1$};
\end{scope}
\ifthenelse{\iBngle<180}{
\tdplotsetrotatedcoords{{\iAngle+\iBngle}}{00}{0} %<- changed that in order to rotate the rod
\begin{scope}[tdplot_rotated_coords]
\pgfmathtruncatemacro{\iar}{{\RodLength*\iBngle/180}}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\pgfmathtruncatemacro{\tar}{{(\RodLength*\iBngle/360)-\iar}}
\foreach \jar in {\iar, \tar, ...,\tar}{
\draw[ultra thick, color=orange, opacity=1] (0,0,0) -- 
(\RodLength,0,0)node[near end, below left] {$(T)$};
\coordinate[label=below right:$C$] (A1) at 
({\RodLength*\iBngle/180},0,0.3); 
\fill[blue,thick] (A1) circle (0.3pt);
\coordinate[label=above:$I_1$] (I1) at 
({\RodLength*\iBngle/180},0,0);%changed
\fill[blue,thick] (I1) circle (0.3pt);}
\end{scope}
\tdplotsetrotatedcoords{{\iAngle+130}}{90}{0} %<-
\begin{scope}[tdplot_rotated_coords]
\draw[pattern=north west lines, pattern color=blue, opacity=0.5 ] (A1) 
 circle (\relRad);
\node[] at (45:0.4cm){$D$};
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$k_1$};  %<-
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$i_1$};  %<-
\draw[-latex,blue] (A1) -- ++({-0.7*cos(\iBngle/\relRad+\iAngle)},0,{0.7*sin(\iBngle/\relRad+\iAngle)})node[right]{$i_2$}; %<-
\draw[-latex,blue] (A1) -- ++({-0.7*sin(\iBngle/\relRad)},0,{-0.7*cos(\iBngle/\relRad)})node[below]{$k_2$};  %<-
\end{scope}}{
\tdplotsetrotatedcoords{{\iAngle+\iBngle}}{00}{0} %<- changed that in order to rotate the rod
\begin{scope}[tdplot_rotated_coords]
\pgfmathtruncatemacro{\iar}{{\RodLength*\iBngle/180}}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\pgfmathtruncatemacro{\tar}{{(\RodLength*\iBngle/360)-\iar}}
\foreach \jar in {\iar, \tar, ...,\tar}{
\draw[ultra thick, color=orange, opacity=1] (0,0,0) -- 
(\RodLength,0,0)node[near end, below left] {$(T)$};
\coordinate[label=below right:$C$] (A1) at 
({\RodLength*\iBngle/180},0,0.3); 
\fill[blue,thick] (A1) circle (0.3pt);
\coordinate[label=above:$I_1$] (I1) at 
({\RodLength*\iBngle/180},0,0);%changed
\fill[blue,thick] (I1) circle (0.3pt);}
\end{scope}
\tdplotsetrotatedcoords{{\iAngle+130}}{90}{0} %<-
\begin{scope}[tdplot_rotated_coords]
\draw[pattern=north west lines, pattern color=blue, opacity=0.5 ] (A1) 
 circle (\relRad);
\node[] at (45:0.4cm){$D$};
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$k_1$};  %<-
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$i_1$};  %<-
\draw[-latex,blue] (A1) -- ++({-0.7*cos(\iBngle/\relRad+\iAngle)},0,{0.7*sin(\iBngle/\relRad+\iAngle)})node[right]{$i_2$}; %<-
\draw[-latex,blue] (A1) -- ++({-0.7*sin(\iBngle/\relRad)},0,{-0.7*cos(\iBngle/\relRad)})node[below]{$k_2$};  %<-
\end{scope}}
\end{tikzpicture}
}
\end{animateinline}
\end{document}

答案1

真实的问题在于,正如你所说,在行中。TeX 到达此处时,和\foreach \jar in {\iar, \tar, ...,\tar}的值均为零,因此命令读取,这会导致无限循环\iar\tar\foreach \jar in {0, 0, ...,0}:)

循环增量(\tar)的值不能为零,否则会出现这种情况。\iar和的值都\tar为零,因为\iBngle为零。

所以第一的修复方法是改变线路

\multiframe{100}{iBngle=0+2}{

改为除零以外的其他值。由于此处的增量为 2,我建议使用奇数,这样无论迭代多少次,它都不会为零。

第二个问题是这些行:

\pgfmathtruncatemacro{\iar}{{\RodLength*\iBngle/180}}
\pgfmathtruncatemacro{\tar}{{(\RodLength*\iBngle/360)-\iar}}

\pgfmathtruncatemacro作用正如其名称所示。\RodLength = 1.65在第一次修正后,有 和\iBngle = 1。这说明1.65*1/180 = 0.009,截断后为零。并且 和\iar\tar为零。

将这些行替换为:

\pgfmathparse{\RodLength*\iBngle/180}
\let\iar\pgfmathresult
\pgfmathparse{(\RodLength*\iBngle/360)-\iar}
\let\tar\pgfmathresult

您将获得正确的值,而不会被截断。

我修复了你的代码并且它运行良好,但不幸的是我的 PDF 查看器无法播放动画,所以我无法检查它是否有效。

顺便提一下,这一行:\foreach \jar in {\iar, \tar, ...,\tar}。应该是这样的吗?据我了解,循环只会对 进行一次迭代\jar=\iar,如果这是正确的,那么使用 就毫无意义了\foreach

完整代码如下:

\documentclass[border=5pt]{standalone}
\usepackage{tikz,tikz-3dplot}
\usepackage{animate}
\usepackage{ifthen}
\usetikzlibrary{patterns}% 
\def\relRad{0.3}
\def\RodLength{1.65}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{animateinline}[loop, poster = first, controls=false]{24}
%\foreach \iBngle in {0,2,...,100}{
\multiframe{100}{iBngle=1+2}{
\pgfmathsetmacro{\iAngle}{140}%35
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\useasboundingbox[tdplot_screen_coords] (-2.05,-1.2) rectangle 
(2.5,1.5);
\coordinate (O) at (0,0,0);
\node[red, left] at (O) {$O$};
\draw[thick,->] (O) -- (2,0,0) node[anchor=north]{$x_0$};
\draw[thick,->] (O) -- (0,1.5,0) node[anchor=west]{$y_0$};
\draw[thick,->] (O) -- (0,0,1.5) node[anchor=south]{$z_0$};
\draw[thick,->] (O) -- (0.3,0,0) node[anchor=north, left]{$\vec i_0$};
\draw[thick,->] (O) -- (0,0.3,0) node[near end, below]{$\vec j_0$};
\draw[thick,->] (O) -- (0,0,0.3) node[anchor=south, right]{$\vec 
k_0$};
\draw[thick, opacity=0.3] (-2,-1.5,0) -- (2,-1.5,0) -- (2,1.5,0) --(-2,1.5,0) -- cycle;
\fill[red,opacity=0.2](-2,-1.5,0) -- (2,-1.5,0) -- (2,1.5,0) --(-2,1.5,0) -- cycle;
\tdplotdrawarc[thick, color=red]{(2,-1.5,0)}{-0.3}{-90}{0}{anchor=180}
{$\pi/2$}% <-
\tdplotdrawarc[thick, color=red, ->]{(O)}{0.5}{0}{\iAngle+\iBngle}
{anchor=180, below}{$\omega\cdot t$}%
\tdplotdrawarc[thick,dotted, color=violet, ->]{(O)}{0.55}{90}
{90+\iAngle+\iBngle}{anchor=180,above}{$\omega\cdot t$}
\tdplotdrawarc[thick, color=purple, dashed]{(O)}
{\RodLength*\iBngle/180}{0}{360}{anchor=180}{} %%changed
\tdplotsetrotatedcoords{\iAngle+\iBngle}{00}{0}%%changed
\begin{scope}[tdplot_rotated_coords]
\draw[thick, dashed, opacity=1, ->] (0,0,0) -- (2.5,0,0)node[above]
{$x_1$};
\draw[thick, dashed, opacity=1, ->] (0,0,0) -- (0,2.5,0)node[above] 
{$y_1$};
\draw[thick,->] (O) -- (0.3,0,0) node[anchor=north, above left]{$\vec 
i_1$};
\draw[thick,->] (O) -- (0,0.3,0) node[near end, above]{$\vec j_1$};
\end{scope}
\ifthenelse{\iBngle<180}{
\tdplotsetrotatedcoords{{\iAngle+\iBngle}}{00}{0} %<- changed that in order to rotate the rod
\begin{scope}[tdplot_rotated_coords]
\pgfmathparse{\RodLength*\iBngle/180}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\let\iar\pgfmathresult
\pgfmathparse{(\RodLength*\iBngle/360)-\iar}
\let\tar\pgfmathresult
\foreach \jar in {\iar, \tar, ...,\tar}{
\draw[ultra thick, color=orange, opacity=1] (0,0,0) -- 
(\RodLength,0,0)node[near end, below left] {$(T)$};
\coordinate[label=below right:$C$] (A1) at 
({\RodLength*\iBngle/180},0,0.3); 
\fill[blue,thick] (A1) circle (0.3pt);
\coordinate[label=above:$I_1$] (I1) at 
({\RodLength*\iBngle/180},0,0);%changed
\fill[blue,thick] (I1) circle (0.3pt);}
\end{scope}
\tdplotsetrotatedcoords{{\iAngle+130}}{90}{0} %<-
\begin{scope}[tdplot_rotated_coords]
\draw[pattern=north west lines, pattern color=blue, opacity=0.5 ] (A1) 
 circle (\relRad);
\node[] at (45:0.4cm){$D$};
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$k_1$};  %<-
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$i_1$};  %<-
\draw[-latex,blue] (A1) -- ++({-0.7*cos(\iBngle/\relRad+\iAngle)},0,{0.7*sin(\iBngle/\relRad+\iAngle)})node[right]{$i_2$}; %<-
\draw[-latex,blue] (A1) -- ++({-0.7*sin(\iBngle/\relRad)},0,{-0.7*cos(\iBngle/\relRad)})node[below]{$k_2$};  %<-
\end{scope}}{
\tdplotsetrotatedcoords{{\iAngle+\iBngle}}{00}{0} %<- changed that in order to rotate the rod
\begin{scope}[tdplot_rotated_coords]
\pgfmathparse{\RodLength*\iBngle/180}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\let\iar\pgfmathresult
\pgfmathparse{(\RodLength*\iBngle/360)-\iar}
\let\tar\pgfmathresult
\foreach \jar in {\iar, \tar, ...,\tar}{
\draw[ultra thick, color=orange, opacity=1] (0,0,0) -- 
(\RodLength,0,0)node[near end, below left] {$(T)$};
\coordinate[label=below right:$C$] (A1) at 
({\RodLength*\iBngle/180},0,0.3); 
\fill[blue,thick] (A1) circle (0.3pt);
\coordinate[label=above:$I_1$] (I1) at 
({\RodLength*\iBngle/180},0,0);%changed
\fill[blue,thick] (I1) circle (0.3pt);}
\end{scope}
\tdplotsetrotatedcoords{{\iAngle+130}}{90}{0} %<-
\begin{scope}[tdplot_rotated_coords]
\draw[pattern=north west lines, pattern color=blue, opacity=0.5 ] (A1) 
 circle (\relRad);
\node[] at (45:0.4cm){$D$};
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$k_1$};  %<-
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$i_1$};  %<-
\draw[-latex,blue] (A1) -- ++({-0.7*cos(\iBngle/\relRad+\iAngle)},0,{0.7*sin(\iBngle/\relRad+\iAngle)})node[right]{$i_2$}; %<-
\draw[-latex,blue] (A1) -- ++({-0.7*sin(\iBngle/\relRad)},0,{-0.7*cos(\iBngle/\relRad)})node[below]{$k_2$};  %<-
\end{scope}}
\end{tikzpicture}
}
\end{animateinline}
\end{document}

相关内容