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
___________________________________________________________________________________

Reply via email to