如何使用 \today 创建小写的月份名称

如何使用 \today 创建小写的月份名称

我只想使用\today“2013 年 11 月 18 日”格式进行输出。使用 datetime 包,我可以使用以下命令获取“2013 年 11 月 18 日”:

 \documentclass[11pt,twoside,onecolumn,openany,final]{memoir}

 \usepackage[nodayofweek]{datetime}

 \newdateformat{mydate}{{\THEDAY}{ }\monthname[\THEMONTH] \THEYEAR}

 \begin{document}

 \mydate\today

 \end{document}

但此后,我无法成功创建小写的月份名称。我最接近的方法是添加\MakeLowercase以下命令:

{{\THEDAY}{ }\monthname\MakeLowercase[\THEMONTH] \THEYEAR}

但由于某种原因,它引入了数字,最终结果是这样的:

2013年11月18日[11]

再次,这仍然没有达到我的期望。有没有办法在这里正确地引入小写命令,以便对于任何给定的日期,\today格式输出都是

2013年11月18日

答案1

日期时间大写月份,您可以重新定义提取月份名称的适合语言的定义:

在此处输入图片描述

\documentclass[11pt,twoside,onecolumn,openany,final]{memoir}% http://ctan.org/pkg/memoir
\usepackage[nodayofweek]{datetime}% http://ctan.org/pkg/datetime
\newdateformat{mydate}{{\THEDAY}{ }\monthname[\THEMONTH] \THEYEAR}
\makeatletter
\renewcommand*{\monthnameenglish}[1][\month]{%
  \@orgargctr=#1\relax
  \ifcase\@orgargctr
  \PackageError{datetime}{Invalid Month number \the\@orgargctr}{Month
  numbers should go from 1 (january) to 12 (december)}%
  \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 \PackageError{datetime}{Invalid Month number \the\@orgargctr}{%
  Month numbers should go from 1 (january) to 12 (december)}%
  \fi
}
\makeatother
\begin{document}

\mydate\today

\end{document}

由于选择了默认语言,因此上述操作有效english。如果您对非标题大小写的“短月份名称”感兴趣,您还必须重新定义\shortmonthnameenglish

\renewcommand*{\shortmonthnameenglish}[1][\month]{%
  \@orgargctr=#1\relax
  \ifcase\@orgargctr
  \PackageError{datetime}{Invalid Month number \the\@orgargctr}{Month
  numbers should go from 1 (jan) to 12 (dec)}%
  \or jan%
  \or feb%
  \or mar%
  \or apr%
  \or may%
  \or jun%
  \or jul%
  \or aug%
  \or sept%
  \or oct%
  \or nov%
  \or dec%
  \else%
  \PackageError{datetime}%
  {Invalid Month number \the\@orgargctr}%
  {Month numbers should go from 1 (jan) to 12 (dec)}%
\fi
}

答案2

定义\Monthname,而不是\monthname

 \documentclass[11pt,twoside,onecolumn,openany,final]{memoir}
 \newcommand\Monthname[1][EMPTY]{%
  \ifnum1=#1january\else
  \ifnum2=#1february\else
  \ifnum3=#1march\else
  \ifnum4=#1april\else
  \ifnum5=#1may\else
  \ifnum6=#1june\else
  \ifnum7=#1july\else
  \ifnum8=#1august\else
  \ifnum9=#1september\else
  \ifnum10=#1october\else
  \ifnum11=#1november\else
  \ifnum12=#1december\else
  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
}
 \usepackage[nodayofweek]{datetime}

 \newdateformat{mydate}{{\THEDAY}{ }\Monthname[\THEMONTH] \THEYEAR}

 \begin{document}
\mydate\today

 \end{document}

相关内容