客观的

客观的

客观的

允许我写入自定义日志数据的函数。结果是命令\writeToLog(参见 MWE),该命令将其输入写入文件log.txt

问题

在我的实际文档中,我使用的是包datetime。如果我注释掉\usepackage{datetime},编译工作正常。如果没有注释掉,我会得到错误

! Incomplete \iffalse; all text was ignored after line 15.

为什么会发生这种情况?该如何解决?

平均能量损失

\documentclass{book}

\usepackage{datetime}

% Creates a file called log.txt
\newwrite\logFile
\immediate\openout\logFile=log.txt
\newcommand{\writeToLog}[1]{
    \immediate\write\logFile{#1}
}
\AtEndDocument{
    \immediate\closeout\logFile
}

% I'd like to log the compilation date, among other things
\writeToLog{Compiled on \today}

\begin{document}

Content

\end{document}

编辑

我也尝试使用datetime2下面的 MWE,但是这会写

Compiled on 9\, \DTMmonthname {11} 2022

我如何确保它输出Compiled on 9 November 2022

\documentclass{book}

\usepackage[calc]{datetime2}

% Set date format
\DTMnewdatestyle{mydateformat}{%
  \renewcommand{\DTMdisplaydate}[4]{%
    \number##3\, \DTMmonthname{##2} \number##1%
  }%
  \renewcommand{\DTMDisplaydate}{\DTMdisplaydate}%
}
\DTMsetdatestyle{mydateformat}

% Creates a file called log.txt
\newwrite\logFile
\immediate\openout\logFile=log.txt
\newcommand{\writeToLog}[1]{
    \write\logFile{#1}
}
\AtEndDocument{
    \closeout\logFile
}

\writeToLog{Compiled on \today}

\begin{document}

\today

\end{document}

相关内容