ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* how to set the name of outputfile using a value defined in the source
@ 2018-09-21  8:09 J Huisman
  2018-09-21  8:30 ` Henri Menke
  0 siblings, 1 reply; 12+ messages in thread
From: J Huisman @ 2018-09-21  8:09 UTC (permalink / raw)
  To: ntg-context

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

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21  8:09 how to set the name of outputfile using a value defined in the source J Huisman
@ 2018-09-21  8:30 ` Henri Menke
  2018-09-21  8:44   ` Taco Hoekwater
  2018-09-21 12:43   ` Procházka Lukáš Ing.
  0 siblings, 2 replies; 12+ messages in thread
From: Henri Menke @ 2018-09-21  8:30 UTC (permalink / raw)
  To: ntg-context

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

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

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21  8:30 ` Henri Menke
@ 2018-09-21  8:44   ` Taco Hoekwater
  2018-09-21  8:48     ` J Huisman
                       ` (2 more replies)
  2018-09-21 12:43   ` Procházka Lukáš Ing.
  1 sibling, 3 replies; 12+ messages in thread
From: Taco Hoekwater @ 2018-09-21  8:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users



> On 21 Sep 2018, at 10:30, Henri Menke <henrimenke@gmail.com> 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
___________________________________________________________________________________

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21  8:44   ` Taco Hoekwater
@ 2018-09-21  8:48     ` J Huisman
  2018-09-21  9:00       ` Taco Hoekwater
  2018-09-21  8:59     ` luigi scarso
  2018-09-21 10:25     ` Hans Hagen
  2 siblings, 1 reply; 12+ messages in thread
From: J Huisman @ 2018-09-21  8:48 UTC (permalink / raw)
  To: ntg-context

Thank you, Taco, that is exactly what I need!

Jelle
On Fri, Sep 21, 2018 at 10:44 AM Taco Hoekwater <taco@elvenkind.com> wrote:
>
>
>
> > On 21 Sep 2018, at 10:30, Henri Menke <henrimenke@gmail.com> 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
___________________________________________________________________________________

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21  8:44   ` Taco Hoekwater
  2018-09-21  8:48     ` J Huisman
@ 2018-09-21  8:59     ` luigi scarso
  2018-09-21  9:06       ` Taco Hoekwater
  2018-09-21 10:25     ` Hans Hagen
  2 siblings, 1 reply; 12+ messages in thread
From: luigi scarso @ 2018-09-21  8:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

On Fri, Sep 21, 2018 at 10:44 AM Taco Hoekwater <taco@elvenkind.com> wrote:

>
>
> > On 21 Sep 2018, at 10:30, Henri Menke <henrimenke@gmail.com> 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

[-- Attachment #1.2: Type: text/html, Size: 1987 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21  8:48     ` J Huisman
@ 2018-09-21  9:00       ` Taco Hoekwater
  0 siblings, 0 replies; 12+ messages in thread
From: Taco Hoekwater @ 2018-09-21  9:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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 <jellehuismanlist@gmail.com> wrote:
> 
> Thank you, Taco, that is exactly what I need!
> 
> Jelle
> On Fri, Sep 21, 2018 at 10:44 AM Taco Hoekwater <taco@elvenkind.com> wrote:
>> 
>> 
>> 
>>> On 21 Sep 2018, at 10:30, Henri Menke <henrimenke@gmail.com> 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




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

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21  8:59     ` luigi scarso
@ 2018-09-21  9:06       ` Taco Hoekwater
  2018-09-21 10:05         ` luigi scarso
  0 siblings, 1 reply; 12+ messages in thread
From: Taco Hoekwater @ 2018-09-21  9:06 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

> On 21 Sep 2018, at 10:59, luigi scarso <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.

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
___________________________________________________________________________________

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21  9:06       ` Taco Hoekwater
@ 2018-09-21 10:05         ` luigi scarso
  2018-09-21 10:44           ` Hans Hagen
  0 siblings, 1 reply; 12+ messages in thread
From: luigi scarso @ 2018-09-21 10:05 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

On Fri, Sep 21, 2018 at 11:06 AM Taco Hoekwater <taco@elvenkind.com> wrote:

> Hi,
>
> > On 21 Sep 2018, at 10:59, luigi scarso <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.


-- 
luigi

[-- Attachment #1.2: Type: text/html, Size: 2244 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21  8:44   ` Taco Hoekwater
  2018-09-21  8:48     ` J Huisman
  2018-09-21  8:59     ` luigi scarso
@ 2018-09-21 10:25     ` Hans Hagen
  2 siblings, 0 replies; 12+ messages in thread
From: Hans Hagen @ 2018-09-21 10:25 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Taco Hoekwater

On 9/21/2018 10:44 AM, Taco Hoekwater wrote:
> 
> 
>> On 21 Sep 2018, at 10:30, Henri Menke <henrimenke@gmail.com> 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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21 10:05         ` luigi scarso
@ 2018-09-21 10:44           ` Hans Hagen
  2018-09-21 10:48             ` luigi scarso
  0 siblings, 1 reply; 12+ messages in thread
From: Hans Hagen @ 2018-09-21 10:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 9/21/2018 12:05 PM, luigi scarso wrote:
> 
> 
> On Fri, Sep 21, 2018 at 11:06 AM Taco Hoekwater <taco@elvenkind.com 
> <mailto:taco@elvenkind.com>> wrote:
> 
>     Hi,
> 
>      > On 21 Sep 2018, at 10:59, luigi scarso <luigi.scarso@gmail.com
>     <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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21 10:44           ` Hans Hagen
@ 2018-09-21 10:48             ` luigi scarso
  0 siblings, 0 replies; 12+ messages in thread
From: luigi scarso @ 2018-09-21 10:48 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

On Fri, Sep 21, 2018 at 12:44 PM Hans Hagen <j.hagen@xs4all.nl> wrote:

> On 9/21/2018 12:05 PM, luigi scarso wrote:
> >
> >
> > On Fri, Sep 21, 2018 at 11:06 AM Taco Hoekwater <taco@elvenkind.com
> > <mailto:taco@elvenkind.com>> wrote:
> >
> >     Hi,
> >
> >      > On 21 Sep 2018, at 10:59, luigi scarso <luigi.scarso@gmail.com
> >     <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

[-- Attachment #1.2: Type: text/html, Size: 3108 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: how to set the name of outputfile using a value defined in the source
  2018-09-21  8:30 ` Henri Menke
  2018-09-21  8:44   ` Taco Hoekwater
@ 2018-09-21 12:43   ` Procházka Lukáš Ing.
  1 sibling, 0 replies; 12+ messages in thread
From: Procházka Lukáš Ing. @ 2018-09-21 12:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello,

On Fri, 21 Sep 2018 10:30:34 +0200, Henri Menke <henrimenke@gmail.com> wrote:

> 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

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

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

end of thread, other threads:[~2018-09-21 12:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-21  8:09 how to set the name of outputfile using a value defined in the source J Huisman
2018-09-21  8:30 ` Henri Menke
2018-09-21  8:44   ` Taco Hoekwater
2018-09-21  8:48     ` J Huisman
2018-09-21  9:00       ` Taco Hoekwater
2018-09-21  8:59     ` luigi scarso
2018-09-21  9:06       ` Taco Hoekwater
2018-09-21 10:05         ` luigi scarso
2018-09-21 10:44           ` Hans Hagen
2018-09-21 10:48             ` luigi scarso
2018-09-21 10:25     ` Hans Hagen
2018-09-21 12:43   ` Procházka Lukáš Ing.

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