
長い間、私は LaTeX がコマンドを展開する方法を理解していると思っていました。しかし、どうやらそうではないようです。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\edef\r{1 and 2}
\draw (0,0) ellipse (2 and 4); % this works
\draw (0,0) ellipse (\r); % this causes the error
\end{tikzpicture}
\end{document}
上記のコードをコンパイルしようとすると、次のエラーが発生します。
! Package PGF Math Error: Unknown operator `a' or `an' (in '1 and 2').
上記のエラーがなぜ発生するのか、またこの問題を回避するにはどうすればいいのかを教えていただけますか?
答え1
この問題はどこにでも存在するため、PGF は実際にこれを回避する標準的な方法を開発しています。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\edef\r{1 and 2}
\draw (0,0) ellipse (2 and 4); % this works
\edef\pgfmarshal{\noexpand\draw (0,0) ellipse (\r);}
\pgfmarshal
\end{tikzpicture}
\end{document}
(\pgf@marshal
パッケージ全体では232個あります。)