ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] using command line arguments
@ 2024-10-28 11:18 Henning Hraban Ramm
  2024-10-28 12:01 ` [NTG-context] " Thomas A. Schmitz
  2024-10-28 15:18 ` Wolfgang Schuster
  0 siblings, 2 replies; 6+ messages in thread
From: Henning Hraban Ramm @ 2024-10-28 11:18 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi, I’m trying to use a command line argument in parameter names – color 
name in the example below, variable namespace in my actual project.
I guess I need more expansion, but where?
Or what’s the problem here?

"""
\setupbodyfont[plex,18pt]

% set \OEM to the parameter name, fall back to "fiee"
\expanded\define\OEM{\expanded\doifelsedocumentargument{OEM}{\expanded\getdocumentargument{OEM}}{fiee}}

\definecolor[col:fiee][c=1]
\definecolor[col:pragma][m=1,y=1]
\definecolor[col:black][k=1]

\starttext

\color[col:\OEM]{Company: \OEM}

\stoptext
"""

Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: using command line arguments
  2024-10-28 11:18 [NTG-context] using command line arguments Henning Hraban Ramm
@ 2024-10-28 12:01 ` Thomas A. Schmitz
  2024-10-28 12:41   ` Henning Hraban Ramm
  2024-10-28 15:18 ` Wolfgang Schuster
  1 sibling, 1 reply; 6+ messages in thread
From: Thomas A. Schmitz @ 2024-10-28 12:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 28.10.24 12:18, Henning Hraban Ramm wrote:
> Hi, I’m trying to use a command line argument in parameter names – color 
> name in the example below, variable namespace in my actual project.
> I guess I need more expansion, but where?
> Or what’s the problem here?

Perhaps my approach is too simplistic, but if I had to do something like 
that, I would use modes:

\startmode [fiee]
   \definecolor [OEM] [c=1]
   \def{OEM}{fiee}
\stopmode

and for the fallback, use

\startnotallmodes [...]

then you can call from the command line with --mode=fiee and write

\color[OEM]{Company: \OEM}

But maybe your needs are more complex...

All best

Thomas
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: using command line arguments
  2024-10-28 12:01 ` [NTG-context] " Thomas A. Schmitz
@ 2024-10-28 12:41   ` Henning Hraban Ramm
  0 siblings, 0 replies; 6+ messages in thread
From: Henning Hraban Ramm @ 2024-10-28 12:41 UTC (permalink / raw)
  To: ntg-context

Am 28.10.24 um 13:01 schrieb Thomas A. Schmitz:
> On 28.10.24 12:18, Henning Hraban Ramm wrote:
>> Hi, I’m trying to use a command line argument in parameter names – 
>> color name in the example below, variable namespace in my actual project.
>> I guess I need more expansion, but where?
>> Or what’s the problem here?
> 
> Perhaps my approach is too simplistic, but if I had to do something like 
> that, I would use modes:
> 
> \startmode [fiee]
>    \definecolor [OEM] [c=1]
>    \def{OEM}{fiee}
> \stopmode
> 
> and for the fallback, use
> 
> \startnotallmodes [...]
> 
> then you can call from the command line with --mode=fiee and write
> 
> \color[OEM]{Company: \OEM}
> 
> But maybe your needs are more complex...

Yes, I have several arguments that I don’t want to mix into modes.

In the end, I’ll need to process some files with Lua, but for the 
prototype I’m defining groups of variables and would like to use one of 
the parameters as variable namespace. I just tried to keep the example 
simple.

Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: using command line arguments
  2024-10-28 11:18 [NTG-context] using command line arguments Henning Hraban Ramm
  2024-10-28 12:01 ` [NTG-context] " Thomas A. Schmitz
@ 2024-10-28 15:18 ` Wolfgang Schuster
  2024-10-28 15:26   ` Henning Hraban Ramm
  1 sibling, 1 reply; 6+ messages in thread
From: Wolfgang Schuster @ 2024-10-28 15:18 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Henning Hraban Ramm

Henning Hraban Ramm schrieb am 28.10.2024 um 12:18:
> Hi, I’m trying to use a command line argument in parameter names – color 
> name in the example below, variable namespace in my actual project.
> I guess I need more expansion, but where?
> Or what’s the problem here?
> 
> """
> \setupbodyfont[plex,18pt]
> 
> % set \OEM to the parameter name, fall back to "fiee"
> \expanded\define\OEM{\expanded\doifelsedocumentargument{OEM}{\expanded\getdocumentargument{OEM}}{fiee}} 

\doifelsedocumentargument{OEM}
   {\def\OEM{\getdocumentargument{OEM}}}
   {\def\OEM{fiee}}

or

\def\OEM
   {\ifempty{\getdocumentargument{OEM}}%
      fiee%
    \else
      \getdocumentargument{OEM}%
    \fi}

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: using command line arguments
  2024-10-28 15:18 ` Wolfgang Schuster
@ 2024-10-28 15:26   ` Henning Hraban Ramm
  2024-10-28 17:54     ` Wolfgang Schuster
  0 siblings, 1 reply; 6+ messages in thread
From: Henning Hraban Ramm @ 2024-10-28 15:26 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 28.10.24 um 16:18 schrieb Wolfgang Schuster:
> Henning Hraban Ramm schrieb am 28.10.2024 um 12:18:
>> Hi, I’m trying to use a command line argument in parameter names – 
>> color name in the example below, variable namespace in my actual project.
>> I guess I need more expansion, but where?
>> Or what’s the problem here?
>>
>> """
>> \setupbodyfont[plex,18pt]
>>
>> % set \OEM to the parameter name, fall back to "fiee"
>> \expanded\define\OEM{\expanded\doifelsedocumentargument{OEM} 
>> {\expanded\getdocumentargument{OEM}}{fiee}} 
> 
> \doifelsedocumentargument{OEM}
>    {\def\OEM{\getdocumentargument{OEM}}}
>    {\def\OEM{fiee}}
> 
> or
> 
> \def\OEM
>    {\ifempty{\getdocumentargument{OEM}}%
>       fiee%
>     \else
>       \getdocumentargument{OEM}%
>     \fi}

Thank you, both works (of course, if you say so…).
Also in my actual project.

Can you explain why
\define\OEM{\doifelsedocumentargument{OEM}{\getdocumentargument{OEM}}{fiee}} 

doesn’t?

Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: using command line arguments
  2024-10-28 15:26   ` Henning Hraban Ramm
@ 2024-10-28 17:54     ` Wolfgang Schuster
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Schuster @ 2024-10-28 17:54 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Henning Hraban Ramm

Henning Hraban Ramm schrieb am 28.10.2024 um 16:26:
> Am 28.10.24 um 16:18 schrieb Wolfgang Schuster:
>> Henning Hraban Ramm schrieb am 28.10.2024 um 12:18:
>>> Hi, I’m trying to use a command line argument in parameter names – 
>>> color name in the example below, variable namespace in my actual 
>>> project.
>>> I guess I need more expansion, but where?
>>> Or what’s the problem here?
>>>
>>> """
>>> \setupbodyfont[plex,18pt]
>>>
>>> % set \OEM to the parameter name, fall back to "fiee"
>>> \expanded\define\OEM{\expanded\doifelsedocumentargument{OEM} 
>>> {\expanded\getdocumentargument{OEM}}{fiee}} 
>>
>> \doifelsedocumentargument{OEM}
>>    {\def\OEM{\getdocumentargument{OEM}}}
>>    {\def\OEM{fiee}}
>>
>> or
>>
>> \def\OEM
>>    {\ifempty{\getdocumentargument{OEM}}%
>>       fiee%
>>     \else
>>       \getdocumentargument{OEM}%
>>     \fi}
> 
> Thank you, both works (of course, if you say so…).
> Also in my actual project.
> 
> Can you explain why
> \define\OEM{\doifelsedocumentargument{OEM}{\getdocumentargument{OEM}}{fiee}} 
> 
> doesn’t?

1. \define creates an unexpandable command which can't be used as name 
placeholder for \color.

%%%% begin example
\starttext

\protected\def\GELB{yellow} % \defineexpandable\GELB{...}
           \def\BLAU{blue}   %           \define\BLAU{...}

\color[\GELB]{yellow}

\color[\BLAU]{blue}

\stoptext
%%%% end example

2. The \doifelsedocumentargument command is not expandable as well which 
makes it impossible to use it to pick the correct color name within the 
argument of \color.

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2024-10-28 17:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-28 11:18 [NTG-context] using command line arguments Henning Hraban Ramm
2024-10-28 12:01 ` [NTG-context] " Thomas A. Schmitz
2024-10-28 12:41   ` Henning Hraban Ramm
2024-10-28 15:18 ` Wolfgang Schuster
2024-10-28 15:26   ` Henning Hraban Ramm
2024-10-28 17:54     ` Wolfgang Schuster

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