
アニメーションに使用する複数ページの PDF を TikZ で作成しています。作成中に、次のエラーが発生します。
! Missing number, treated as zero.
<to be read again>
問題を示す最小限の動作例 (MWE) を次に示します。
\documentclass[tikz]{standalone}
\begin{document}
\def\timesteps{10}
\foreach \timestep in {0,1,...,\timesteps} {
\begin{tikzpicture}
\path[draw] (0, 0) circle (1);
\def\initialx{-1};
\def\initialy{0};
\def\finalx{0.9};
\def\finaly{0};
\def\length{0.1};
\def\xi{{\initialx+(\finalx-\initialx)*(\timestep/\timesteps)}};
\def\yi{{\initialy+(\finaly-\initialy)*(\timestep/\timesteps)}};
\def\xf{{\initialx+(\finalx-\initialx)*(\timestep/\timesteps)+\length}}; % This line works ...
%\def\xf{{\xi+\length}}; % ... but this line does not ...
%\def\xf{{(\xi)+\length}}; % ... unless there are parentheses
\def\yf{{\yi}};
\path[draw, ->] (\xi, \yi) -- (\xf, \yf);
\end{tikzpicture}
}
\end{document}
MWEを実行すると、画面を横切る矢印のシンプルな11ページのPDFが出力されます。ここで、次の行をコメントアウトします。
\def\xf{{\initialx+(\finalx-\initialx)*(\timestep/\timesteps)+\length}};
そして、その行のコメントを解除します
\def\xf{{\xi+\length}};
数学的に同等だからです。前述のエラーが発生します。
! Missing number, treated as zero.
<to be read again>
私はこれを TikZ に関連して Google で検索しましたが、すべての回答で計算の前後に中括弧が必要であると書かれています。しかし、上記の行には中括弧があるので、それが問題だとは思いません。いろいろ試してみた結果、括弧で囲むと\xi
問題が解決することに気付きました。
\def\xf{{(\xi)+\length}};
したがって、私の質問は、なぜここで括弧が必要なのかということです。前に述べたように、計算が中括弧内であれば、他に特別なことは何も必要ないと考えていました。これについて説明している「公式」ドキュメントはありますか? 最後に、私は TikZ を初めて使用するので、自由にコードを改善してください。