ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Taco Hoekwater <taco@elvenkind.com>
Subject: Re: how to set the name of outputfile using a value defined in the source
Date: Fri, 21 Sep 2018 12:25:28 +0200	[thread overview]
Message-ID: <3f06c86f-a63a-d54f-6a10-e37799f46f2c@xs4all.nl> (raw)
In-Reply-To: <B9720339-953B-4D97-8526-10D767EE595A@elvenkind.com>

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
___________________________________________________________________________________

  parent reply	other threads:[~2018-09-21 10:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-21  8:09 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 [this message]
2018-09-21 12:43   ` Procházka Lukáš Ing.

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=3f06c86f-a63a-d54f-6a10-e37799f46f2c@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=ntg-context@ntg.nl \
    --cc=taco@elvenkind.com \
    /path/to/YOUR_REPLY

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

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