[NTG-context] Passing and retrieveing a variable

Procházka Lukáš Ing. - Pontex s. r. o. LPr at pontex.cz
Fri Jan 7 09:32:59 CET 2011


I created a testing file which tests existence and type of (tex|context|document).(modes|arguments|variables) by Lua - see the attachments.

It seems that:

- Modes are accessible by tex.modes[<a-mode>].

- - tex.modes are 'false' by default. I.e. they are not 'nil' but 'false', even if not specified on the command line. (tex.mode.__newindex predefined to this purpose?)

- There is no table of arguments or variables being passed by --arguments="ARG=arg" or by --variable="VAR=var" from the command line.

- All arguments passed to the command line are accessible by document.arguments. Unfortunately, when repeating an arg, only the last is accessible, e.g.

	context.exe t.mkiv --arguments="ARG1=arg1" --arguments="ARG2=arg2"

   will cause that only (string) "ARG2=arg2" will be in document.arguments.arguments.

- - That means also that not splitting to key-value pair is not performed by default (document.arguments.arguments is still "ARG2=arg2", no splitting to document.arguments.arguments.ARG2 to be "arg2" is not done).

- Not only predefined options/switches, but all args passed by command line are accessible by document.arguments. I.e. it's possible to call

	context.exe t.mkiv --myvar=MYVAR

   and later it's possible to get "MYVAR" from document.arguments.myvar.

Let's check the call:

	context.exe t.mkiv --arguments=AAA=aaa --mode=MMM --arguments=BBB=bbb --myvar=MYVAR

Best regards,


On Wed, 05 Jan 2011 21:11:51 +0100, Peter Münster <pmlists at free.fr> wrote:

> Procházka Lukáš <lpr at pontex.cz> writes:
>> I'd need to pass a variable to Ctx and to retrieve it inside a
>> compiled document - via Ctx itself and also by Lua.
> Hello,
> % cmd-line: context --arguments=testvar=my-value test
> \starttext
> value of testvar: \env{testvar}
> with lua: \ctxlua{tex.print(document.arguments.arguments)}
> \stoptext
> There is perhaps a nicer solution in lua.
> Peter

Ing. Lukáš Procházka [mailto:LPr at pontex.cz]
Pontex s. r. o.      [mailto:pontex at pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.mkiv
Type: application/octet-stream
Size: 1372 bytes
Desc: not available
URL: <http://www.ntg.nl/pipermail/ntg-context/attachments/20110107/41183e45/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.pdf
Type: application/pdf
Size: 8326 bytes
Desc: not available
URL: <http://www.ntg.nl/pipermail/ntg-context/attachments/20110107/41183e45/attachment-0001.pdf>

More information about the ntg-context mailing list