Why is the graph drawn by the first code good, while the second code looks not good? In in the first one I use \the\numexpr \relax
, and in the second code I use \tikzmath
.
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{ifthen}
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,2,3,4,5} {
%\node[draw,circle,minimum size=1cm,fill=blue!20] (\i) at (
% \i*360/5:1cm ) {$\i$};
\node[draw,circle,minimum size=0.5cm,fill=blue!20] (\i) at ({
72*(\i-1)}:1cm) {$\i$};}
\foreach \i in {1,2,3,4,5} {
\ifthenelse{\i<5}{ \draw (\i) -- ( \the\numexpr \i+1 \relax );}{ \draw (\i)
-- (1);}
}
\end{tikzpicture}
\end{document}
\documentclass{article}
\usepackage{ifthen}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,2,3,4,5} {
\node[draw,circle,minimum size=0.5cm,fill=blue!20] (\i) at (72*\i-36:1cm)
{$\i$};};
\foreach \i in {1,2,3,4,5} {
\tikzmath{\j=\i+1;}
\ifthenelse{\i<5}{ \draw (\i) -- ( \j );}{ \draw
(\i) -- (1);}
};
\end{tikzpicture}
\end{document}
My expectation is that the two outputs should be consistent.
print{\j};
.\show\j
,\typeout{\j}
, or\showtokens\expandafter{\j}
, that prints to the command-line. They all do slightly different things, documentation are in TeXbook/LaTeX reference manual/e-TeX manual.