1

Is there any way to define a new value that is a counter + a constant?

e.g.

\foreach\k in {0,1,...,7}
{
   \def\m    % ???? I want to make m=k+4
   \draw[->] (box\k) -- (box\m);
}
2
  • Please go also back to your list of questions: Many of them have answers, but you didn't accept them. – user31729 Feb 1 '18 at 19:06
  • @ChristianHupfer Thanks. It's frustrating, however, when the stackexchange software doesn't let you accept immediately; you have to come back later and that puts a barrier to being able to use the site efficiently. – Jason S Feb 1 '18 at 21:03
3

Since I can't use the coordinates box1 etc. here, I just print the values.

It is a common usage of \foreach for variables like \m, \k but I don't recommend that.

The calculation inside the loop and definition of \youshoulduseothermacronames is done with \numexpr\k+4 here.

\documentclass{article}

\usepackage{tikz}

\begin{document}
\foreach\k in {0,1,...,7}
{
  \def\youshoulduseothermacronames{\the\numexpr\k+4}    % ???? I want to make m=k+4
  \youshoulduseothermacronames\par

%   \draw[->] (box\k) -- (box\youshoulduseothermacronames);
}
\end{document}

Not the answer you're looking for? Browse other questions tagged or ask your own question.