[Tex/LaTex] Define a variable and add 1 to it’s value

calculationstex-coretikz-pgf

I'm programming a calendar in LaTeX and as it should be used for my univertsity planning, I want to split it up in semesters. So on one page there are the months from September to February and on the second page, there will be the months March to August.

To have a dynamic code which I don't have to touch after finishing the calandar, I'm defining all the variables that will be used in the preamble.

For example

\def\year{2017}

This variable is later called by the Tikz calendar. My problem is, that the version of the calendar spreads over two different years. My idea was to define a second variable \def\nextyear which is equal to \year + 1. Unfortunately \def\nextyear{\year+1} returns 2017+1 instead of 2018

How can I add one year to my variable?

Best Answer

Using \pgfmathtruncatemacro makes the trick.

\documentclass{standalone}
\usepackage{amsmath,tikz}
\usetikzlibrary{arrows,calc}

\begin{document}
  \begin{tikzpicture}
  \def \currentYear {2016}
  \def \n {4}
  \foreach \i in {0,...,\n}
  {

  \pgfmathtruncatemacro{\nextYear}{\currentYear + \i}
  \node (N) at (\i,\i) {\nextYear};
  }
  \end{tikzpicture}

\end{document}

enter image description here

Related Question