[OS X TeX] datetime
jkock
jkock at start.no
Thu Jul 13 19:06:09 EDT 2006
Hello,
Re date stamps, I just wanted to point out some alternative technology:
In my opinion, the \date command in latex is not particularly useful: often
it is quite uninteresting and confusing to know when the dvi or pdf file
was compiled -- the interesting bit of info really is the time the source
file was last modified.
For example if you find an old tex file on your hard disc and compile it,
it will get today's date stamp, even though the file was last modified
several years ago -- this goes also for some papers on the ArXiv eprint
server!
Hence the date stamping should not be tex's business. Rather, the text
editor should be in charge of inserting a date stamp whenever the source
file is saved to disk.
This functionality exists in Alpha for most programming modes, for which
the date stamp is simply written in a commented-out header of the file.
However, having the date stamp written a place where tex can grab it
requires a little tweaking of the functionality.
I use the following code snippet. To try it, paste it into your prefs.tcl
file, or your TeXprefs.tcl file:
proc ::TeX::dateStamp { name } {
set patt {\\def\\lastModified\{[^\}\r\n]{4,20}\}}
set datePos [search -n -r 1 -l [pos::math [minPos] + 20000] \
$patt [minPos]]
if { ![llength $datePos] } { return 0 }
set time [clock format [clock seconds] -format "%Y-%m-%d %H:%M"]
eval replaceText $datePos [list "\\def\\lastModified\{" $time "\}"]
return 1
}
hook::register saveHook TeX::dateStamp TeX
Now for this to be of any use, you need to have a declaration like this
in the preamble of your tex files:
\def\lastModified{2006-07-14 00:02}
and then, in the body of the document, where you want the date stamp, write
\lastModified
Now the code snippet above will trigger each time the document is saved,
then look for the \def\lastModified declaration, and subsitute the current
time into it, before actually saving the file.
(You can use the "Documents Projects" package in Alpha to have the
declaration inserted as part of the preamble template for TeX mode or for a
particular project.)
Of course you can modify the format of the date stamp to suit your taste,
(I think the format string "%Y-%m-%d %H:%M" is some standard posix stuff).
Clearly the same effect can be achieved in any other programmable editor
with event hooks.
Cheers,
Joachim.
-------------------------------------------------------------------------
Start.no tilbyr nå raskere bredbånd til lavere pris.
Sjekk http://www.start.no/bredband/ for mer informasjon
------------------------- Info --------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
& FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
More information about the MacOSX-TeX
mailing list