[OS X TeX] print the latex source filename

Peter Dyballa Peter_Dyballa at Web.DE
Sat Mar 21 11:15:21 CET 2009


Am 21.03.2009 um 03:41 schrieb Alain Schremmer:

> I haven't been able to make this code work. What does it do  
> compared to:
>
> \documentclass[11pt]{book}
> 			\usepackage{calc}
> 			\newcounter{hours}\newcounter{minutes}
> 			\newcommand{\printtime}%
> 			{%begin definition
> 				\setcounter{hours}{\time/60}%
> 				\setcounter{minutes}{\time-\value{hours}*60}%
> 				\thehours:\theminutes%
> 			}%end definition
> \begin{document}
> 	This file was saved as \jobname \hspace{1mm} on \today \hspace 
> {1mm} at \printtime.
> \end{document}


This records the time when the source file was compiled. The other  
code reflects the time when the source file was saved. This does make  
a difference: some time vs. a versioning time stamp. BTW: the compile  
time is usually recorded in the PDF output, so it's not that useful  
to put it also in the text body. You can see it on the command line  
with pdfinfo (from the xpdf software), you can see it in Finder's  
inspector (quite the same with ⌘-I), and you can also check it in  
Adobe or Acrobat Readers. For example:

	pete 574 /\ pdfinfo Beispiel.pdf
	Title:          An UTF-8 LaTeX Example
	Subject:        ISO Latin-1 and ISO Latin-9 characters
	Keywords:       LaTeX, UTF8, ISO, Latin-1, Latin-2, Latin-9, ISO  
8859, LICR
	Author:         Peter Dyballa
	Creator:        LaTeX with hyperref package
	Producer:       pdfTeX-1.40.9
	CreationDate:   Fri Mar 20 17:47:41 2009
	ModDate:        Fri Mar 20 17:47:41 2009
	Tagged:         no
	Pages:          4
	Encrypted:      no
	Page size:      841.89 x 595.276 pts (A4)
	File size:      141162 bytes
	Optimized:      no
	PDF version:    1.4
	pete 575 /\ ls -l Beispiel.pdf
	-rw-r--r--   1 pete  admin  141162 21 Mär 10:48 Beispiel.pdf

Although recently re-compiled the date of the source file's last  
change is recorded. You can have both times by commenting, for  
example, the line with ``pdfcreationdate={\@SourceFileDate},%´´ in  
the \hypersetup:

	Title:          An UTF-8 LaTeX Example
	Subject:        ISO Latin-1 and ISO Latin-9 characters
	Keywords:       LaTeX, UTF8, ISO, Latin-1, Latin-2, Latin-9, ISO  
8859, LICR
	Author:         Peter Dyballa
	Creator:        LaTeX with hyperref package
	Producer:       pdfTeX-1.40.9
	CreationDate:   Sat Mar 21 11:11:22 2009
	ModDate:        Sat Mar 21 11:11:11 2009
	Tagged:         no
	Pages:          4
	Encrypted:      no
	Page size:      841.89 x 595.276 pts (A4)
	File size:      141162 bytes
	Optimized:      no
	PDF version:    1.4


To implement it, in the preamble:

\documentclass[]{<somecls>}

     \usepackage{hyperref}						% necessary
     \makeatletter
     \@ifundefined{pdffilemoddate}{%
        \PackageError{sourcetime}{%
          pdfTeX >= 1.30.0 required%
        }%
        \let\pdffilemoddate\@gobble
     }{}%
     \newcommand*{\SourceFile}[1]{%
       \edef\@SourceFileDate{\pdffilemoddate{#1}}%
       % empty in case of errors, but don't harm in next comparison
       \ifnum\pdfstrcmp{\@SourceFileDate}{\@CurrentSourceFileDate}>0 %
         \let\@CurrentSourceFileDate\@SourceFileDate
         \expandafter\@ParseDate\@SourceFileDate\@nil
         \hypersetup{%
           pdfcreationdate={\@SourceFileDate},%
           pdfmoddate={\@SourceFileDate}%
         }%
         \PackageInfo{sourcetime}{%
           Using file `#1'%
         }%
       \fi
     }
     \newcommand*{\@CurrentSourceFileDate}{}			% produces date form  
for PDF info
     \expandafter\def\expandafter\@ParseDate\detokenize{D:} 
#1#2#3#4#5#6#7#8{%
       \year=#1#2#3#4\relax
       \month=#5#6\relax
       \day=#7#8\relax
       \@ParseTime
     }
     \def\@ParseTime #1#2#3#4#5\@nil{%
       \time=\numexpr #1#2 * 60 + #3#4\relax
     }
     \makeatother
     \SourceFile{\jobname.tex}						% execution

\begin{document}
This is a text body!
\end{document}


What are the errors you get?

--
Greetings

   Pete

A common mistake that people make when trying to design something  
completely foolproof is to underestimate the ingenuity of complete  
fools.


-------------- next part --------------
----------- Please Consult the Following Before Posting -----------
TeX FAQ: http://www.tex.ac.uk/faq
List Reminders and Etiquette: http://email.esm.psu.edu/mac-tex/
List Archive: http://tug.org/pipermail/macostex-archives/
TeX on Mac OS X Website: http://mactex-wiki.tug.org/
List Info: http://email.esm.psu.edu/mailman/listinfo/macosx-tex



More information about the macostex-archives mailing list