![包 [日期時間] 不適用於](https://rvso.com/image/305763/%E5%8C%85%20%5B%E6%97%A5%E6%9C%9F%E6%99%82%E9%96%93%5D%20%E4%B8%8D%E9%81%A9%E7%94%A8%E6%96%BC%20.png)
以下是 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}
並將其報告給包作者。