I want TikZ
to first compute and then display the value of a variable. The question is, for sake of simplicity, based on this concrete example from TeXample.net:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def \n {5}
\def \radius {3cm}
\def \margin {8} % margin in angles, depends on the radius
\foreach \s in {1,...,\n}
{
\node[draw, circle] at ({360/\n * (\s - 1)}:\radius) {$\s$};
\draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
}
\end{tikzpicture}
\end{document}
Suppose I messed up and I wanted my labels to run from 0 to n-1, instead of from 1 to n. How can I tell TikZ to first compute the difference or whatever operation on the variable, and then display it:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def \n {5}
\def \radius {3cm}
\def \margin {12} % margin in angles, depends on the radius
\foreach \s in {1,...,\n}
{
\node[draw, circle] at ({360/\n * (\s - 1)}:\radius) {$\s-1$};
\draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
}
\end{tikzpicture}
\end{document}
I even used a temporary auxiliary variable \r=\s-1 but it still prints the following instead the nodes' numbers from 0 to n-1:
Remark: I know the problem would be solved by defining another range for \s
, i.e. {0,...,\n-1}
but I already wrote a similar code (but long, so it wouldn't be a MWE if I post it) based on this, with dependence on the \s
and I wouldn't like to shift lot of times the variable to \s+1
in the somehow long formulas.