![不使用包,定义函数 \lastMonth 为上个月,上个月的年份 LaTeX](https://linux22.com/image/480302/%E4%B8%8D%E4%BD%BF%E7%94%A8%E5%8C%85%EF%BC%8C%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0%20%5ClastMonth%20%E4%B8%BA%E4%B8%8A%E4%B8%AA%E6%9C%88%EF%BC%8C%E4%B8%8A%E4%B8%AA%E6%9C%88%E7%9A%84%E5%B9%B4%E4%BB%BD%20LaTeX.png)
使用这种格式,我该如何将月份指定为上个月/年而不是当前月份/年?例如,如果我明天(01/01)运行它,\lastMonth = 2022 年 1 月,但我需要它是 \lastMonth = 2021 年 12 月。
\documentclass{article}
\newcommand{\lastMonth}{\ifcase \month \or January\or February\or March\or %
April\or May \or June\or July\or August\or September\or October\or November\or %
December\fi, \number \year}
\begin{document}
\lastMonth
\end{document}
答案1
只需将月份名称向下移动并从一月份的年份中减去 1
\documentclass{article}
\newcommand{\lastMonth}{\ifcase \month\or %
December\or January\or February\or March\or %
April\or May\or June\or July\or August\or September\or
October\or November\fi, \number \numexpr\year\ifnum\month=1 -1\fi\relax}
\begin{document}
\lastMonth
\def\month{1}
\lastMonth
\end{document}