ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Use date of the tex file in the document
@ 2011-03-24  9:26 Cecil Westerhof
  2011-03-24 10:22 ` Philipp Gesang
  0 siblings, 1 reply; 23+ messages in thread
From: Cecil Westerhof @ 2011-03-24  9:26 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 198 bytes --]

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?

-- 
Cecil Westerhof

[-- Attachment #1.2: Type: text/html, Size: 224 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24  9:26 Use date of the tex file in the document Cecil Westerhof
@ 2011-03-24 10:22 ` Philipp Gesang
  2011-03-24 10:56   ` Cecil Westerhof
  2011-03-24 11:00   ` Marco
  0 siblings, 2 replies; 23+ messages in thread
From: Philipp Gesang @ 2011-03-24 10:22 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 10:22 ` Philipp Gesang
@ 2011-03-24 10:56   ` Cecil Westerhof
  2011-03-24 11:00   ` Marco
  1 sibling, 0 replies; 23+ messages in thread
From: Cecil Westerhof @ 2011-03-24 10:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 578 bytes --]

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

> 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?
>
> this solution checks only the main file, you’d have to extend it
> if you want it to respect included parts as well.
>

For this moment it is good enough. In the future I'll change it to generate
different formats. (I'll post it here.)

-- 
Cecil Westerhof

[-- Attachment #1.2: Type: text/html, Size: 888 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 10:22 ` Philipp Gesang
  2011-03-24 10:56   ` Cecil Westerhof
@ 2011-03-24 11:00   ` Marco
  2011-03-24 16:09     ` Cecil Westerhof
  1 sibling, 1 reply; 23+ messages in thread
From: Marco @ 2011-03-24 11:00 UTC (permalink / raw)
  To: ntg-context

On 2011-03-24 Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> wrote:

This should also work:

\starttext

\startluacode
  function modification_date (file)
    local f = file
    local attr = lfs.attributes (f)
    assert (type(attr) == "table")
    if attr.mode ~= "directory" then
      return os.date("%Y-%m-%d %H:%M",attr.modification)
    end
  end
\stopluacode

\unexpanded\def\getdate{%
  \ctxlua{context(modification_date ("\jobname.tex"))}%
}

\getdate

\stoptext


Marco


___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 11:00   ` Marco
@ 2011-03-24 16:09     ` Cecil Westerhof
  2011-03-24 16:12       ` Aditya Mahajan
  0 siblings, 1 reply; 23+ messages in thread
From: Cecil Westerhof @ 2011-03-24 16:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 844 bytes --]

2011/3/24 Marco <netuse@lavabit.com>

> On 2011-03-24 Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> wrote:
>
> This should also work:
>
> \starttext
>
> \startluacode
>  function modification_date (file)
>    local f = file
>    local attr = lfs.attributes (f)
>    assert (type(attr) == "table")
>    if attr.mode ~= "directory" then
>      return os.date("%Y-%m-%d %H:%M",attr.modification)
>    end
>  end
> \stopluacode
>
> \unexpanded\def\getdate{%
>  \ctxlua{context(modification_date ("\jobname.tex"))}%
> }
>
> \getdate
>
> \stoptext
>

I would like to do something like the following:
    \getdate would return os.date("%Y-%m-%d",attr.modification)
and
    \getdate{"long"} would return os.date("%Y-%m-%d
%H:%M",attr.modification)

I have looked at lua, but do not see how to do it. (Something else to
learn.)

-- 
Cecil Westerhof

[-- Attachment #1.2: Type: text/html, Size: 1332 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 16:09     ` Cecil Westerhof
@ 2011-03-24 16:12       ` Aditya Mahajan
  2011-03-24 16:29         ` Cecil Westerhof
  0 siblings, 1 reply; 23+ messages in thread
From: Aditya Mahajan @ 2011-03-24 16:12 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, 24 Mar 2011, Cecil Westerhof wrote:

> 2011/3/24 Marco <netuse@lavabit.com>
>
>> On 2011-03-24 Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> wrote:
>>
>> This should also work:
>>
>> \starttext
>>
>> \startluacode
>>  function modification_date (file)
>>    local f = file
>>    local attr = lfs.attributes (f)
>>    assert (type(attr) == "table")
>>    if attr.mode ~= "directory" then
>>      return os.date("%Y-%m-%d %H:%M",attr.modification)
>>    end
>>  end
>> \stopluacode
>>
>> \unexpanded\def\getdate{%
>>  \ctxlua{context(modification_date ("\jobname.tex"))}%
>> }
>>
>> \getdate
>>
>> \stoptext
>>
>
> I would like to do something like the following:
>    \getdate would return os.date("%Y-%m-%d",attr.modification)
> and
>    \getdate{"long"} would return os.date("%Y-%m-%d
> %H:%M",attr.modification)
>
> I have looked at lua, but do not see how to do it. (Something else to
> learn.)

Untested:

\def\getdate%
   {\dosinglegroupempty\dogetdate}

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

and then in the lua code

function modification_date(file, format)
....
if format == "long" then
....
else
...
end

end

Aditya
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 16:12       ` Aditya Mahajan
@ 2011-03-24 16:29         ` Cecil Westerhof
  2011-03-24 16:33           ` Wolfgang Schuster
  0 siblings, 1 reply; 23+ messages in thread
From: Cecil Westerhof @ 2011-03-24 16:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1225 bytes --]

2011/3/24 Aditya Mahajan <adityam@umich.edu>

>   \getdate would return os.date("%Y-%m-%d",attr.modification)
>> and
>>   \getdate{"long"} would return os.date("%Y-%m-%d
>> %H:%M",attr.modification)
>>
>> I have looked at lua, but do not see how to do it. (Something else to
>> learn.)
>>
> I would like to do something like the following:
>
> Untested:
>
> \def\getdate%
>  {\dosinglegroupempty\dogetdate}
>
> \def\dogetdate#1%
>   {context{modification_date("\jobname.tex", "#1")}}
>
> and then in the lua code
>
> function modification_date(file, format)
> ....
> if format == "long" then
> ....
> else
> ...
> end
>
> end
>

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%
 {\dosinglegroupempty\dogetdate}

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

This results in:
    contextmodification_date("subversion.tex", "")

-- 
Cecil Westerhof

[-- Attachment #1.2: Type: text/html, Size: 1933 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  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:42             ` Florian Wobbe
  0 siblings, 2 replies; 23+ messages in thread
From: Wolfgang Schuster @ 2011-03-24 16:33 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 24.03.2011 um 17:29 schrieb Cecil Westerhof:

> \def\getdate%
>  {\dosinglegroupempty\dogetdate}
> 
> \def\dogetdate#1%
>   {context{modification_date("\jobname.tex", "#1")}}

\def\getdate
  {\dosingleempty\dogetdate}

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

Wolfgang

___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  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:30               ` Marco
  2011-03-24 17:42             ` Florian Wobbe
  1 sibling, 2 replies; 23+ messages in thread
From: Cecil Westerhof @ 2011-03-24 17:15 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1226 bytes --]

2011/3/24 Wolfgang Schuster <schuster.wolfgang@googlemail.com>

>
> Am 24.03.2011 um 17:29 schrieb Cecil Westerhof:
>
> > \def\getdate%
> >  {\dosinglegroupempty\dogetdate}
> >
> > \def\dogetdate#1%
> >   {context{modification_date("\jobname.tex", "#1")}}
>
> \def\getdate
>  {\dosingleempty\dogetdate}
>
> \def\dogetdate[#1]%
>  {\ctalua{context(modification_date("\jobname.tex", "#1"))}}
>

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]%
     {\ctalua{context(modification_date("\jobname.tex", "#1"))}}

    \starttext

    \getdate

    \stoptext

This gives:
\dogetdate [#1]->\ctalua
                         {context(modification_date("\jobname .tex", "#1"))}
l.29 \getdate[]

?

I tried with \getdate, \getdate{} and \getdate[].

-- 
Cecil Westerhof

[-- Attachment #1.2: Type: text/html, Size: 1835 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  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:30               ` Marco
  1 sibling, 1 reply; 23+ messages in thread
From: Philipp Gesang @ 2011-03-24 17:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2020 bytes --]

On 2011-03-24 <18:15:31>, Cecil Westerhof wrote:
> 2011/3/24 Wolfgang Schuster <schuster.wolfgang@googlemail.com>
> 
> >
> > Am 24.03.2011 um 17:29 schrieb Cecil Westerhof:
> >
> > > \def\getdate%
> > >  {\dosinglegroupempty\dogetdate}
> > >
> > > \def\dogetdate#1%
> > >   {context{modification_date("\jobname.tex", "#1")}}
> >
> > \def\getdate
> >  {\dosingleempty\dogetdate}
> >
> > \def\dogetdate[#1]%
> >  {\ctalua{context(modification_date("\jobname.tex", "#1"))}}
> >
> 
> 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]%
>      {\ctalua{context(modification_date("\jobname.tex", "#1"))}}
           ^
s/\\ctalua/\\ctxlua/

Regards, Philipp
> 
>     \starttext
> 
>     \getdate
> 
>     \stoptext
> 
> This gives:
> \dogetdate [#1]->\ctalua
>                          {context(modification_date("\jobname .tex", "#1"))}
> l.29 \getdate[]
> 
> ?
> 
> I tried with \getdate, \getdate{} and \getdate[].
> 
> -- 
> 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.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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 17:15             ` Cecil Westerhof
  2011-03-24 17:29               ` Philipp Gesang
@ 2011-03-24 17:30               ` Marco
  2011-03-24 18:35                 ` Hans Hagen
  1 sibling, 1 reply; 23+ messages in thread
From: Marco @ 2011-03-24 17:30 UTC (permalink / raw)
  To: ntg-context

On 2011-03-24 Cecil Westerhof <cldwesterhof@gmail.com> wrote:

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


Marco


___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 17:29               ` Philipp Gesang
@ 2011-03-24 17:42                 ` Cecil Westerhof
  2011-03-24 17:50                   ` Philipp Gesang
  2011-03-24 23:08                   ` Cecil Westerhof
  0 siblings, 2 replies; 23+ messages in thread
From: Cecil Westerhof @ 2011-03-24 17:42 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 831 bytes --]

2011/3/24 Philipp Gesang <pgesang@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

[-- Attachment #1.2: Type: text/html, Size: 1383 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 16:33           ` Wolfgang Schuster
  2011-03-24 17:15             ` Cecil Westerhof
@ 2011-03-24 17:42             ` Florian Wobbe
  2011-03-24 17:47               ` Aditya Mahajan
  1 sibling, 1 reply; 23+ messages in thread
From: Florian Wobbe @ 2011-03-24 17:42 UTC (permalink / raw)
  To: mailing list for ConTeXt users

> \def\getdate
>  {\dosingleempty\dogetdate}
> 
> \def\dogetdate[#1]%
>  {\ctalua{context(modification_date("\jobname.tex", "#1"))}}

How would you automatically find out the filename which the macro is called from? For instance if the file with the macro is included in a master document.

Florian

___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 17:42             ` Florian Wobbe
@ 2011-03-24 17:47               ` Aditya Mahajan
  2011-03-24 17:59                 ` Florian Wobbe
  0 siblings, 1 reply; 23+ messages in thread
From: Aditya Mahajan @ 2011-03-24 17:47 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, 24 Mar 2011, Florian Wobbe wrote:

>> \def\getdate
>>  {\dosingleempty\dogetdate}
>>
>> \def\dogetdate[#1]%
>>  {\ctalua{context(modification_date("\jobname.tex", "#1"))}}
>
> How would you automatically find out the filename which the macro is called from? For instance if the file with the macro is included in a master document.

\inputfilename

So, if you want the name of the file in which this macro is defined in, 
then something like this should work:

\edef\thisfilename{\inputfilename}

\def.....{...."\thisfilename.tex", ...}


Aditya
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  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
  1 sibling, 1 reply; 23+ messages in thread
From: Philipp Gesang @ 2011-03-24 17:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1763 bytes --]

On 2011-03-24 <18:42:12>, Cecil Westerhof wrote:
> 2011/3/24 Philipp Gesang <pgesang@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]
\getdate[nil]
\getdate[false]

In context optional args are specified in brackets. It’s all
documented on the wiki:
  http://wiki.contextgarden.net/Commands_with_optional_arguments

Regards, phg


> 
> \getdate{"long"}
> 
> \stoptext
> 
> This gives:
> 2011-03-24
> 2011-03-24"short"
> 2011-03-24"long"
> 
> -- 
> 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.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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 17:47               ` Aditya Mahajan
@ 2011-03-24 17:59                 ` Florian Wobbe
  2011-03-24 20:49                   ` Aditya Mahajan
  0 siblings, 1 reply; 23+ messages in thread
From: Florian Wobbe @ 2011-03-24 17:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users

>> How would you automatically find out the filename which the macro is called from? For instance if the file with the macro is included in a master document.
> 
> \inputfilename
> 
> So, if you want the name of the file in which this macro is defined in, then something like this should work:
> 
> \edef\thisfilename{\inputfilename}
> 
> \def.....{...."\thisfilename.tex", ...}

Thanks, nice! I suppose the filename is also directly reachable from inside \startluacode ... \stopluacode. How?

Florian

___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 17:30               ` Marco
@ 2011-03-24 18:35                 ` Hans Hagen
  0 siblings, 0 replies; 23+ messages in thread
From: Hans Hagen @ 2011-03-24 18:35 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Marco

On 24-3-2011 6:30, Marco wrote:
> On 2011-03-24 Cecil Westerhof<cldwesterhof@gmail.com>  wrote:
>
>>      \def\dogetdate[#1]%
>>       {\ctalua{context(modification_date("\jobname.tex", "#1"))}}
>          ^^^^^^^
> Try \ctxlua …

or

\cldcontext{modification_date("\jobname.tex", "#1")}

but ... is it clever to define modification_date in the global lua 
table? just calling lfs.attributes is just as efficient

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 17:50                   ` Philipp Gesang
@ 2011-03-24 20:41                     ` Cecil Westerhof
  0 siblings, 0 replies; 23+ messages in thread
From: Cecil Westerhof @ 2011-03-24 20:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 455 bytes --]

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

> > \getdate
> >
> > \getdate{"short"}
>
> \getdate[long]
> \getdate[nil]
> \getdate[false]
>
> In context optional args are specified in brackets.


I had tried \getdate["long"], but the quotes where wrong.



> It’s all
> documented on the wiki:
>  http://wiki.contextgarden.net/Commands_with_optional_arguments
>

I'll look into it.

Thanks.

-- 
Cecil Westerhof

[-- Attachment #1.2: Type: text/html, Size: 1064 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 17:59                 ` Florian Wobbe
@ 2011-03-24 20:49                   ` Aditya Mahajan
  2011-03-24 21:43                     ` Florian Wobbe
  0 siblings, 1 reply; 23+ messages in thread
From: Aditya Mahajan @ 2011-03-24 20:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, 24 Mar 2011, Florian Wobbe wrote:

>>> How would you automatically find out the filename which the macro is called from? For instance if the file with the macro is included in a master document.
>>
>> \inputfilename
>>
>> So, if you want the name of the file in which this macro is defined in, then something like this should work:
>>
>> \edef\thisfilename{\inputfilename}
>>
>> \def.....{...."\thisfilename.tex", ...}
>
> Thanks, nice! I suppose the filename is also directly reachable from 
> inside \startluacode ... \stopluacode. How?

\start-stop luacode expands its contents. So, the following should work 
(untested)

\startluacode
   thisfilename = "\thisfilename.tex"
\stopluacode

Aditya
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 20:49                   ` Aditya Mahajan
@ 2011-03-24 21:43                     ` Florian Wobbe
  0 siblings, 0 replies; 23+ messages in thread
From: Florian Wobbe @ 2011-03-24 21:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users

>> Thanks, nice! I suppose the filename is also directly reachable from inside \startluacode ... \stopluacode. How?
> 
> \start-stop luacode expands its contents. So, the following should work (untested)
> 
> \startluacode
>  thisfilename = "\thisfilename.tex"
> \stopluacode

No, that is not what I meant. I thought why do the detour when the filename is available from the environment of the lua core. I just found it:
\inputfilename is defined as \ctxsprint{environment.inputfilename}

Florian

___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 17:42                 ` Cecil Westerhof
  2011-03-24 17:50                   ` Philipp Gesang
@ 2011-03-24 23:08                   ` Cecil Westerhof
  2011-03-24 23:30                     ` Hans Hagen
  1 sibling, 1 reply; 23+ messages in thread
From: Cecil Westerhof @ 2011-03-24 23:08 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1005 bytes --]

2011/3/24 Cecil Westerhof <cldwesterhof@gmail.com>

> \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
>

I made the code a little better:
\startluacode
  os.setlocale("nl_NL")

  function modification_date(file, format)
    local f    = file
    local attr = lfs.attributes(f)
    local fmt  = "%d %B %Y"

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

There is only one problem. I get:
    25 March 2011
instead of:
    25 maart 2011

What am I doing wrong?

-- 
Cecil Westerhof

[-- Attachment #1.2: Type: text/html, Size: 1532 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 23:08                   ` Cecil Westerhof
@ 2011-03-24 23:30                     ` Hans Hagen
  2011-03-25  0:33                       ` Philipp Gesang
  0 siblings, 1 reply; 23+ messages in thread
From: Hans Hagen @ 2011-03-24 23:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 25-3-2011 12:08, Cecil Westerhof wrote:

> I made the code a little better:
> \startluacode
>    os.setlocale("nl_NL")

blocked in mkiv to prevent unwanted side effects and that will stay

>    function modification_date(file, format)
>      local f    = file
>      local attr = lfs.attributes(f)

why the f?

function modification_date(filename,format)
     local attr = lfs.attributes(filename)
     if type(attr) == "table" and attr.mode ~= "directory" then
         if format == "nice" then
             return os.date("%Y-%m-%dT%X",attr.modification) .. 
os.timezone(true)
         elseif format == "long" then
             return os.date("%d %B %Y %H:%M",attr.modification)
         else
             return os.date("%d %B %Y",attr.modification)
         end
     end
     return "<unset>"
end


print(modification_date("oeps.lua","nice"))
print(modification_date("oeps.lua","long"))

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Use date of the tex file in the document
  2011-03-24 23:30                     ` Hans Hagen
@ 2011-03-25  0:33                       ` Philipp Gesang
  0 siblings, 0 replies; 23+ messages in thread
From: Philipp Gesang @ 2011-03-25  0:33 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

On 2011-03-25 <00:30:40>, Hans Hagen wrote:
> On 25-3-2011 12:08, Cecil Westerhof wrote:
> 
> >I made the code a little better:
> >\startluacode
> >   os.setlocale("nl_NL")
> 
> blocked in mkiv to prevent unwanted side effects and that will stay

Still, one can access context’s language substitution tables to
achieve a quasilocale effect (concerning the month, that is).
(-> attachments.)

Good night all, Philipp



> 
> >   function modification_date(file, format)
> >     local f    = file
> >     local attr = lfs.attributes(f)
> 
> why the f?
> 
> function modification_date(filename,format)
>     local attr = lfs.attributes(filename)
>     if type(attr) == "table" and attr.mode ~= "directory" then
>         if format == "nice" then
>             return os.date("%Y-%m-%dT%X",attr.modification) ..
> os.timezone(true)
>         elseif format == "long" then
>             return os.date("%d %B %Y %H:%M",attr.modification)
>         else
>             return os.date("%d %B %Y",attr.modification)
>         end
>     end
>     return "<unset>"
> end
> 
> 
> print(modification_date("oeps.lua","nice"))
> print(modification_date("oeps.lua","long"))
> 
> -----------------------------------------------------------------
>                                           Hans Hagen | PRAGMA ADE
>               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
>                                              | www.pragma-pod.nl
> -----------------------------------------------------------------
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________

-- 
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

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

\ctxloadluafile{getdate}

\def\getdate
  {\dosingleempty\dogetdate}

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

\def\Testall{%
  \starttabulate[|r|l|]
    \NC nice  \NC {\os\getdate[nice]} \AR
    \NC long  \NC {\os\getdate[long]} \AR
    \NC plain \NC {\os\getdate}       \AR   
  \stoptabulate
  \hairline%
}

\starttext

\Testall

\language[de]
\Testall

\language[nl]
\Testall

\language[it]
\Testall

\language[no]
\Testall

\stoptext

[-- Attachment #1.1.3: getdate.lua --]
[-- Type: text/plain, Size: 1125 bytes --]

#!/usr/bin/env texlua

local ldl_texts = languages.data.labels.texts
local u         = utf

local function localize_it (str, lang)
    local current_language = lang or languages.current(tex.language)
    return ldl_texts[u.lower(str)].labels[current_language]
end

local function modification_date (filename, format)
    local attr = lfs.attributes(filename)
    if type(attr) == "table" and attr.mode ~= "directory" then
        if format == "nice" then
            return os.date("%Y-%m-%dT%X",attr.modification) ..  os.timezone(true)
        elseif format == "long" then
            local tmp  = string.explode(os.date("%d %B %Y %H:%M",attr.modification), " ")
            local day, month, year, time = table.unpack(tmp)
            return day .. ". " .. localize_it(month) .. " " .. year .. " " .. time
        else
            local tmp  = string.explode(os.date("%d %B %Y",attr.modification), " ")
            local day, month, year = table.unpack(tmp)
            return day .. ". " .. localize_it(month) .. " " .. year
        end
    end
    return "<unset>"
end

documentdata.modification_date = modification_date

[-- 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2011-03-25  0:33 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-24  9:26 Use date of the tex file in the document Cecil Westerhof
2011-03-24 10:22 ` Philipp Gesang
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

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