开发者

LaTeX command for last modified

开发者 https://www.devze.com 2022-12-17 16:14 出处:网络
Is there a LaTeX command that prints the \"last modified\" date of the actual document? Since LaTeX projects consist of more than开发者_StackOverflow中文版 one file this command ideally prints the dat

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


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.)


The package filemod seems to do exactly what you need. To get the last modified date of the file you just include the package in the usual way:

\usepackage{filemod}

and the modification time of the current document is printed by:

\filemodprintdate{\jobname}

you can also print the modification time, and there are many options to format the output.


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.


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.


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))"}"> $@


There is the getfiledate LaTeX package (it was part of my LaTeX distribution by default). It seems to be designed to automatically output a paragraph like:

The date of last modification of file misc-test1.tex was 2009-10-11  21:45:50.

with a bit of ability to tweak the output. You can definitely get just the date. However, I couldn't figure out how to get rid of newlines around the date and how to change the date format. To be honest I think the authors implemented it exactly for the single purpose they needed it, and it is rather cumbersome for general use.

0

精彩评论

暂无评论...
验证码 换一张
取 消