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>,
	autumnus <ai2472206007@yeah.net>
Subject: [NTG-context] Re: issue when the encapsulation ‘startitem stopitem’ command is in another self-defined command
Date: Sat, 28 Dec 2024 14:22:54 +0100	[thread overview]
Message-ID: <0df0279d-1f8d-7f03-fb03-e61b8376e996@gmail.com> (raw)
In-Reply-To: <173538927531.1763.1030629409830318898@cgl.ntg.nl>

autumnus  schrieb am 28.12.2024 um 13:34:
> hi,
> 
> I'm creating a command that can format multiple choice questions on my own.
> I've done most of it at the moment.
> But I want more, so I'm trying to create more versions of this command
> that is already nearing completion.
> So I'm using the following command to create a command with more possibilities.
> 
> I've noticed that ‘startitem stopitem’ isn't working.


You can't put the items in a group.


\starttext

before

\startitemize[n,horizontal,two]
\begingroup\startitem aaa\stopitem\endgroup
\begingroup\startitem bbb\stopitem\endgroup
\stopitemize

after

\stoptext


> Their location and serial number are anomalous.
> 
> %%%% Removed some unnecessary commands to show what the problem was.
> % macros=mkvi
> \starttext
> \unprotect
> \installnamespace          {chitem}
> \installcommandhandler \????chitem     {chitem}     \????chitem
> 
> \appendtoks
>   \setuevalue{\e!start\currentchitem}{\startnamedchitem [\currentchitem]}%
>   \setuevalue{\e!stop \currentchitem}{\stopnamedchitem}%
> \to \everydefinechitem
> 
> \tolerant\protected\def\markedchoice#1{{\sym{@} \red sym : #1}}
> \tolerant\protected\def\normalchoice#1{\startitem normal : #1\stopitem}
> \tolerant\protected\def\\calc_maxwidth#1{}
> %The longest option text is calculated by comparison to
> %  determine the number of columns that can be typeset
> 
> \tolerant\protected\def\startnamedchitem[#chitem]#*[#mark]#*[#option]#*#choice\stopnamedchitem%

You can't use \stopnamedchitem as delimiter for the environment,
what TeX has to see is the new \stopchitem command.

One method to achieve this is \grabuntil with a processing function.

\tolerant\protected\def\startnamedchitem[#1]#*[#2]#*[#3]%
   {\begingroup
    \edef\currentchitem{#1}%
    \edef\m_mark{#2}%
    \grabuntil{\e!stop\currentchitem}\process_chitem}

\def\process_chitem#1%
   {\ifx\m_mark\wildcardsymbol
      \aftergroup\markedchoice
    \else
      \aftergroup\normalchoice
    \fi
    \endgroup{#1}}

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-12-28 13:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-28 12:34 [NTG-context] " autumnus 
2024-12-28 13:22 ` Wolfgang Schuster [this message]
2024-12-28 14:14   ` [NTG-context] " autumnus 
2024-12-28 14:44   ` autumnus 
2024-12-29 18:37     ` Wolfgang Schuster

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=0df0279d-1f8d-7f03-fb03-e61b8376e996@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).