[NTG-context] Conditional text appearing in a fixed vertical space
Hans Hagen
j.hagen at xs4all.nl
Tue Jan 11 21:13:00 CET 2022
On 1/11/2022 8:50 PM, Gavin via ntg-context wrote:
> Hello List,
>
> I am making problem sets for a physics class. Solutions use the style defined in the example below, and only appear if the “solution” mode is enabled. I am struggling to get a vertical space for the solution which is the same whether or not the solution is printed. Different problems require different amounts of space, so this should be an argument or key-value.
>
> In the example below, the first solution has the desired behavior. The second solution has the syntax I’d like, but it doesn’t make the space without a solution.
>
> Any ideas would be welcome! I am still pretty new to ConTeXt, so I struggle mixing things like the plain tex \vbox and ConTeXt \start…\stop concepts.
>
> Thanks,
> Gavin
>
>
>
>
> \definemode[solution][yes] % yes to enable solutions, no to disable
>
> \definebuffer [solution] % Captures solution in a buffer that isn't used
>
> \startmode[solution] % If in solution mode, redefine \startsolution...\stopsolution
> \definedelimitedtext[solution][ % Solution italic and indented
> spacebefore=medium,
> spaceafter=medium,
> style=\rm\it,
> leftmargin=standard, % Indents block on the left
> rightmargin=yes, % Indents block on the right
> indentnext=no,
> before=\vbox to 1in\bgroup,
> after=\egroup,
> ]
> \stopmode
>
> \starttext
>
> How many roads? (The 1-inch space below appears whether or not it contains a solution.)
>
> \vbox to 1in{%
> \startsolution
> 42 roads.
> \stopsolution
> }
>
> How much wood? (I would like to define solution so this to behaves like the previous question.)
> \startsolution[1in]
> Alotta wood!
> \stopsolution
>
> No more questions.
> \stoptext
a mix between big and low level
% \enablemode[solution]
\startmode[solution] % If in solution mode, redefine
\startsolution...\stopsolution
\definenarrower
[mysolution]
[before=\blank,
after=\blank]
\tolerant\protected\def\startsolution[#1]%
{\startmysolution
\it}
\protected\def\stopsolution
{\stopmysolution}
\stopmode
\startnotmode[solution] % If in solution mode, redefine
\startsolution...\stopsolution
\tolerant\protected\def\startsolution[#1]%
{\doifelsenothing{#1}{\blank[2.5cm]}{\blank[#1]}
\gobbleuntil\stopsolution}
\protected\def\stopsolution
{}
\stopnotmode
\starttext
How many roads? (The 1-inch space below appears whether or not it
contains a solution.)
\startsolution
42 roads.
\stopsolution
How much wood? (I would like to define solution so this to behaves like
the previous question.)
\startsolution[1in]
Alotta wood!
\stopsolution
No more questions.
\stoptext
much nicer is to use the blocks mechanism (but i need to check if we can
do the 2in there)
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
More information about the ntg-context
mailing list