Working with variables in MkIV (\ setvariables, \getparameters etc)
Hello ConTeXist, Is it possible go through all the keys of \setvariables (getvariable) macro and create the appropriate macros, as in the case of \getparameters macro? I mean macro like \getallvariablesfrom[myfirstnamespace], which return contents of brackets macro \setvariables[myfirstnamespace] (it mean list of all assignments key=value ...) In addition, you can assign all the variables one namespace to another namespace (or to create a loop which all variables passed and placed into the other namespace.)? Thanx Jaroslav Hajtmar Here is my inspiration of example : \setvariables[myfirstnamespace][id=1, value={text}] \starttext % \getparameters[myfirstnamespace][\getallvariablesfrom[myfirstnamespace]] % Now would be defined macros \myfirstnamespaceid (1) and \myfirstnamespacevalue (text) % Assign all the variables of [myfirstnamespace] namespace to [myotherspace] namespace? %\setvariable[myotherspace][\getallvariablesfrom[myfirstnamespace]] \stoptext
Am 09.09.2012 um 10:42 schrieb Jaroslav Hajtmar
Hello ConTeXist,
Is it possible go through all the keys of \setvariables (getvariable) macro and create the appropriate macros, as in the case of \getparameters macro?
I mean macro like \getallvariablesfrom[myfirstnamespace], which return contents of brackets macro \setvariables[myfirstnamespace] (it mean list of all assignments key=value ...)
In addition, you can assign all the variables one namespace to another namespace (or to create a loop which all variables passed and placed into the other namespace.)?
Thanx Jaroslav Hajtmar
Here is my inspiration of example :
\setvariables[myfirstnamespace][id=1, value={text}]
\starttext
% \getparameters[myfirstnamespace][\getallvariablesfrom[myfirstnamespace]]
% Now would be defined macros \myfirstnamespaceid (1) and \myfirstnamespacevalue (text)
% Assign all the variables of [myfirstnamespace] namespace to [myotherspace] namespace? %\setvariable[myotherspace][\getallvariablesfrom[myfirstnamespace]]
\stoptext
There is no way to access the list with the parameters from \setvariables but the question why you want a command for each variable. In MkIV direct use of values in the form \myfirstnamespaceid are replaced with something like \mynamespaceparameter{id} which has the advantage that you can even use keys which haven’t been assigned before. Wolfgang
Thanx Wolfgang. I do not know anything about such a possibility. What do you mean? Can you show a simple example? I tried several options but nothing works. Here are some examples: \setvariables[myspacename][id=1, value={value}] \getparameters[myotherspacename][id=1, value={value}] \starttext % \myspacenameid % not work % \myspacename{id} % not work % \myspacenameparameter{id} % not work % ??? \myotherspacenameid % this works only \stoptext Thanx Jaroslav Hajtmar Dne 9.9.2012 11:35, Wolfgang Schuster napsal(a):
Am 09.09.2012 um 10:42 schrieb Jaroslav Hajtmar
: Hello ConTeXist,
Is it possible go through all the keys of \setvariables (getvariable) macro and create the appropriate macros, as in the case of \getparameters macro?
I mean macro like \getallvariablesfrom[myfirstnamespace], which return contents of brackets macro \setvariables[myfirstnamespace] (it mean list of all assignments key=value ...)
In addition, you can assign all the variables one namespace to another namespace (or to create a loop which all variables passed and placed into the other namespace.)?
Thanx Jaroslav Hajtmar
Here is my inspiration of example :
\setvariables[myfirstnamespace][id=1, value={text}]
\starttext
% \getparameters[myfirstnamespace][\getallvariablesfrom[myfirstnamespace]]
% Now would be defined macros \myfirstnamespaceid (1) and \myfirstnamespacevalue (text)
% Assign all the variables of [myfirstnamespace] namespace to [myotherspace] namespace? %\setvariable[myotherspace][\getallvariablesfrom[myfirstnamespace]]
\stoptext
There is no way to access the list with the parameters from \setvariables but the question why you want a command for each variable. In MkIV direct use of values in the form \myfirstnamespaceid are replaced with something like \mynamespaceparameter{id} which has the advantage that you can even use keys which haven’t been assigned before.
Wolfgang
Am 09.09.2012 um 12:35 schrieb Jaroslav Hajtmar
Thanx Wolfgang.
I do not know anything about such a possibility. What do you mean? Can you show a simple example? I tried several options but nothing works. Here are some examples:
\setvariables[myspacename][id=1, value={value}]
\getparameters[myotherspacename][id=1, value={value}]
\starttext
% \myspacenameid % not work % \myspacename{id} % not work % \myspacenameparameter{id} % not work % ???
\myotherspacenameid % this works only
\stoptext
When you use \getparameter you have to define the command yourself, e.g. \def\mynamespaceid#1{\csname mynamespace#1\endcsname} or you use \definenamespace which creates all these commands for you: \starttext \definenamespace[one][name=one,command=yes,setup=yes,parent=one] \definenamespace[two][name=two,command=yes,setup=yes,parent=one] % With this parent setting \twoparameter uses the values from \setupone % when no value is set with \setuptwo. \unprotect \setuptwo[parent=\????one] \protect \setupone[one=One,two=Two] \starttabulate \NC one:one \EQ \oneparameter{one} \NC\NR \NC one:two \EQ \oneparameter{two} \NC\NR \NC two:one \EQ \twoparameter{one} \NC\NR \NC two:one \EQ \twoparameter{two} \NC\NR \stoptabulate \setuptwo[one=1,two=2] \starttabulate \NC one:one \EQ \oneparameter{one} \NC\NR \NC one:two \EQ \oneparameter{two} \NC\NR \NC two:one \EQ \twoparameter{one} \NC\NR \NC two:one \EQ \twoparameter{two} \NC\NR \stoptabulate \stoptext Wolfgang
Thanx Wolfgang. So far I have never worked with namespaces as follows. I thought that \setvariables macro automatically namespace for variables creates and sets the values in it. Setvariables somehow connected with the creation of macro variables in the namespace of the given name? It appears that the following example shows that it is not ... \starttext \definenamespace[myspace][name=myspace,command=yes,setup=yes,parent=one] \setupmyspace[ id=3, graphcolor=green, ] \setvariables[myspace][ id=5, graphcolor=blue, ] \myspaceparameter{id} \myspaceparameter{graphcolor} \stoptext Thanx Jaroslav Dne 9.9.2012 12:45, Wolfgang Schuster napsal(a):
Am 09.09.2012 um 12:35 schrieb Jaroslav Hajtmar
: Thanx Wolfgang.
I do not know anything about such a possibility. What do you mean? Can you show a simple example? I tried several options but nothing works. Here are some examples:
\setvariables[myspacename][id=1, value={value}]
\getparameters[myotherspacename][id=1, value={value}]
\starttext
% \myspacenameid % not work % \myspacename{id} % not work % \myspacenameparameter{id} % not work % ???
\myotherspacenameid % this works only
\stoptext
When you use \getparameter you have to define the command yourself, e.g.
\def\mynamespaceid#1{\csname mynamespace#1\endcsname}
or you use \definenamespace which creates all these commands for you:
\starttext
\definenamespace[one][name=one,command=yes,setup=yes,parent=one] \definenamespace[two][name=two,command=yes,setup=yes,parent=one]
% With this parent setting \twoparameter uses the values from \setupone % when no value is set with \setuptwo.
\unprotect \setuptwo[parent=\????one] \protect
\setupone[one=One,two=Two]
\starttabulate \NC one:one \EQ \oneparameter{one} \NC\NR \NC one:two \EQ \oneparameter{two} \NC\NR \NC two:one \EQ \twoparameter{one} \NC\NR \NC two:one \EQ \twoparameter{two} \NC\NR \stoptabulate
\setuptwo[one=1,two=2]
\starttabulate \NC one:one \EQ \oneparameter{one} \NC\NR \NC one:two \EQ \oneparameter{two} \NC\NR \NC two:one \EQ \twoparameter{one} \NC\NR \NC two:one \EQ \twoparameter{two} \NC\NR \stoptabulate
\stoptext
Wolfgang
Am 09.09.2012 um 13:56 schrieb Jaroslav Hajtmar
Thanx Wolfgang.
So far I have never worked with namespaces as follows. I thought that \setvariables macro automatically namespace for variables creates and sets the values in it. Setvariables somehow connected with the creation of macro variables in the namespace of the given name? It appears that the following example shows that it is not …
The internal functioning of both methods is more or less the same, I will begin with \getparameters. To set values as key-value-list you can use the \getparameters command, e.g. \getparameters[namespace][key1=value1,key2=value2,…] When ConTeXt process this list it takes each entry which till the next comma or the end of the list and splits it in two parts which are on the left (the “key”)and the right (the “value”) of the = sign. After that it creates a new command whose name consist of the namespace and key, e.g. “\namespacekye1” which stores the content of the key, e.g. “value1”. To create the command which stores the value context uses \csname/\endcsname which allows one to use numbers, spaces etc. as part of the key. The \setvariables command is a wrapper around \getparameters to store values in a certain namespace which can only be accessed with the \getvariable command. With \definenamespace you can generate \setup… and \define… command which use itself \getparameters to store the values but the namespace itself uses symbols (? and @) which can’t be normally used to create a command. What you always have to keep in mind is that what we call a namespace is nothing more than a certain string a command names which makes it possible to distinguish them because there a many setups which have a width key, e.g. tables can “\tablewidth” to store the value of the key while figures use “\figurewidth” to store the value etc. In reality context uses namespace like “@@ef” in MkII and in MkIV namespace have the form “123>” where instead of letters numbers are used. Wolfgang
Thanx Wolfgang for your explanations. Jaroslav Hajtmar Dne 9.9.2012 14:44, Wolfgang Schuster napsal(a):
Am 09.09.2012 um 13:56 schrieb Jaroslav Hajtmar
: Thanx Wolfgang.
So far I have never worked with namespaces as follows. I thought that \setvariables macro automatically namespace for variables creates and sets the values in it. Setvariables somehow connected with the creation of macro variables in the namespace of the given name? It appears that the following example shows that it is not …
The internal functioning of both methods is more or less the same, I will begin with \getparameters.
To set values as key-value-list you can use the \getparameters command, e.g.
\getparameters[namespace][key1=value1,key2=value2,…]
When ConTeXt process this list it takes each entry which till the next comma or the end of the list and splits it in two parts which are on the left (the “key”)and the right (the “value”) of the = sign. After that it creates a new command whose name consist of the namespace and key, e.g. “\namespacekye1” which stores the content of the key, e.g. “value1”. To create the command which stores the value context uses \csname/\endcsname which allows one to use numbers, spaces etc. as part of the key.
The \setvariables command is a wrapper around \getparameters to store values in a certain namespace which can only be accessed with the \getvariable command.
With \definenamespace you can generate \setup… and \define… command which use itself \getparameters to store the values but the namespace itself uses symbols (? and @) which can’t be normally used to create a command.
What you always have to keep in mind is that what we call a namespace is nothing more than a certain string a command names which makes it possible to distinguish them because there a many setups which have a width key, e.g. tables can “\tablewidth” to store the value of the key while figures use “\figurewidth” to store the value etc.
In reality context uses namespace like “@@ef” in MkII and in MkIV namespace have the form “123>” where instead of letters numbers are used.
Wolfgang
participants (2)
-
Jaroslav Hajtmar
-
Wolfgang Schuster