ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Use date of the tex file in the document
Date: Thu, 24 Mar 2011 11:22:02 +0100	[thread overview]
Message-ID: <20110324102202.GD3626@orcus> (raw)
In-Reply-To: <AANLkTikNcE1GvWqcH6b1rkz-43wfeULfgMjW1SNVC3yv@mail.gmail.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 1041 bytes --]

On 2011-03-24 <10:26:00>, Cecil Westerhof wrote:
> I would like to use the date of the document in the generated PDF. (It is
> not interesting when the PDF is generated, but when the source was last
> changed.) How would I do this?

Hi Cecil,

this solution checks only the main file, you’d have to extend it
if you want it to respect included parts as well.

Regards, Philipp

PS: Could be optimized but this way the main function allows for
    lazily adjusting the output …

> 
> -- 
> Cecil Westerhof

> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________


[-- Attachment #1.1.2: changed.tex --]
[-- Type: text/x-tex, Size: 1547 bytes --]

\startluacode
  documentdata = documentdata or { }
  documentdata.changed = documentdata.changed or { }
  local p = io.popen("ls -l --time-style=long-iso \jobname.tex", "r")
  local time = p:read("*all")
  p:close()

  local P, R, V = lpeg.P, lpeg.R, lpeg.V
  local C, Ct = lpeg.C, lpeg.Ct

  local p_lsout = P{
    [1] = "lsout",
    lsout = V"before" * V"date",
    before = (1 - V"date")^1,
    date  = Ct(C(V"four")
                 * V"hyphen"
                 * C(V"two")
                 * V"hyphen"
                 * C(V"two")
                 * V"space"
                 * Ct(C(V"two")
                        * P":"
                        * C(V"two"))),
    hyphen  = P"-",
    space   = P" ",
    four    = V"digit" * V"digit" * V"digit" * V"digit",
    two     = V"digit" * V"digit",
    digit   = R"09",
  }
  
  local changed = p_lsout:match(time)

  function documentdata.changed.get_changed ()
    if documentdata.changed.__last_changed then
      return documentdata.changed.__last_changed end
    local dateform = {
      changed[3],
      ".",
      changed[2],
      ".",
      changed[1],
      "\\space ",
      changed[4][1],
      ":",
      changed[4][2],
    }
    local datestr = table.concat(dateform)
    documentdata.changed.__last_changed = datestr
    return datestr
  end
\stopluacode

\unexpanded\def\getdate{%
  \ctxlua{context(documentdata.changed.get_changed())}%
}

\starttext

The source of this file was last modified {\os\getdate}.

\stoptext

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2011-03-24 10:22 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-24  9:26 Cecil Westerhof
2011-03-24 10:22 ` Philipp Gesang [this message]
2011-03-24 10:56   ` Cecil Westerhof
2011-03-24 11:00   ` Marco
2011-03-24 16:09     ` Cecil Westerhof
2011-03-24 16:12       ` Aditya Mahajan
2011-03-24 16:29         ` Cecil Westerhof
2011-03-24 16:33           ` Wolfgang Schuster
2011-03-24 17:15             ` Cecil Westerhof
2011-03-24 17:29               ` Philipp Gesang
2011-03-24 17:42                 ` Cecil Westerhof
2011-03-24 17:50                   ` Philipp Gesang
2011-03-24 20:41                     ` Cecil Westerhof
2011-03-24 23:08                   ` Cecil Westerhof
2011-03-24 23:30                     ` Hans Hagen
2011-03-25  0:33                       ` Philipp Gesang
2011-03-24 17:30               ` Marco
2011-03-24 18:35                 ` Hans Hagen
2011-03-24 17:42             ` Florian Wobbe
2011-03-24 17:47               ` Aditya Mahajan
2011-03-24 17:59                 ` Florian Wobbe
2011-03-24 20:49                   ` Aditya Mahajan
2011-03-24 21:43                     ` Florian Wobbe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110324102202.GD3626@orcus \
    --to=pgesang@ix.urz.uni-heidelberg.de \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).