latex 中的 advancedate 和 ifthenelse

latex 中的 advancedate 和 ifthenelse

我正在尝试为仅在一周中的某些日子(M、W)上课的课程编写课程大纲。我想检查课程日期,并根据日期将其提前 2 天或 5 天。以下代码似乎不起作用(语句失败\ifthenelse

\documentclass{article}
\usepackage{advdate}
\usepackage[ddmmyyyy]{datetime}
\usepackage{tikz}

\newdateformat{syldate}{\THEMONTH/\THEDAY%(\shortdayofweekname%{\THEDAY}{\THEMONTH}{\THEYEAR})}

 \newcommand{\class}[1]{  
 \def \currday {\shortdayofweekname{\the\day}{\the\month}{\the\year}}
 \ifthenelse{\equal{\currday}{Mon}}{\AdvanceDate[2]}{\AdvanceDate[5]}
 \section* {\syldate{\today} \quad #1}
 }

 \SetDate[06/01/2014]

 \begin{document}
 \class{First Class} 
 \class{Second class}
 \class{Class after holiday}

 \end{document}

我之所以要这样做,是因为我想检查是否\today在假期列表中,如果是,则自动前进到下一个上课日。有什么建议吗?如果有更高效的代码就更好了。

答案1

希望这就是你所追求的:

在此处输入图片描述

\documentclass{article}
\usepackage[ddmmyyyy]{datetime}% http://ctan.org/pkg/datetime
\usepackage{advdate}% http://ctan.org/pkg/advdate

\newdateformat{syldate}{\THEMONTH/\THEDAY/\THEYEAR}%(\shortdayofweekname%{\THEDAY}{\THEMONTH}{\THEYEAR})}

\newsavebox{\MONDAY}\savebox{\MONDAY}{Mon}% Mon

\makeatletter
\newcommand{\cleardate}[1]{%
  \expandafter\let\csname date@#1@d\endcsname\relax% Clear day
  \expandafter\let\csname date@#1@m\endcsname\relax% Clear month
  \expandafter\let\csname date@#1@y\endcsname\relax% Clear year
}
\makeatother

\newcommand{\class}[1]{%
  \cleardate{mydate}% Clear date
  \newdate{mydate}{\the\day}{\the\month}{\the\year}% Store date
  \section*{\displaydate{mydate} \quad #1}% Set heading
  \setbox1=\hbox{\shortdayofweekname{\getdateday{mydate}}{\getdatemonth{mydate}}{\getdateyear{mydate}}}%
  \ifdim\wd1=\wd\MONDAY
    \AdvanceDate[2]
  \else
    \AdvanceDate[5]
  \fi%
}

\SetDate[06/01/2014]

\begin{document}

\class{First class}
\class{Second class}
\class{Third class}
\class{Fourth class}
\class{Fifth class}
\class{Sixth class}
\class{Seventh class}

\end{document}

该过程将数据存储在mydate连接接口中datetimeadvdate。通过测试单词的宽度来与星期几进行比较Mon。每个三字母/短日期的长度不同:

在此处输入图片描述

相关内容