为什么 \the\day 在我的宏中不起作用?

为什么 \the\day 在我的宏中不起作用?

(TeX 代码!)

我定义了一个 TeX 宏来比较日期和时间值。一切运行正常,直到我输入\the\day来调用它的当前值。有人能想象为什么它适用于除 之外的所有日期和时间函数\the\day吗?

    %transformations of \time
\newcount\hour  %
\newcount\hours  %
\newcount\minutes  %
\hour=\time \divide\hour by 60 
\minutes=\time
\hours=\hour \multiply\hours by 60 
\advance \minutes by -\hours
%end transformations of \time
%begin  definitions of caldate
\newcount\fromcalyear %% 
\newcount\fromcalmonth %%
\newcount\fromcalday %%
\newcount\fromcalhour %%
\newcount\fromcalminutes %%
\newcount\tocalyear %% 
\newcount\tocalmonth %%
\newcount\tocalday %%
\newcount\tocalhour %%
\newcount\tocalminutes %%
\newcount\rescalyear %% 
\newcount\rescalmonth %%
\newcount\rescalday %%
\newcount\rescalhour %%
\newcount\rescalminutes %%
\def\fromcaldate[#1-#2-#3 #4:#5]{%
\global\fromcalyear=#1 %
\global\fromcalmonth=#2 %
\global\fromcalday=#3 %
\global\fromcalhour=#4 %
\global\fromcalminutes=#5 %
\ \the\fromcalyear-\ifnum\fromcalmonth<10
0\fi\the\fromcalmonth-\ifnum\fromcalday<10
0\fi\the\fromcalday\ \ifnum\fromcalhour<10
0\fi\the\fromcalhour:\ifnum\fromcalminutes<10 0\fi\the\fromcalminutes
\vskip0.1\baselineskip}% 
\def\tocaldate[#1-#2-#3 #4:#5]{%
\global\tocalyear=#1 %
\global\tocalmonth=#2 %
\global\tocalday=#3 %
\global\tocalhour=#4 %
\global\tocalminutes=#5\ % 
\the\tocalyear-\ifnum\tocalmonth<10
0\fi\the\tocalmonth-\ifnum\tocalday<10
0\fi\the\tocalday\ \ifnum\tocalhour<10
0\fi\the\tocalhour:\ifnum\tocalminutes<10 0\fi\the\tocalminutes}
\def\rescaldate{
\global\rescalyear=\the\fromcalyear %
\global\rescalmonth=\fromcalmonth %
\global\rescalday=\fromcalday %
\global\rescalhour=\fromcalhour %
\global\rescalminutes=\fromcalminutes %
\advance\rescalyear by -\tocalyear %
\global\advance\rescalmonth by -\tocalmonth  %
\global\advance\rescalday by -\tocalday   %
\global\advance\rescalhour by -\tocalhour   %
\global\advance\rescalminutes by -\tocalminutes   %
\vskip0.1\baselineskip}% 
\def\rescaldatetime{\rescaldate (\the\rescalyear)-(\the\rescalmonth)-(\the\rescalday)\ (\the\rescalhour):(\the\rescalminutes)}
%end definitions of caldate
Here, the day is displayed: {\bf \the\day}
\vskip1\baselineskip
Below, it works without calling the day by function

From Date: \fromcaldate[\the\year-\the\month-11 \the\hour:\the\minutes]
To Date: \tocaldate[2012-11-05 04:16]

Res Date: \rescaldatetime
\vskip1\baselineskip

Below, it does not work with calling the day by function (outcommented)

%Fromdate: \fromcaldate[\the\year-\the\month-\the\day 13:00]
%Fromdate: \fromcaldate[\the\year-\the\month-\the\day \the\hour:\the\minutes]
%Todate: \tocaldate[\the\year-\the\month-\the\day \the\hour:\the\minutes]

%Resdate: \rescaldatetime

\bye

答案1

你有

\def\tocaldate[#1-#2-#3 #4:#5]{%

所以后面必须有一个空格标记#3

Fromdate: \fromcaldate[\the\year-\the\month-\the\day 13:00]

上面的内容之前没有空格标记,13因为文件中的空格在标记时被吸收了\day

使用

Fromdate: \fromcaldate[\the\year-\the\month-{\the\day} 13:00]

相关内容