tags:

views:

231

answers:

4

Is there a LaTeX command that prints the "last modified" date of the actual document? Since LaTeX projects consist of more than one file this command ideally prints the date of the actual file, not that of the project.

+2  A: 

Unfortunately, TeX does not provide commands for such information; the only way to get such information is

  1. by running a non-TeX script to create a TeX file before running LaTeX and including this file in your main LaTeX document somehow, or
  2. by running the external script from TeX (which only works if the so-called write18 or shellescape feature is enabled; you'd have to consult the manual of your TeX implementation for this, and not have a stubborn sysadmin).

It is possible that extended TeXs do support file info commands (luaTeX perhaps?), but it's not part of TeX proper.

Ruben
No-one (basically) uses Knuth's original TeX to process LaTeX documents these days; pdfTeX is helpful here. See my answer below.
Will Robertson
+3  A: 

If you are using an automated build system, you could ask it to generate a file (perhaps named today.sty) which depends on all the source files.

In make that might look like:

today.sty: $LATEX_SRCS
        echo "\date{" > $@
        date +D >> $@
        echo "}" >> $@

and \usepackage{today.sty}.

The will use the date of the first build after a file changes, and won't update until either you delete today.sty or alter another source file.

dmckee
Neat idea! `:)`
Will Robertson
+5  A: 

pdfTeX provides the primitive \pdffilemoddate to query this information for files. (LuaTeX uses its own Lua functions for the same thing.) Since pdfTeX is used by default in all LaTeX distributions in the last few years (at least), there's no harm in using the new functionality unless you're dealing with very old production systems. Here's an example:

\documentclass{article}
\begin{document}
\def\parsedate #1:20#2#3#4#5#6#7#8\empty{20#2#3/#4#5/#6#7}
\def\moddate#1{\expandafter\parsedate\pdffilemoddate{#1}\empty}
this is the moddate: \moddate{\jobname.tex}
\end{document}

(Assuming the file has been modified since year 2000.)

Will Robertson
Xetex supports this as well. I'm fairly sure that Etex does not.
Charles Stewart
Actually, I don't think XeTeX does support `\pdffilemoddate`; XeTeX only has partial overlap with pdfTeX's "new" primitives (see `texdoc xetexref`). eTeX does not support it either, but only old distributions use eTeX as an engine for LaTeX. (Even in DVI mode, pdfTeX is used nowadays.)
Will Robertson
A: 

thank dmckee

LATEX_SRCS = test.tex

define moddate
date +%Y%m%d%H%M%S
endef

today.sty: $(LATEX_SRCS)
    @echo "\def\moddate{"$(shell $(moddate))"}"> $@
overlord