ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Why didn't I get the correct ordinal number, after defining an environment via command "installcounterassociation".
@ 2024-10-21 17:26 ai2472206007
  2024-10-21 20:27 ` [NTG-context] " Wolfgang Schuster
  0 siblings, 1 reply; 5+ messages in thread
From: ai2472206007 @ 2024-10-21 17:26 UTC (permalink / raw)
  To: ntg-context

hi, everyone

I defined a command to unite counters by 
the method of defining counters that I saw on other posts. 
When I wanted to modify the start parameter of the counter, 
I found that it did not inherit the settings of the current environment, 
but inherited the settings of the previous environment.

For example, 
in the first chapter, 
I set the counter for the environment to start counting from 5, 
but it inherited the original count of 9, 

and in the second chapter, 
it inherited the setting from the first chapter, 
and its counter became 5. 

The same happens in Chapter 3. Pls can someone fix this?

Since the command to unite with the counter is 
what I found through previous posts and source files, 
I don't know exactly how it is used. 
If my question or the mistake I made was too stupid, 
be sure to let me know.

Many thanks.

Muyik.

%%%% example
%%%% I've cut out other parts of the environment that aren't relevant to this issue.
\unprotect
\installnamespace          {material}
\installcommandhandler \????material  {material}  \????material
\installcounterassociation {material}
\appendtoks
   \registermaterialcounter\currentmaterial
   \definecounter[\currentmaterial]%
\to \everydefinematerial
\appendtoks
   \synchronizematerialcounters
\to \everysetupmaterial

\definematerial [material]
\definematerial [number]

\setupmaterial [\c!title=,
                          \c!author=,
                          \c!source=,
                          \c!start=8,]
\setupmaterial [\c!number] [\c!before={(},\c!after={)},
                            \c!prefix=no,\c!start=9,
                            \c!numberconversion=n,
                            \c!way=\v!by\v!chapter]

\def\material_counter_parameter#1%
  {\begingroup
    \def\currentmaterial{#1}%
    \usematerialstyleandcolor\c!style\c!color
    \namedmaterialparameter\currentmaterial\c!before
    \convertedcounter[\currentmaterial]%
    \incrementcounter[\currentmaterial]%
    \namedmaterialparameter\currentmaterial\c!after
   \endgroup}

\def\startmaterial{\begingroup\dosingleempty\startmaterial_indeed}
\def\startmaterial_indeed[#1]{%
  \iffirstargument\setupcurrentmaterial[#1]\fi
  \usematerialstyleandcolor\c!style\c!color%
    \convertedcounter[\currentmaterial]%
   number   seq=(5 3 3) : real num=\material_counter_parameter\c!number     => get previous parameter,not right start number\\
   number   seq=(5 3 3) : real num=\namedmaterialparameter{number}\c!start => get right number\\
   material  seq=(8 8 8) : real num=\convertedcounter[material] => work well
%%%%%%%%%%But I don't want to set the number directly by \setupmaterial,
%%%%%%%%%%because there are other elements of this environment, 
%%%%%%%%%%and they are set by their respective names,like "title" and so on.
                                    \incrementcounter[material]}
\def\stopmaterial{\par\blackrule%
    \endgroup}
\protect

\setuplayout[margin=5mm,width=fit,]
\setuphead[chapter][page=no]

\starttext
\chapter{}
\setupmaterial[number][style=tfb,color=red,start=5]

\startmaterial
\color[gray]{ knuthmath }
\stopmaterial

\startmaterial
\color[gray]{ knuthmath }
\stopmaterial

\chapter{}

\setupmaterial[number][way=bychapter,start=3]

\startmaterial
\color[gray]{ knuthmath }
\stopmaterial

\startmaterial
\color[gray]{ knuthmath }
\stopmaterial

\chapter{}

\startmaterial
\color[gray]{ knuthmath }
\stopmaterial

\startmaterial
\color[gray]{ knuthmath }
\stopmaterial
\stoptext
%%% example
___________________________________________________________________________________
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-10-23  4:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-21 17:26 [NTG-context] Why didn't I get the correct ordinal number, after defining an environment via command "installcounterassociation" ai2472206007
2024-10-21 20:27 ` [NTG-context] " Wolfgang Schuster
2024-10-22  5:32   ` ai2472206007
2024-10-22 16:56     ` Wolfgang Schuster
2024-10-23  4:27       ` 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).