使用日历 \usepackage{montly} 输出生日年龄

使用日历 \usepackage{montly} 输出生日年龄

我想在日历上显示多个人的年龄。我可以通过 得到当前年份\the\year,但我不知道如何解决下面选项中的方程式( 的一部分birthdays.cld

 every 25 August {Mr. Kale's Birthday! \solvethismathproblem{\the\year - 1983 years old}}

谢谢

答案1

像这样吗?

\the\numexpr\year-1983将计算当前年份(只要寄存器\year没有被搞砸)和年份之间的差异1983并打印结果。

\documentclass{article}

\def\yearofbirth{1983}
\begin{document}

Foo is \the\numexpr\year-\yearofbirth\ year(s) old
\end{document}

在此处输入图片描述

这是一个更方便的方法,使用宏和不使用的方法\numexpr(这是一项e-TeX发明)

\documentclass{article}


\newcounter{agecntr}

\newcommand{\printage}[2][\year]{%
  \the\numexpr#1-#2%
}

\newcommand{\printageother}[2][\year]{%
  \setcounter{agecntr}{#1}%
  \addtocounter{agecntr}{-#2}%
  \theagecntr%
}
\def\yearofbirth{1983}
\begin{document}

Foo is \the\numexpr\year-\yearofbirth\ year(s) old

Foo is \printage{1980}\ year(s) old

Foo is \printageother{1974}\ year(s) old
\end{document}

相关内容