[NTG-context] Passing and retrieveing a variable

Procházka Lukáš Ing. - Pontex s. r. o. LPr at pontex.cz
Thu Jan 6 08:39:06 CET 2011


Hello,

thanks, -

On Wed, 05 Jan 2011 21:41:13 +0100, Wolfgang Schuster <schuster.wolfgang at googlemail.com> wrote:

>
> Am 05.01.2011 um 20:22 schrieb Procházka Lukáš:
>
>> Hello,
>>
>> I'd need to pass a variable to Ctx and to retrieve it inside a compiled document - via Ctx itself and also by Lua. Something like modes; but modes allow just to check whether they are on or off. I'd need something like this:
>
> You can check modes in Lua:
>
> context --arguments="size=small" --mode=print test.tex

And can I check a variable (argument) in Lua in a similar way?

---
\starttext

Print mode: \doifmodeelse{print}{yes}{no}

\startluacode
	if tex.modes['print'] then
		context("Print mode is enabled")
	else
		context("Print mode is disabled")
	end

	-- Something like this: >>

	if tex.arguments['size'] == "small" then
	-- Or: 'tex.variables["size"] == "small"'
	-- Or: 'document.arguments["size"] == "small"'

		context("Small size")
	end

	--
\stopluacode

\doifenvelse{size}
   {\processaction
      [\env{size}]
      [  small=>Small size,
        medium=>Medium size,
           big=>Big size,
       unknown=>Other size: \env{size}]}
   {No value “size”}
\stoptext
---

If the passed argument has a NUMBER value, should it be checked against a number value or a string - so what of the following should be right:

context --arguments="size=1" test.tex

if tex.arguments['size'] == "1" then ...

Or:

if tex.arguments['size'] == 1 then ...

Best regards,

Lukas


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



More information about the ntg-context mailing list