[NTG-context] Re: Define a new command that inherits from multiple other command options

2024-04-28 Thread ai2472206007
Thanks for the detailed answer, my problem was solved very well through the 
code you provided

--

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


[NTG-context] Re: Define a new command that inherits from multiple other command options

2024-04-27 Thread Wolfgang Schuster

ai2472206...@yeah.net schrieb am 25.04.2024 um 10:24:

hi!

I'm new to ConTeXt. I want to define a command with sidenote function. This 
[setupsidenote] command inherits the options of [setupmargindata], 
[setupcounter] and [setupframed]. just like [setupenumeration] inherits the 
option of [setupcounter].

I've defined the following sidenote command by searching, and I know how to 
define a new option for it. But what I don't know is how to get it to inherit 
the options of other commands and perform these features correctly.

Any clue is warmly welcome.


Hi ???,

not all commands provide a way to inherit their options but the "framed" 
and "counter" mechanism supports it.


To use the framed mechanism with your own command replace 
\installcommandhandler with \installframedcommandhandler. This creates a 
command named \inherited...framed which can be customized with the 
setups of the new namespace.


 begin example
\unprotect

\installnamespace  {sidenote}
\installframedcommandhandler \sidenote {sidenote} \sidenote

\protect

\starttext

\inheritedsidenoteframed{Text in a frame!}

\setupsidenote[framecolor=red,width=8cm,height=2cm]

\inheritedsidenoteframed{Text in a frame!}

\stoptext
 end example

To use the counter mechanism with your commands you have to first use 
\installcounterassociation to create the two new commands 
\register...counter (this ensures the default counter values are used 
when you don't set anything) and \synchronize...counters (which updates 
the counter values when you use the setup of your own command).


Unlike the framed mechanism this no longer works with the root instance 
of your own commands because we create a new counter only when you 
create a instance (with \define...) of the new command.


 begin example
\unprotect

\installnamespace{sidenote}
\installcommandhandler \sidenote {sidenote} \sidenote

\installcounterassociation{sidenote}

\appendtoks
  \registersidenotecounter\currentsidenote
  \definecounter[\currentsidenote]%
\to \everydefinesidenote

\appendtoks
  \synchronizesidenotecounters
\to \everysetupsidenote

\protect

\starttext

% create a new sidenote instance with a associated counter
\definesidenote[example]

\start % use grouping to keep the sidenote instance local
\def\currentsidenote{example}% set the sidenote instance to example
\incrementcounter[example]% increment the example/sidenote counter
\convertedcounter[example]% print the example/sidenote counter
\stop

% change the number format of the example/sidenote counter
\setupsidenote[example][numberconversion=romannumerals]

\start
\def\currentsidenote{example}
\incrementcounter[example]
\convertedcounter[example]
\stop

\stoptext
 end example

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
___


[NTG-context] Re: Define a new command that inherits from multiple other command options

2024-04-26 Thread ai2472206007
Thanks for your reply. 

The kanji part requires a specific font and typescript file, which I defined on 
my own computer but forgot to add to this example. This is something I didn't 
take into account. It's true, I need to think about what exactly my command 
needs, not build an all-powerful command. It's my poor consideration.
___
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
___


[NTG-context] Re: Define a new command that inherits from multiple other command options

2024-04-26 Thread Bruce Horrocks


> On 25 Apr 2024, at 09:24, ai2472206...@yeah.net wrote:
> 
> But what I don't know is how to get it to inherit the options of other 
> commands and perform these features correctly.

Your example didn't work for me - none of the Chinese|Japanese[1] characters 
showed.

AFAIK there is no way to "inherit" functionality.

You still need to write \setupsidenote to call \setupcounter, \setupframed at 
the right points to achieve the right effects.

What you can do is have \setupsidenote accept all options in one big long list 
and then pass the ones that apply to setupcounter to each use of \setupcounter, 
pass on the ones that apply to setupframed to each use of \setupframed and so 
on.

Thsi is releatively easy in Lua where you could define a list of all possible 
commands and which macro they apply to then loop through it looking to see if 
that option had been supplied and building a set of parameters for 
\setupframed, \setupcounter etc.

Hope this makes sense.

But I feel there's probably a better way - it's a lot of effort to go to in 
order to have a single "does it all macro" instead of calling two or three 
macros each time.

Regards,

[1] Apologies for my ignorance.
—
Bruce Horrocks
Hampshire, UK

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