ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	ai2472206007@yeah.net
Subject: [NTG-context] Re: Why didn't I get the correct ordinal number, after defining an environment via command "installcounterassociation".
Date: Mon, 21 Oct 2024 22:27:21 +0200	[thread overview]
Message-ID: <3a6bd5a4-0948-52b8-60da-af7824f2891e@gmail.com> (raw)
In-Reply-To: <172953158287.1601626.2482296264759389824@cgl.ntg.nl>

ai2472206007@yeah.net schrieb am 21.10.2024 um 19:26:
> 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.

When you change the start value of a counter you have to reset the 
counter, in your case the reset happened at the start of the following 
chapter which explains the delay.

You can try the following example with and without the reset mode.

%%%% begin example
\definecounter[xxx][way=bychapter,prefix=no]

\startbuffer[increment]
   \incrementcounter[xxx]
   \convertedcounter[xxx]
\stopbuffer

%\enablemode[reset]

\starttext

\dorecurse{2}{\getbuffer[increment]\blank}

\startchapter [title={Setting counter value after \tex{chapter}}]

   \setupcounter[xxx][start=6]
   \doifmode{reset}{\resetcounter[xxx]}

   \dorecurse{2}{\getbuffer[increment]\blank}

\stopchapter

\startchapter [title={Dummy \tex{chapter}}]

   \dorecurse{2}{\getbuffer[increment]\blank}

   \setupcounter[xxx][start=4]
   \doifmode{reset}{\resetcounter[xxx]}

\stopchapter

\startchapter [title={Setting counter value before \tex{chapter}}]

   \dorecurse{2}{\getbuffer[increment]\blank}

\stopchapter

\startchapter [title={Dummy \tex{chapter}}]

   \dorecurse{2}{\getbuffer[increment]\blank}

\stopchapter

\stoptext
%%%% end example

> 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,]

There is no need to set keys which take empty value because 
\materialparameter takes care of this and handles keys which haven't 
been set as empty.

> \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}

Increment counter value before you output the value and set the start 
value always 1 below the first number, other counters in ConTeXt use 
this system and it's good style to follow it.

> \def\startmaterial{\begingroup\dosingleempty\startmaterial_indeed}
> \def\startmaterial_indeed[#1]{%
>    \iffirstargument\setupcurrentmaterial[#1]\fi

You can use the tolerant mechanism to skip the two-step-process to 
create a command with an optional argument and don't forget to assign a 
value to \currentmaterial at the start of the environment.

\tolerant\protected\def\startmaterial[#1]%
   {\begingroup
    \lettonothing\currentmaterial
    \ifarguments\or
      \setupcurrentmaterial[#1]%
    \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
___________________________________________________________________________________

  reply	other threads:[~2024-10-21 20:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-21 17:26 [NTG-context] " ai2472206007
2024-10-21 20:27 ` Wolfgang Schuster [this message]
2024-10-22  5:32   ` [NTG-context] " ai2472206007
2024-10-22 16:56     ` Wolfgang Schuster
2024-10-23  4:27       ` ai2472206007

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3a6bd5a4-0948-52b8-60da-af7824f2891e@gmail.com \
    --to=wolfgang.schuster.lists@gmail.com \
    --cc=ai2472206007@yeah.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).