ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* processing of setvariables/getvariables again
@ 2005-10-20 19:43 Thomas A. Schmitz
  2005-10-21  8:24 ` Taco Hoekwater
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas A. Schmitz @ 2005-10-20 19:43 UTC (permalink / raw)


Hi all,

excuse me for being so pig-headed, but I'm running into the same  
problem I had two weeks ago. Peter Rolf was incredibly helpful, but I  
couldnt get things working. It is more a problem of architecture and  
general choices, IMHO, than of actual code. I tried every single part  
of what I want to achieve, and it works. The difficulty lies in  
getting the variables to work...

Basic problem: I want to refine my greek module. It provides a command

\setupgreek[font=,scale=]

which sets variables fonts and scale in the namespace Greek. The  
command is defined in the module, so in order to use it, the module  
has to be read. BUT: I want to use the result [i.e. \getvariable 
{Greek}{font} and \getvariable{Greek}{scale}] within the module  
itself. Is this possible?

Details: I want to organize the fonts in a typescript to be more  
flexible. So the module first defines the setupcommand:

\def\setupgreek{\setvariables[Greek]}

then it calls the typescript

\usetypescriptfile[type-tasgreek]

where all the Greek fonts are defined in this form:

\starttypescript [serif] [GreekGentium] [agr]
   \definefontsynonym [Greekgentium-Roman] [genagr-GentiumAlt]   
[encoding=agr]
   \definefontsynonym [Greekgentium-Italic][genagr-GentiumAItI]  
[encoding=agr]
\stoptypescript

\starttypescript [serif] [GreekGentium] [name]
   \usetypescript[serif][fallback]
   \definefontsynonym [Serif]           [Greekgentium-Roman]
   \definefontsynonym [SerifItalic]     [Greekgentium-Italic]
   \definefontsynonym [SerifBold]       [Serif]
   \definefontsynonym [SerifBoldItalic] [Serif]
\stoptypescript

So the module calls the typescriptfile (or would it be more elegant  
to include these typescripts in the module itself?)

I then have the definition for the command \localgreek which  
contains, among other things, a call of the Greek font. I had been  
planning to implement it in this form:

\definetypeface [My\getvariable{Greek}{font}] [rm] [serif]  
[\getvariable{Greek}{font}] [default] [rscale = \getvariable{Greek} 
{font},encoding=agr]

and then, in the setups for \localgreek,

\switchtobodyfont[My\getvariable{Greek}{font}]

And that's where I'm banging my head against the wall: the module  
would be used like this

\usemodule[t-greek]
\setupgreek[font=GreekGentium,scale=0.9]

Which means: the entire module will be read BEFORE the \setupgreek  
command. But I would need the values of the setupgreek command WITHIN  
the module. Is that possible at all? Would I have to call a third  
file where the values are then processed? I tried to look into the  
source how \setup commands work, but I do get the impression that  
collecting the values and processing them is done in different files.  
Is this necessary? And how could I implement it in one module?

Sorry if this sounds confusing, but I'm pretty confused, and hoping  
for enlightenment from the wizzards.

All best

Thomas

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

* Re: processing of setvariables/getvariables again
  2005-10-20 19:43 processing of setvariables/getvariables again Thomas A. Schmitz
@ 2005-10-21  8:24 ` Taco Hoekwater
  2005-10-21  8:37   ` Taco Hoekwater
  2005-10-21  8:38   ` Thomas A. Schmitz
  0 siblings, 2 replies; 9+ messages in thread
From: Taco Hoekwater @ 2005-10-21  8:24 UTC (permalink / raw)



Hi Thomas,

It looks like you are looking for (inside the module):

   \def\initializegreek
     {\switchtobodyfont[My\getvariable{Greek}{font}]}
   \appendtoks \initialize \to \everystarttext

There is no other way to get arguments to/from the module.
For Hans: it would be really cool if there was a way to
do something like this:

   \usemodule[greek][font=GreekGentium,scale=0.9]

with (in this example) the \usemodule command defining the
variables

   \moduleoptionfont
   \moduleoptionscale

etc.

Greetings, Taco

Thomas A. Schmitz wrote:
> Hi all,
> 
> excuse me for being so pig-headed, but I'm running into the same  
> problem I had two weeks ago. Peter Rolf was incredibly helpful, but I  
> couldnt get things working. It is more a problem of architecture and  
> general choices, IMHO, than of actual code. I tried every single part  
> of what I want to achieve, and it works. The difficulty lies in  getting 
> the variables to work...
> 
> Basic problem: I want to refine my greek module. It provides a command
> 
> \setupgreek[font=,scale=]
> 
> which sets variables fonts and scale in the namespace Greek. The  
> command is defined in the module, so in order to use it, the module  has 
> to be read. BUT: I want to use the result [i.e. \getvariable 
> {Greek}{font} and \getvariable{Greek}{scale}] within the module  itself. 
> Is this possible?
> 
> Details: I want to organize the fonts in a typescript to be more  
> flexible. So the module first defines the setupcommand:
> 
> \def\setupgreek{\setvariables[Greek]}
> 
> then it calls the typescript
> 
> \usetypescriptfile[type-tasgreek]
> 
> where all the Greek fonts are defined in this form:
> 
> \starttypescript [serif] [GreekGentium] [agr]
>   \definefontsynonym [Greekgentium-Roman] [genagr-GentiumAlt]   
> [encoding=agr]
>   \definefontsynonym [Greekgentium-Italic][genagr-GentiumAItI]  
> [encoding=agr]
> \stoptypescript
> 
> \starttypescript [serif] [GreekGentium] [name]
>   \usetypescript[serif][fallback]
>   \definefontsynonym [Serif]           [Greekgentium-Roman]
>   \definefontsynonym [SerifItalic]     [Greekgentium-Italic]
>   \definefontsynonym [SerifBold]       [Serif]
>   \definefontsynonym [SerifBoldItalic] [Serif]
> \stoptypescript
> 
> So the module calls the typescriptfile (or would it be more elegant  to 
> include these typescripts in the module itself?)
> 
> I then have the definition for the command \localgreek which  contains, 
> among other things, a call of the Greek font. I had been  planning to 
> implement it in this form:
> 
> \definetypeface [My\getvariable{Greek}{font}] [rm] [serif]  
> [\getvariable{Greek}{font}] [default] [rscale = \getvariable{Greek} 
> {font},encoding=agr]
> 
> and then, in the setups for \localgreek,
> 
> \switchtobodyfont[My\getvariable{Greek}{font}]
> 
> And that's where I'm banging my head against the wall: the module  would 
> be used like this
> 
> \usemodule[t-greek]
> \setupgreek[font=GreekGentium,scale=0.9]
> 
> Which means: the entire module will be read BEFORE the \setupgreek  
> command. But I would need the values of the setupgreek command WITHIN  
> the module. Is that possible at all? Would I have to call a third  file 
> where the values are then processed? I tried to look into the  source 
> how \setup commands work, but I do get the impression that  collecting 
> the values and processing them is done in different files.  Is this 
> necessary? And how could I implement it in one module?
> 
> Sorry if this sounds confusing, but I'm pretty confused, and hoping  for 
> enlightenment from the wizzards.
> 
> All best
> 
> Thomas
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

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

* Re: processing of setvariables/getvariables again
  2005-10-21  8:24 ` Taco Hoekwater
@ 2005-10-21  8:37   ` Taco Hoekwater
  2005-10-21  8:38   ` Thomas A. Schmitz
  1 sibling, 0 replies; 9+ messages in thread
From: Taco Hoekwater @ 2005-10-21  8:37 UTC (permalink / raw)




Taco Hoekwater wrote:
> 
> Hi Thomas,
> 
> It looks like you are looking for (inside the module):
> 
>   \def\initializegreek
>     {\switchtobodyfont[My\getvariable{Greek}{font}]}
>   \appendtoks \initialize \to \everystarttext

Sorry, of course this should read:

   \appendtoks \initializegreek \to \everystarttext

Taco

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

* Re: processing of setvariables/getvariables again
  2005-10-21  8:24 ` Taco Hoekwater
  2005-10-21  8:37   ` Taco Hoekwater
@ 2005-10-21  8:38   ` Thomas A. Schmitz
  2005-10-21  9:16     ` Taco Hoekwater
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas A. Schmitz @ 2005-10-21  8:38 UTC (permalink / raw)


Hi Taco,

thanks for your reply!! I have to catch a train now, but I'll try  
your suggestion tonight when I'm back. And yes, having the  
module<something> variables would be great.

What does \appendtoks do?

Thanks, and all best

Thomas

On Oct 21, 2005, at 10:24 AM, Taco Hoekwater wrote:

>
> Hi Thomas,
>
> It looks like you are looking for (inside the module):
>
>   \def\initializegreek
>     {\switchtobodyfont[My\getvariable{Greek}{font}]}
>   \appendtoks \initialize \to \everystarttext
>
> There is no other way to get arguments to/from the module.
> For Hans: it would be really cool if there was a way to
> do something like this:
>
>   \usemodule[greek][font=GreekGentium,scale=0.9]
>
> with (in this example) the \usemodule command defining the
> variables
>
>   \moduleoptionfont
>   \moduleoptionscale
>
> etc.
>
> Greetings, Taco
>
> Thomas A. Schmitz wrote:
>
>> Hi all,
>> excuse me for being so pig-headed, but I'm running into the same   
>> problem I had two weeks ago. Peter Rolf was incredibly helpful,  
>> but I  couldnt get things working. It is more a problem of  
>> architecture and  general choices, IMHO, than of actual code. I  
>> tried every single part  of what I want to achieve, and it works.  
>> The difficulty lies in  getting the variables to work...
>> Basic problem: I want to refine my greek module. It provides a  
>> command
>> \setupgreek[font=,scale=]
>> which sets variables fonts and scale in the namespace Greek. The   
>> command is defined in the module, so in order to use it, the  
>> module  has to be read. BUT: I want to use the result [i.e.  
>> \getvariable {Greek}{font} and \getvariable{Greek}{scale}] within  
>> the module  itself. Is this possible?
>> Details: I want to organize the fonts in a typescript to be more   
>> flexible. So the module first defines the setupcommand:
>> \def\setupgreek{\setvariables[Greek]}
>> then it calls the typescript
>> \usetypescriptfile[type-tasgreek]
>> where all the Greek fonts are defined in this form:
>> \starttypescript [serif] [GreekGentium] [agr]
>>   \definefontsynonym [Greekgentium-Roman] [genagr-GentiumAlt]    
>> [encoding=agr]
>>   \definefontsynonym [Greekgentium-Italic][genagr-GentiumAItI]   
>> [encoding=agr]
>> \stoptypescript
>> \starttypescript [serif] [GreekGentium] [name]
>>   \usetypescript[serif][fallback]
>>   \definefontsynonym [Serif]           [Greekgentium-Roman]
>>   \definefontsynonym [SerifItalic]     [Greekgentium-Italic]
>>   \definefontsynonym [SerifBold]       [Serif]
>>   \definefontsynonym [SerifBoldItalic] [Serif]
>> \stoptypescript
>> So the module calls the typescriptfile (or would it be more  
>> elegant  to include these typescripts in the module itself?)
>> I then have the definition for the command \localgreek which   
>> contains, among other things, a call of the Greek font. I had  
>> been  planning to implement it in this form:
>> \definetypeface [My\getvariable{Greek}{font}] [rm] [serif]   
>> [\getvariable{Greek}{font}] [default] [rscale = \getvariable 
>> {Greek} {font},encoding=agr]
>> and then, in the setups for \localgreek,
>> \switchtobodyfont[My\getvariable{Greek}{font}]
>> And that's where I'm banging my head against the wall: the module   
>> would be used like this
>> \usemodule[t-greek]
>> \setupgreek[font=GreekGentium,scale=0.9]
>> Which means: the entire module will be read BEFORE the  
>> \setupgreek  command. But I would need the values of the  
>> setupgreek command WITHIN  the module. Is that possible at all?  
>> Would I have to call a third  file where the values are then  
>> processed? I tried to look into the  source how \setup commands  
>> work, but I do get the impression that  collecting the values and  
>> processing them is done in different files.  Is this necessary?  
>> And how could I implement it in one module?
>> Sorry if this sounds confusing, but I'm pretty confused, and  
>> hoping  for enlightenment from the wizzards.
>> All best
>> Thomas
>> _______________________________________________
>> ntg-context mailing list
>> ntg-context@ntg.nl
>> http://www.ntg.nl/mailman/listinfo/ntg-context
>>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>

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

* Re: processing of setvariables/getvariables again
  2005-10-21  8:38   ` Thomas A. Schmitz
@ 2005-10-21  9:16     ` Taco Hoekwater
  2005-10-21 21:06       ` Thomas A. Schmitz
  0 siblings, 1 reply; 9+ messages in thread
From: Taco Hoekwater @ 2005-10-21  9:16 UTC (permalink / raw)




Thomas A. Schmitz wrote:
> Hi Taco,
> 
> thanks for your reply!! I have to catch a train now, but I'll try  your 
> suggestion tonight when I'm back. And yes, having the  module<something> 
> variables would be great.
> 
> What does \appendtoks do?

It appends stuff to token registers (like \everystarttext)

Taco

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

* Re: processing of setvariables/getvariables again
  2005-10-21  9:16     ` Taco Hoekwater
@ 2005-10-21 21:06       ` Thomas A. Schmitz
  2005-10-22  8:55         ` Taco Hoekwater
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas A. Schmitz @ 2005-10-21 21:06 UTC (permalink / raw)


Taco,

I tried your suggestion, but I'm not sure I'm doing it the right way.  
I took the definition of \initialize... like so:

\def\initializegreekfont%
{\getvariable{Greek}{font}}
    \appendtoks \initializegreekfont \to \everystarttext % I guess I  
will need a similar procedure for
                                                         %  
initializegreekscale later

I will need the variable twice: once for selecting the typescript and  
defining the bodyfont. So in the typescriptfile with the definitions  
for all the fonts, I have these lines:

\starttypescript[Greek]
\definetypeface [My\initializegreekfont] [rm] [serif]  
[\initializegreekfont] [default] [encoding=agr]
\stoptypescript

And once more for switching to this font:

\startsetups[enablegreek]
    \catcode`~=\other
    \catcode`|=\other
    \catcode`'=\other
    \language[greek]
    \switchtobodyfont[My\initializegreekfont]
\stopsetups  %% suggested by Hans

\def\localgreek{\rescanwithsetup{enablegreek}}

I don't get any errors, but the font is not switched...

Any obvious mistakes I'm making?

Best

Thomas


On Oct 21, 2005, at 11:16 AM, Taco Hoekwater wrote:

>
>
> Thomas A. Schmitz wrote:
>
>> Hi Taco,
>> thanks for your reply!! I have to catch a train now, but I'll try   
>> your suggestion tonight when I'm back. And yes, having the   
>> module<something> variables would be great.
>> What does \appendtoks do?
>>
>
> It appends stuff to token registers (like \everystarttext)
>
> Taco
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>

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

* Re: processing of setvariables/getvariables again
  2005-10-21 21:06       ` Thomas A. Schmitz
@ 2005-10-22  8:55         ` Taco Hoekwater
  2005-10-24  7:35           ` Thomas A. Schmitz
  0 siblings, 1 reply; 9+ messages in thread
From: Taco Hoekwater @ 2005-10-22  8:55 UTC (permalink / raw)


Thomas A. Schmitz wrote:
> Taco,
> 
> I tried your suggestion, but I'm not sure I'm doing it the right way.  I 
> took the definition of \initialize... like so:
> 
> \def\initializegreekfont%
> {\getvariable{Greek}{font}}
>    \appendtoks \initializegreekfont \to \everystarttext % I guess I  
> will need a similar procedure for                                                        %  

That is not what I meant. What (I think) you want is more like this:

  \def\initializegreekfont%
   {\starttypescript[Greek]
    \definetypeface [My\getvariable{Greek}{font}] [rm] [serif]
     [\getvariable{Greek}{font}] [default] [encoding=agr]
    \stoptypescript
    \startsetups[enablegreek]
     \catcode`~=\other
     \catcode`|=\other
     \catcode`'=\other
     \language[greek]
     \switchtobodyfont[My\getvariable{Greek}{font}]
     \stopsetups }
  \appendtoks \initializegreekfont \to \everystarttext

In this way, you postpone all stuff that depends on the user-supplied
variables until the occurance of \starttext. I hope you can understand
me better now>

Cheers, Taco

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

* Re: processing of setvariables/getvariables again
  2005-10-22  8:55         ` Taco Hoekwater
@ 2005-10-24  7:35           ` Thomas A. Schmitz
  2005-10-24  8:01             ` Taco Hoekwater
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas A. Schmitz @ 2005-10-24  7:35 UTC (permalink / raw)


Taco,

thanks so much! With a slight modification, your solution seems to  
work! I will have to test it a bit, but for the moment, it looks very  
good. Is  the \appendtoks expensive in terms of TeX memory, cpu  
cycles, etc., or is it a good solution for the time being?

All best, and many thanks

Thomas

On Oct 22, 2005, at 10:55 AM, Taco Hoekwater wrote:

>
> That is not what I meant. What (I think) you want is more like this:
>
>  \def\initializegreekfont%
>   {\starttypescript[Greek]
>    \definetypeface [My\getvariable{Greek}{font}] [rm] [serif]
>     [\getvariable{Greek}{font}] [default] [encoding=agr]
>    \stoptypescript
>    \startsetups[enablegreek]
>     \catcode`~=\other
>     \catcode`|=\other
>     \catcode`'=\other
>     \language[greek]
>     \switchtobodyfont[My\getvariable{Greek}{font}]
>     \stopsetups }
>  \appendtoks \initializegreekfont \to \everystarttext
>
> In this way, you postpone all stuff that depends on the user-supplied
> variables until the occurance of \starttext. I hope you can understand
> me better now>
>
> Cheers, Taco
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>

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

* Re: processing of setvariables/getvariables again
  2005-10-24  7:35           ` Thomas A. Schmitz
@ 2005-10-24  8:01             ` Taco Hoekwater
  0 siblings, 0 replies; 9+ messages in thread
From: Taco Hoekwater @ 2005-10-24  8:01 UTC (permalink / raw)


Thomas A. Schmitz wrote:
> 
> Is the \appendtoks expensive in terms of TeX memory, cpu  cycles, 
> etc., or is it a good solution for the time being?

This solution is perfectly OK. If there was a way to pass
arguments through \usemodule, that would be nicer, but if
that never happens, this will solution be fine.

Taco

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

end of thread, other threads:[~2005-10-24  8:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-20 19:43 processing of setvariables/getvariables again Thomas A. Schmitz
2005-10-21  8:24 ` Taco Hoekwater
2005-10-21  8:37   ` Taco Hoekwater
2005-10-21  8:38   ` Thomas A. Schmitz
2005-10-21  9:16     ` Taco Hoekwater
2005-10-21 21:06       ` Thomas A. Schmitz
2005-10-22  8:55         ` Taco Hoekwater
2005-10-24  7:35           ` Thomas A. Schmitz
2005-10-24  8:01             ` Taco Hoekwater

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