Le 7 juin 2020 à 23:19, Aditya Mahajan <adityam@umich.edu> a écrit :

On Sun, 7 Jun 2020, Fabrice L wrote:

Dear List,

I would like to insert a page using (ideally) start/stop instructions. The problem is that this page should be inserted only in a certain mode. Consulting the mailing list, I thought the following code was working, but it’s not ! The code is executed in the mode as expected, but the following instructions ("Some other text... » in the exemple) is not typeset.

Here is a minimal (not working!) example:

% ————————————————————————————————————
\unexpanded\def\StartQuestionsList{
\startmode[ClassRoom]  \page[yes] Here are some questions: \blank
}
\unexpanded\def\StopQuestionsList{
\page[yes] \stopmode
}
\definestartstop[Questions][
before=\StartQuestionsList,
after=\StopQuestionsList
]


\startQuestions
Question A….
Question B….
\stopQuestions

Some other text...
% ————————————————————————————————————


So to be clear, I would like the result in the « ClassRoom » mode to be:
% ————————————————————————————————————
Here are some questions:

Question A….
Question B….

Some other text...
% ————————————————————————————————————

Otherwise to be:
% ————————————————————————————————————
Some other text...
% ————————————————————————————————————

If you only set `ClassRoom` mode at compile time (rather than setting and unsetting it the middle of the document), then you can do:

\definebuffer[Questions]

\startmode[ClassRoom]
\define\StopQuestionsList {...}

\definestartstop[Questions][...]
\stopmode


Thanks to Aditya, I have succeeded, but it was not trivial for me. So, in case somebody someday would need a detailed solution, here is a minimal example, and an explanation. 

A buffer « Questions » is defined. If in « ClassRoom » mode, a start/stop « Questions » is also defined. So when ConTeXt encounters the \startQuestions / \stopQuestions, if the « ClassRoom » mode is enabled, the buffer is processed (with some format if needed - framed here for the example), and if the mode « ClassRoom » is disabled, then nothing is process. You can add as many \startQuestions / \stopQuestions you wish. 


% ----------------------------------------------
\definebuffer[Questions]

\enablemode[ClassRoom] % Try "On / Off » to process "\startQuestions / \stopQuestions » or not.

\startmode[ClassRoom]
 \definestartstop[Questions][before={\startframedtext\red},after={\stopframedtext\blue}]
\stopmode

\starttext

Before...

\startQuestions
The content of the buffer ! 
\stopQuestions

After...

\stoptext
% ----------------------------------------------

Thanks Aditya !
Fabrice.



Aditya___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________