Text FormattingGetting date & time into logfile

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
BKthesis
Posts: 1
Joined: Mon Feb 13, 2012 9:50 pm

Getting date & time into logfile

Post by BKthesis »

I sometimes process my LaTex through a server for publication I want to get the current date and time into the log file. I've tried things such as:

Code: Select all

\usepackage{datetime}
\ClassWarning{}{Processing File... \today  \currenttime}%
\typeout{Processing File... \today  \currenttime}%
\newcommand*{\bkdatemsg}{Today is \today}%
\typeout{\bkdatemsg}%
\typeout{\today}%
But each time I get the text "\today" and not the commands' evaluated result.
Last edited by Stefan Kottwitz on Mon Feb 13, 2012 10:07 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Getting date & time into logfile

Post by cgnieder »

The commands \today and \currenttime need to be (fully) expanded first. However, as I tried to get a solution expanding them before I got errors. It seems they're not expandable.

So I came up with a solution using expl3 (which provides easy expansion control). You would need a rather new version of the l3kernel, I guess. I'm not sure since when \iow_log:n is provided.

Here's what I have:

Code: Select all

\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
% save original \today since the new one is not expandable:
\cs_set_eq:NN \lgt_file_date: \today

\usepackage{datetime}

% avoid \currenttime since it's not expandable:
\cs_new_nopar:Npn \lgt_file_time:
  {
    \lgt_get_time:N \currenthour :
    \lgt_get_time:N \currentminute :
    \lgt_get_time:N \currentsecond
  }

% add leading 0 if necessary:
\cs_new_nopar:Npn \lgt_get_time:N #1
  {
    \int_compare:nNnT { #1 } < { 10 } { 0 }
    \int_use:N #1
  }

% write to log file (argument is expanded first):
\iow_log:x
  { Processing~File... ~ \lgt_file_date: \tl_use:N \c_space_tl \lgt_file_time: }

% give a message:
% \ClassWarning { }
%   { Processing~File... ~ \lgt_file_date: \tl_use:N \c_space_tl \lgt_file_time: }
\ExplSyntaxOff

\begin{document}

bla

\end{document}
Regards
site moderator & package author
Post Reply