强制宏扩展

强制宏扩展

我已尽力去理解\expandafter\edef朋友,但我找不到使用它们强制扩展\FormatDate以下示例中传递给宏的参数的方法。

\documentclass{article}
\makeatletter
\def\@FormatDateAuxA#1/#2/#3 #4.{%
    % Day
            \number#3\relax\space
    % Month
            \ifcase#2{}?#2?\or
            January\or February\or March\or April\or
            May\or June\or July\or August\or
            September\or October\or November\or December\else
            ?#2?\fi\space
    % Year
            \ifnum#1>99{}#1\else\ifnum#1>9{}19#1\else190#1\fi\fi}
\def\@FormatDateAuxB#1$#2.{{
    \typeout{\noexpand#1}
    \@FormatDateAuxA#1 X.}}
\def\FormatDate#1{\@FormatDateAuxB#1$X.}
\makeatother
\begin{document}
\FormatDate{2015/4/15}
\def\Date{2015/4/15}
\FormatDate{\Date}
\end{document}

以上内容给出以下输出。

2015/4/15
\Date 
! Argument of \@FormatDateAuxA has an extra }.

\Date 尚未扩展,这(可能)已停止\@FormatDateAuxA工作参数的模式匹配。如能提供任何帮助,我们将不胜感激。

答案1

\documentclass{article}
\makeatletter
\def\@FormatDateAuxA#1/#2/#3 #4.{%
    % Day
            \number#3\relax\space
    % Month
            \ifcase#2{}?#2?\or
            January\or February\or March\or April\or
            May\or June\or July\or August\or
            September\or October\or November\or December\else
            ?#2?\fi\space
    % Year
            \ifnum#1>99{}#1\else\ifnum#1>9{}19#1\else190#1\fi\fi}
\def\@FormatDateAuxB#1$#2.{{
    \typeout{\noexpand#1}
    \@FormatDateAuxA#1 X.}}
\def\FormatDate#1{\expandafter\@FormatDateAuxB#1$X.}
                  %%%%%%%%%%%%%
\makeatother
\begin{document}
\FormatDate{2015/4/15}
\def\Date{2015/4/15}
\FormatDate{\Date}
\end{document}

相关内容