how to set the name of outputfile using a value defined in the source
Hi all, I'm getting back to using ConTeXt after a couple of years, so I might be missing something obvious... I would like to add an I.D. code to the name of my outputfile, but since this will be used in an automated environment I would like to load the ID-code from the source file. MWE: test.tex \starttext \def\idcode{something} Some text, whatever. \stoptext If I typeset with: context text --result=test-idcode the result is obviously "test-idcode.pdf", but I want to get a file name: "test-something.pdf" Is this possible? Thanks, Jelle
On 21/09/18 20:09, J Huisman wrote:
Hi all,
I'm getting back to using ConTeXt after a couple of years, so I might be missing something obvious...
I would like to add an I.D. code to the name of my outputfile, but since this will be used in an automated environment I would like to load the ID-code from the source file.
MWE: test.tex
\starttext
\def\idcode{something}
Some text, whatever.
\stoptext
If I typeset with: context text --result=test-idcode the result is obviously "test-idcode.pdf", but I want to get a file name: "test-something.pdf" Is this possible?
Once you enter TeX, the output file has been opened. The very concept of a filesystem forbids you to change the filehandle while writing. So no, it is not possible easily. You could still do it, but it would require two passes. In the first pass to identify that you want to change the output file and write the new name to an auxiliary file. In the second file, you use your automation script to read that file back in and call context --result=test-<value read from file> test.tex
Thanks,
Jelle ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
On 21 Sep 2018, at 10:30, Henri Menke
wrote: On 21/09/18 20:09, J Huisman wrote:
Hi all,
I'm getting back to using ConTeXt after a couple of years, so I might be missing something obvious...
I would like to add an I.D. code to the name of my outputfile, but since this will be used in an automated environment I would like to load the ID-code from the source file.
MWE: test.tex
\starttext
\def\idcode{something}
Some text, whatever.
\stoptext
If I typeset with: context text --result=test-idcode the result is obviously "test-idcode.pdf", but I want to get a file name: "test-something.pdf" Is this possible?
Once you enter TeX, the output file has been opened. The very concept of a filesystem forbids you to change the filehandle while writing. So no, it is not possible easily.
But it can be done sneakily … % start demo \enabledirectives[system.callbacks.permitoverloads] % previous line allows redefinition of ‘wrapup_run’ % to keep the code short, I use a direct definition of % \idcode and \ctxlua. Nicer would be to store the desired % output name in a lua variable and replace the % \ctxlua with \startluacode … \stopluacode with % a string.format inside it. \def\idcode{something} \ctxlua{callbacks.register('wrapup_run', function() os.execute("cp \jobname.pdf doc-\idcode.pdf") end)} \starttext Hello from \idcode \stoptext % stop demo Taco
Thank you, Taco, that is exactly what I need!
Jelle
On Fri, Sep 21, 2018 at 10:44 AM Taco Hoekwater
On 21 Sep 2018, at 10:30, Henri Menke
wrote: On 21/09/18 20:09, J Huisman wrote:
Hi all,
I'm getting back to using ConTeXt after a couple of years, so I might be missing something obvious...
I would like to add an I.D. code to the name of my outputfile, but since this will be used in an automated environment I would like to load the ID-code from the source file.
MWE: test.tex
\starttext
\def\idcode{something}
Some text, whatever.
\stoptext
If I typeset with: context text --result=test-idcode the result is obviously "test-idcode.pdf", but I want to get a file name: "test-something.pdf" Is this possible?
Once you enter TeX, the output file has been opened. The very concept of a filesystem forbids you to change the filehandle while writing. So no, it is not possible easily.
But it can be done sneakily …
% start demo \enabledirectives[system.callbacks.permitoverloads] % previous line allows redefinition of ‘wrapup_run’
% to keep the code short, I use a direct definition of % \idcode and \ctxlua. Nicer would be to store the desired % output name in a lua variable and replace the % \ctxlua with \startluacode … \stopluacode with % a string.format inside it.
\def\idcode{something}
\ctxlua{callbacks.register('wrapup_run', function() os.execute("cp \jobname.pdf doc-\idcode.pdf") end)}
\starttext Hello from \idcode \stoptext % stop demo
Taco
___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
Somewhat related: I would like to mention that you can get at nearly anything mentioned on the "context" command line from within your document, by using \getdocumentargument and \doifdocumentargument . https://wiki.contextgarden.net/Command/getdocumentargument On the lua side, these arguments are in the “document.arguments” table, see file-job.lua for details. Anything that starts with —c: on the luatex command line as seen from the "mtx-context | run <nr>:" line can be accessed this way, it does not have to be a known option to the mtx-context script. So you could e.g. do context —idcode=whatever mydoc and then you could do \getdocumentargument{idcode} in the document source. I know you do not need that, but it may be helpful for other people doing automated typesetting runs. Best wishes, Taco
On 21 Sep 2018, at 10:48, J Huisman
wrote: Thank you, Taco, that is exactly what I need!
Jelle On Fri, Sep 21, 2018 at 10:44 AM Taco Hoekwater
wrote: On 21 Sep 2018, at 10:30, Henri Menke
wrote: On 21/09/18 20:09, J Huisman wrote:
Hi all,
I'm getting back to using ConTeXt after a couple of years, so I might be missing something obvious...
I would like to add an I.D. code to the name of my outputfile, but since this will be used in an automated environment I would like to load the ID-code from the source file.
MWE: test.tex
\starttext
\def\idcode{something}
Some text, whatever.
\stoptext
If I typeset with: context text --result=test-idcode the result is obviously "test-idcode.pdf", but I want to get a file name: "test-something.pdf" Is this possible?
Once you enter TeX, the output file has been opened. The very concept of a filesystem forbids you to change the filehandle while writing. So no, it is not possible easily.
But it can be done sneakily …
% start demo \enabledirectives[system.callbacks.permitoverloads] % previous line allows redefinition of ‘wrapup_run’
% to keep the code short, I use a direct definition of % \idcode and \ctxlua. Nicer would be to store the desired % output name in a lua variable and replace the % \ctxlua with \startluacode … \stopluacode with % a string.format inside it.
\def\idcode{something}
\ctxlua{callbacks.register('wrapup_run', function() os.execute("cp \jobname.pdf doc-\idcode.pdf") end)}
\starttext Hello from \idcode \stoptext % stop demo
Taco
___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
Taco Hoekwater Elvenkind BV
On Fri, Sep 21, 2018 at 10:44 AM Taco Hoekwater
On 21 Sep 2018, at 10:30, Henri Menke
wrote: On 21/09/18 20:09, J Huisman wrote:
Hi all,
I'm getting back to using ConTeXt after a couple of years, so I might be missing something obvious...
I would like to add an I.D. code to the name of my outputfile, but since this will be used in an automated environment I would like to load the ID-code from the source file.
MWE: test.tex
\starttext
\def\idcode{something}
Some text, whatever.
\stoptext
If I typeset with: context text --result=test-idcode the result is obviously "test-idcode.pdf", but I want to get a file name: "test-something.pdf" Is this possible?
Once you enter TeX, the output file has been opened. The very concept of a filesystem forbids you to change the filehandle while writing. So no, it is not possible easily.
But it can be done sneakily …
% start demo \enabledirectives[system.callbacks.permitoverloads] % previous line allows redefinition of ‘wrapup_run’
iirc , this should be avoided .... -- luigi
Hi,
On 21 Sep 2018, at 10:59, luigi scarso
wrote: % start demo \enabledirectives[system.callbacks.permitoverloads] % previous line allows redefinition of ‘wrapup_run’ iirc , this should be avoided ….
Sure, but I find wrapup_run extremely useful, and I know of no other way to use it. Taco
On Fri, Sep 21, 2018 at 11:06 AM Taco Hoekwater
Hi,
On 21 Sep 2018, at 10:59, luigi scarso
wrote: % start demo \enabledirectives[system.callbacks.permitoverloads] % previous line allows redefinition of ‘wrapup_run’ iirc , this should be avoided ….
Sure, but I find wrapup_run extremely useful, and I know of no other way to use it.
sure but the idea of modifying the context state (broadly speaking) before that context says that the state is consistent (ie the run is finished, in this case) is , how to say.. hm hm. Maybe signalling with an asyn msg that has nothing todo with the context state (just to say "Hey, context here: I am finishing the run" to somebofy else) , but usually one wants also to check the starts and the end of the run as process, ie just before the run starts and just after the run ended. This case seems safe but I have already dubious on \ $ lua -e ' os.execute("ls \c*") ' lua: (command line):1: invalid escape sequence near '\c' while $ lua -e ' os.execute([[ls \c*]])' is ok Also, I run context foo.tex and at the end of the runs I found foo.pdf (expected) and doc-<idcode>.pdf ("hm .. where does it come from ? I dont remember ...I have to look into the source" ) so two times the space --- and the copy is done at each run, iirc. But it's just to complete the picture: once one knows the limits, it's a useful callback. -- luigi
On 9/21/2018 12:05 PM, luigi scarso wrote:
On Fri, Sep 21, 2018 at 11:06 AM Taco Hoekwater
mailto:taco@elvenkind.com> wrote: Hi,
> On 21 Sep 2018, at 10:59, luigi scarso
mailto:luigi.scarso@gmail.com> wrote: > > > % start demo > \enabledirectives[system.callbacks.permitoverloads] > % previous line allows redefinition of ‘wrapup_run’ > iirc , > this should be avoided …. Sure, but I find wrapup_run extremely useful, and I know of no other way to use it.
sure but the idea of modifying the context state (broadly speaking) before that context says that the state is consistent (ie the run is finished, in this case) is , how to say.. hm hm. Maybe signalling with an asyn msg that has nothing todo with the context state (just to say "Hey, context here: I am finishing the run" to somebofy else) , but usually one wants also to check the starts and the end of the run as process, ie just before the run starts and just after the run ended. This case seems safe but I have already dubious on \ $ lua -e ' os.execute("ls \c*") ' lua: (command line):1: invalid escape sequence near '\c' while $ lua -e ' os.execute([[ls \c*]])' is ok Also, I run context foo.tex and at the end of the runs I found foo.pdf (expected) and doc-<idcode>.pdf ("hm .. where does it come from ? I dont remember ...I have to look into the source" ) so two times the space --- and the copy is done at each run, iirc.
But it's just to complete the picture: once one knows the limits, it's a useful callback.
that callback is really the last ... files have been closed then here is a (future) safe rename variant (assuming \MyID is defined): luatex.wrapup(function() local oldname = file.addsuffix(environment.jobname,"pdf") local newname = file.addsuffix("doc-\MyId","pdf") if lfs.isfile(newname) then logs.reporter("system","removing %a",newname) os.remove(newname) end if not lfs.isfile(newname) then logs.reporter("system","renaming %a to %a",oldname,newname) os.rename(oldname,newname) end if not lfs.isfile(newname) then logs.reporter("system","error in renaming") end end) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On Fri, Sep 21, 2018 at 12:44 PM Hans Hagen
On 9/21/2018 12:05 PM, luigi scarso wrote:
On Fri, Sep 21, 2018 at 11:06 AM Taco Hoekwater
mailto:taco@elvenkind.com> wrote: Hi,
> On 21 Sep 2018, at 10:59, luigi scarso
mailto:luigi.scarso@gmail.com> wrote: > > > % start demo > \enabledirectives[system.callbacks.permitoverloads] > % previous line allows redefinition of ‘wrapup_run’ > iirc , > this should be avoided …. Sure, but I find wrapup_run extremely useful, and I know of no other way to use it.
sure but the idea of modifying the context state (broadly speaking) before that context says that the state is consistent (ie the run is finished, in this case) is , how to say.. hm hm. Maybe signalling with an asyn msg that has nothing todo with the context state (just to say "Hey, context here: I am finishing the run" to somebofy else) , but usually one wants also to check the starts and the end of the run as process, ie just before the run starts and just after the run ended. This case seems safe but I have already dubious on \ $ lua -e ' os.execute("ls \c*") ' lua: (command line):1: invalid escape sequence near '\c' while $ lua -e ' os.execute([[ls \c*]])' is ok Also, I run context foo.tex and at the end of the runs I found foo.pdf (expected) and doc-<idcode>.pdf ("hm .. where does it come from ? I dont remember ...I have to look into the source" ) so two times the space --- and the copy is done at each run, iirc.
But it's just to complete the picture: once one knows the limits, it's a useful callback.
that callback is really the last ... files have been closed then
sure , but after it there are 2 free_<something> and free the Lua state, --- and closing a file can be delayed by the OS. Anyway, this case looks ok. -- luigi
On 9/21/2018 10:44 AM, Taco Hoekwater wrote:
On 21 Sep 2018, at 10:30, Henri Menke
wrote: On 21/09/18 20:09, J Huisman wrote:
Hi all,
I'm getting back to using ConTeXt after a couple of years, so I might be missing something obvious...
I would like to add an I.D. code to the name of my outputfile, but since this will be used in an automated environment I would like to load the ID-code from the source file.
MWE: test.tex
\starttext
\def\idcode{something}
Some text, whatever.
\stoptext
If I typeset with: context text --result=test-idcode the result is obviously "test-idcode.pdf", but I want to get a file name: "test-something.pdf" Is this possible?
Once you enter TeX, the output file has been opened. The very concept of a filesystem forbids you to change the filehandle while writing. So no, it is not possible easily.
But it can be done sneakily …
% start demo \enabledirectives[system.callbacks.permitoverloads] % previous line allows redefinition of ‘wrapup_run’
% to keep the code short, I use a direct definition of % \idcode and \ctxlua. Nicer would be to store the desired % output name in a lua variable and replace the % \ctxlua with \startluacode … \stopluacode with % a string.format inside it.
\def\idcode{something}
\ctxlua{callbacks.register('wrapup_run', function() os.execute("cp \jobname.pdf doc-\idcode.pdf") end)}
\starttext Hello from \idcode \stoptext % stop demo
In order to prevent future overloads (currently context doesn't itself use the wrapup) I've added luatex.wrapup: \startluacode luatex.wrapup(function() for i=1,10 do print("DONE",i) end end) luatex.wrapup(function() for i=1,10 do print("MORE",i) end end) \stopluacode \starttext test \stoptext no beta yet Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Hello,
On Fri, 21 Sep 2018 10:30:34 +0200, Henri Menke
You could still do it, but it would require two passes. In the first pass to identify that you want to change the output file and write the new name to an auxiliary file. In the second file, you use your automation script to read that file back in and call
context --result=test-<value read from file> test.tex
Or you can do it processing your source file by a batch, which: 1. calls context.exe with appropriate args, 2. checks for existence of a <file>, which - being created during compilation - is processed somehow then. Cheers, Lukas
Thanks,
Jelle
-- Ing. Lukáš Procházka | mailto:LPr@pontex.cz Pontex s. r. o. | mailto:pontex@pontex.cz | http://www.pontex.cz | IDDS: nrpt3sn | IČO: 40763439 Bezová 1658 147 14 Praha 4 Mob.: +420 702 033 396
participants (6)
-
Hans Hagen
-
Henri Menke
-
J Huisman
-
luigi scarso
-
Procházka Lukáš Ing.
-
Taco Hoekwater