ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Define a new command that inherits from multiple other command options
@ 2024-04-25  8:24 ai2472206007
  2024-04-26 20:31 ` [NTG-context] " Bruce Horrocks
  2024-04-27  8:01 ` Wolfgang Schuster
  0 siblings, 2 replies; 5+ messages in thread
From: ai2472206007 @ 2024-04-25  8:24 UTC (permalink / raw)
  To: ntg-context

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.

```
% macros=mkvi
\unprotect
\installnamespace          {sidenote}
\installcommandhandler \????sidenote  {sidenote}  \????sidenote
\setupsidenote[
               align=,
               conversion=n,
               way=bytext,
               style=,
]

\definecounter    [SidenoteMarkNumber] [prefix=no]
\definemargindata [SidenoteContent]    [outer]
                  [margin=margin,width=\outermarginwidth]
\setupmargindata  [SidenoteContent]    [stack=yes,style=\it]
\def\sidenotemark{\rawcountervalue[SidenoteMarkNumber]}
\def\convertsidenotemark#1{\high{\convertnumber{#1}{\sidenotemark}}}
\def\sidenote{\dosingleempty\dosidenote}
\def\dosidenote[#1]#2{%
    \getparameters[SMsidenote]
                  [align=\sidenoteparameter{align},
                  conversion=\sidenoteparameter{conversion},
                  way=\sidenoteparameter{way},
                   #1]%
 \setupcounter    [SidenoteMarkNumber] [#1]
 \incrementcounter[SidenoteMarkNumber]
 \convertsidenotemark{\SMsidenoteconversion}% mark in text
 \SidenoteContent[#1]{\setscript[hanzi]\setup[\SMsidenotealign]%
                      \convertsidenotemark{\SMsidenoteconversion}% mark with note
                  #2
}}
\protect
\starttext
天地玄黄,宇宙洪荒。日月盈昃,辰宿列张。寒来暑往,秋收冬\sidenote[align=flushleft] {天地玄黄,宇宙洪荒。}
\stoptext
```
___________________________________________________________________________________
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] 5+ messages in thread

* [NTG-context] Re: Define a new command that inherits from multiple other command options
  2024-04-25  8:24 [NTG-context] Define a new command that inherits from multiple other command options ai2472206007
@ 2024-04-26 20:31 ` Bruce Horrocks
  2024-04-27  2:44   ` ai2472206007
  2024-04-27  8:01 ` Wolfgang Schuster
  1 sibling, 1 reply; 5+ messages in thread
From: Bruce Horrocks @ 2024-04-26 20:31 UTC (permalink / raw)
  To: ntg-context mailing list



> On 25 Apr 2024, at 09:24, ai2472206007@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
___________________________________________________________________________________

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

* [NTG-context] Re: Define a new command that inherits from multiple other command options
  2024-04-26 20:31 ` [NTG-context] " Bruce Horrocks
@ 2024-04-27  2:44   ` ai2472206007
  0 siblings, 0 replies; 5+ messages in thread
From: ai2472206007 @ 2024-04-27  2:44 UTC (permalink / raw)
  To: ntg-context

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
___________________________________________________________________________________

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

* [NTG-context] Re: Define a new command that inherits from multiple other command options
  2024-04-25  8:24 [NTG-context] Define a new command that inherits from multiple other command options ai2472206007
  2024-04-26 20:31 ` [NTG-context] " Bruce Horrocks
@ 2024-04-27  8:01 ` Wolfgang Schuster
  2024-04-28 12:29   ` ai2472206007
  1 sibling, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2024-04-27  8:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users, ai2472206007

ai2472206007@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
___________________________________________________________________________________

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

* [NTG-context] Re: Define a new command that inherits from multiple other command options
  2024-04-27  8:01 ` Wolfgang Schuster
@ 2024-04-28 12:29   ` ai2472206007
  0 siblings, 0 replies; 5+ messages in thread
From: ai2472206007 @ 2024-04-28 12:29 UTC (permalink / raw)
  To: ntg-context

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
___________________________________________________________________________________

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

end of thread, other threads:[~2024-04-28 12:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25  8:24 [NTG-context] Define a new command that inherits from multiple other command options ai2472206007
2024-04-26 20:31 ` [NTG-context] " Bruce Horrocks
2024-04-27  2:44   ` ai2472206007
2024-04-27  8:01 ` Wolfgang Schuster
2024-04-28 12:29   ` ai2472206007

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