程序包 [datetime] 无法与 [titling] 配合使用

程序包 [datetime] 无法与 [titling] 配合使用

以下是 SSCCE:

\documentclass{report}

\usepackage{datetime}
%\usepackage{titling} %if this line is uncommented compilation fails

\begin{document}
\newdate{date2}{08}{02}{2015}
\date{\displaydate{date2}}
foo
\end{document}

... 上述代码可以编译,但如果包中调用的行titling没有注释,编译就会失败:

pdflatex esa-sre-gedais-sdp.tex
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
(./esa-sre-gedais-sdp.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
(/usr/share/texmf-texlive/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo))
(/usr/share/texmf-texlive/tex/latex/datetime/datetime.sty
(/usr/share/texmf-texlive/tex/latex/fmtcount/fmtcount.sty
(/usr/share/texmf-texlive/tex/latex/base/ifthen.sty)
(/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty)
(/usr/share/texmf-texlive/tex/latex/amsmath/amsgen.sty)
(/usr/share/texmf-texlive/tex/latex/fmtcount/fc-english.def)
(/usr/share/texmf-texlive/tex/latex/fmtcount/fc-USenglish.def)
No configuration file fmtcount.cfg found.
)) (/usr/share/texmf-texlive/tex/latex/titling/titling.sty)
(./esa-sre-gedais-sdp.aux))
! Incomplete \iffalse; all text was ignored after line 8.
<inserted text> 
                \fi 
<*> esa-sre-gedais-sdp.tex

? X
No pages of output.
Transcript written on esa-sre-gedais-sdp.log.
make: *** [all] Error 1

答案1

我不知道这两个包在做什么,但如果有疑问,请添加\protect。此操作运行无错误:

\documentclass{report}

\usepackage{datetime}
\usepackage{titling} %if this line is uncommented compilation fails

\begin{document}
\newdate{date2}{08}{02}{2015}
\date{\protect\displaydate{date2}}
foo
\end{document}

答案2

datetime包对于哪些命令应该是健壮的或不是健壮的有着特殊的选择。例如,它将 和类似的命令声明\longdate\shortdate健壮的(它们可能不应该),但它对\displaydate可能用于移动参数的命令没有做同样的事情。

因此包应该

\DeclareRobustCommand*{\displaydate}[1]{%
\@ifundefined{date@#1@y}{%
\PackageError{datetime}{Date `#1' not defined}{}}{%
\formatdate{\csname date@#1@d\endcsname}{%
\csname date@#1@m\endcsname}{%
\csname date@#1@y\endcsname}}}

因为此命令使用\formatdate执行分配的命令,并且在(重新)定义时未声明为健壮的(也是\PackageError罪魁祸首)。不幸的是,该包改用\newcommand

您可以使用以下方法修复此问题etoolbox

\documentclass{report}

\usepackage{etoolbox}
\usepackage{datetime}
\usepackage{titling} %if this line is uncommented compilation fails

\robustify{\displaydate} % make \displaydate robust

\begin{document}
\newdate{date2}{08}{02}{2015}

\title{Title}
\author{Author}
\date{\displaydate{date2}}

\maketitle

foo

\end{document}

并将此情况报告给软件包作者。

在此处输入图片描述

相关内容