Use date of the tex file in the document
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
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 ___________________________________________________________________________________
2011/3/24 Philipp Gesang
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
On 2011-03-24 Philipp Gesang
2011/3/24 Marco
On 2011-03-24 Philipp Gesang
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
On Thu, 24 Mar 2011, Cecil Westerhof wrote:
2011/3/24 Marco
On 2011-03-24 Philipp Gesang
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
2011/3/24 Aditya Mahajan
\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
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
2011/3/24 Wolfgang Schuster
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
On 2011-03-24 <18:15:31>, Cecil Westerhof wrote:
2011/3/24 Wolfgang Schuster
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 ___________________________________________________________________________________
2011/3/24 Philipp Gesang
{\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
On 2011-03-24 <18:42:12>, Cecil Westerhof wrote:
2011/3/24 Philipp Gesang
{\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 ___________________________________________________________________________________
2011/3/24 Philipp Gesang
\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
2011/3/24 Cecil Westerhof
\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
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 -----------------------------------------------------------------
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
On 24-3-2011 6:30, Marco wrote:
On 2011-03-24 Cecil Westerhof
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 -----------------------------------------------------------------
\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
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
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
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
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
participants (7)
-
Aditya Mahajan
-
Cecil Westerhof
-
Florian Wobbe
-
Hans Hagen
-
Marco
-
Philipp Gesang
-
Wolfgang Schuster