There is no
\pdfcreationdate command in XeTeX as in pdfTeX and LuaTeX. There is a technical reason, for this: the PDF file is produced by XeTeX in an asynchronous way, delivering the pages produced in
xdv format to
xdvipdfmx. In general, these files are kept in a temporary directory and the PDF is finally moved to the current directory at the end.
One could use the shell escape, checking the date of creation of the
.log file, which is opened at the start of the job, but this would be system dependent.
\pdfcreationdate in XeTeX
We can use LuaTeX also from XeTeX (or XeLaTeX)! Create the following file
Then put the following code before loading
creationdate.timestamp will be removed, if existent, and a new one created with the current time in it, in a format similar to that produced by
\pdfcreationdate in pdfTeX. Then it will be read in; the time shown will be that of the execution of the script. However, any recent TeX distribution should have
texlua (because it has
luatex), so this should be as system independent as possible.
Actually, what's written in
creationdate.timestamp is something like
and then its contents is massaged a bit to get it into, essentially,
that's the format requested by
D must have category code 12, because such is the one produced by
\pdfcreationdate in (pdf|Lua)TeX).
A complete example, to be run with
--shell-escape, as always (otherwise
\pdfcreationdate will not be defined and
datetime will show seconds as "00"); the macros do nothing if
\pdfcreationdate is already present (so using
luatex as engines).
An alternative way on Unix systems
Unfortunately, XeTeX doesn't sport the pdfTeX feature of
\input|<command>, so an indirect way has to be taken, creating an auxiliary file to be read in.
- Create a shell script
rm -f $1.timestamp
date -r `stat -f '%m' -t '%s' $1.log` '+D:%Y%m%d%H%M%S+000000' > $1.timestamp
- Give the file the executable bit
chmod u+x creationdate.sh
Put the following in the file before loading
Then your commands will give the required result. Of course one must check that
date accept the required command line options.
XeLaTeX must be run with the
-shell-escape command line option, of course. If it isn't, then the behavior will be as without
\pdfcreationdate available, that is, the seconds will always be "00". If the file is processed with pdfLaTeX or LuaLaTeX, this definition of
\pdfcreationdate will be ignored and
datetime will be happy nonetheless, as those engines already have
On Windows a suitable batch script can be devised.