7

I would like to say, "I have played piano for 23 years" -- but this document will have to be changed every year so I remember to make it 23, then 24, then 25. Is there a way to do something like:

I have played piano for \calculate{\year - 1986} years.

Perhaps using the calc package and the \year command? I haven't been able to figure this out.

1

2 Answers 2

10

You can use the integer arithmetic of TeX too.

\documentclass{article}
\begin{document}
I've played the piano for \number\numexpr\year-1986\relax~years.
\end{document}
0
4

Just in case you are going to use tikz in your document, here is an overkill solution with this package.

\documentclass{article}
\usepackage{tikz}
\begin{document}
I have played piano for \pgfmathparse{int(\year-1986)}\pgfmathresult~years.
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .