[NTG-context] Use date of the tex file in the document

Cecil Westerhof cldwesterhof at gmail.com
Thu Mar 24 18:42:12 CET 2011


2011/3/24 Philipp Gesang <pgesang at ix.urz.uni-heidelberg.de>

> >      {\ctalua{context(modification_date("\jobname.tex", "#1"))}}
>            ^
> s/\\ctalua/\\ctxlua/
>

I have:
\startluacode
  function modification_date(file, format)
    local f    = file
    local attr = lfs.attributes(f)

    assert (type(attr) == "table")
    if attr.mode ~= "directory" then
      if format == "long" then
        return os.date("%Y-%m-%d %H:%M",attr.modification)
      else
        return os.date("%Y-%m-%d",attr.modification)
      end
    end
  end
\stopluacode

\def\getdate
 {\dosingleempty\dogetdate}

\def\dogetdate[#1]%
 {\ctxlua{context(modification_date("\jobname.tex", "#1"))}}

\starttext

\getdate

\getdate{"short"}

\getdate{"long"}

\stoptext

This gives:
2011-03-24
2011-03-24"short"
2011-03-24"long"

-- 
Cecil Westerhof
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ntg.nl/pipermail/ntg-context/attachments/20110324/a598a489/attachment.html>


More information about the ntg-context mailing list