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.
Unfortunately, TeX does not provide commands for such information; the only way to get such information is
- 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
- 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.
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.
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.)
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))"}"> $@