ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Hans Hagen <j.hagen@xs4all.nl>
Subject: Re: Conditional text appearing in a fixed vertical space
Date: Tue, 11 Jan 2022 21:13:00 +0100	[thread overview]
Message-ID: <88738524-afbc-6f9b-2e6b-604fa1351955@xs4all.nl> (raw)
In-Reply-To: <F5F32357-E94B-4352-ACFD-8ADF35D08C4A@comcast.net>

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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

  reply	other threads:[~2022-01-11 20:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 19:50 Gavin via ntg-context
2022-01-11 20:13 ` Hans Hagen via ntg-context [this message]
2022-01-11 22:56   ` Gavin via ntg-context
2022-01-11 23:13     ` Fabrice L via ntg-context
2022-01-11 23:44 ` Aditya Mahajan via ntg-context
2022-01-12 15:30   ` Gavin via ntg-context
2022-01-13  0:49     ` fv leung via ntg-context

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=88738524-afbc-6f9b-2e6b-604fa1351955@xs4all.nl \
    --to=ntg-context@ntg.nl \
    --cc=j.hagen@xs4all.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).