Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Welcome to TeX.SX. –  Claudio Fiandrino Feb 3 '13 at 14:19
add comment

2 Answers 2

up vote 10 down vote accepted

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}
share|improve this answer
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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