ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Conditional text appearing in a fixed vertical space
@ 2022-01-11 19:50 Gavin via ntg-context
  2022-01-11 20:13 ` Hans Hagen via ntg-context
  2022-01-11 23:44 ` Aditya Mahajan via ntg-context
  0 siblings, 2 replies; 7+ messages in thread
From: Gavin via ntg-context @ 2022-01-11 19:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Gavin

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Conditional text appearing in a fixed vertical space
  2022-01-11 19:50 Conditional text appearing in a fixed vertical space Gavin via ntg-context
@ 2022-01-11 20:13 ` Hans Hagen via ntg-context
  2022-01-11 22:56   ` Gavin via ntg-context
  2022-01-11 23:44 ` Aditya Mahajan via ntg-context
  1 sibling, 1 reply; 7+ messages in thread
From: Hans Hagen via ntg-context @ 2022-01-11 20:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Conditional text appearing in a fixed vertical space
  2022-01-11 20:13 ` Hans Hagen via ntg-context
@ 2022-01-11 22:56   ` Gavin via ntg-context
  2022-01-11 23:13     ` Fabrice L via ntg-context
  0 siblings, 1 reply; 7+ messages in thread
From: Gavin via ntg-context @ 2022-01-11 22:56 UTC (permalink / raw)
  To: Hans Hagen; +Cc: Gavin, mailing list for ConTeXt users

Thanks Hans! This is great. I made a slight change to add an additional feature. By moving the “mysolution” definition out of \startmode[solution], I can now use mysolution in either mode. I’d use this if I want to give my solution to one of the problems, as an example, on the handout.

-Gavin


% \enablemode[solution]

% Define "mysolution” for use independent of solution mode.
\definenarrower[mysolution]
  [before=\blank\it,
   after=\blank]

% If in solution mode, define "solution" to use "mysolution"
\startmode[solution]
   \tolerant\protected\def\startsolution[#1]%
     {\startmysolution}
   \protected\def\stopsolution
     {\stopmysolution}
\stopmode

% If NOT in solution mode, define "solution" to produce a blank space
\startnotmode[solution]
   \tolerant\protected\def\startsolution[#1]%
     {\doifelsenothing{#1}{\blank[1in]}{\blank[#1]}
      \gobbleuntil\stopsolution}
   \protected\def\stopsolution
     {}
\stopnotmode


\starttext

How many roads?
  \startsolution
    42 roads.
  \stopsolution

How much wood?
  \startsolution[1.5in]
    Alotta wood!
  \stopsolution

No more questions.

\stoptext


> On Jan 11, 2022, at 1:13 PM, Hans Hagen <j.hagen@xs4all.nl> wrote:
> 
> 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Conditional text appearing in a fixed vertical space
  2022-01-11 22:56   ` Gavin via ntg-context
@ 2022-01-11 23:13     ` Fabrice L via ntg-context
  0 siblings, 0 replies; 7+ messages in thread
From: Fabrice L via ntg-context @ 2022-01-11 23:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Fabrice L


[-- Attachment #1.1: Type: text/plain, Size: 6555 bytes --]


> Le 11 janv. 2022 à 17:56, Gavin via ntg-context <ntg-context@ntg.nl> a écrit :
> 
> Thanks Hans! This is great. I made a slight change to add an additional feature. By moving the “mysolution” definition out of \startmode[solution], I can now use mysolution in either mode. I’d use this if I want to give my solution to one of the problems, as an example, on the handout.
> 
> -Gavin


I have similar problem for my courses. The solution I use, different than the one offered, is to write in a « special » color the text I want to hide from the students. This permits me to have hidden texts in figures for exemple. Also, I do not calculate space required, this is automated !  Here is MWE :

\enablemode[solution]

\doifmode{solution}{
	 \definecolor[solcolor][magenta]
} 
\doifnotmode{solution}{
	 \definecolor[solcolor][white]
} 
\definedescription[solution]
    [color=solcolor]

\starttext

How many roads? \startcolor[solcolor] Professor note.\stopcolor
 \startsolution
   42 roads.
 \stopsolution

How much wood?
 \startsolution
   Alotta wood!
 \stopsolution

No more questions.

\stoptext

So the color used when solutions are hidden are white on white, we can not see the text;  but of course, if you change the background, you see the hidden text. So there is another step to the process (I usually do this only once a term); open the file in Acrobat, and find the option to delete hidden text. The text for which the color is the same as the background is really deleted. You can try to select the text in any pdf view/editor, the text is gone !  

Fabrice.


> 
> 
> % \enablemode[solution]
> 
> % Define "mysolution” for use independent of solution mode.
> \definenarrower[mysolution]
>  [before=\blank\it,
>   after=\blank]
> 
> % If in solution mode, define "solution" to use "mysolution"
> \startmode[solution]
>   \tolerant\protected\def\startsolution[#1]%
>     {\startmysolution}
>   \protected\def\stopsolution
>     {\stopmysolution}
> \stopmode
> 
> % If NOT in solution mode, define "solution" to produce a blank space
> \startnotmode[solution]
>   \tolerant\protected\def\startsolution[#1]%
>     {\doifelsenothing{#1}{\blank[1in]}{\blank[#1]}
>      \gobbleuntil\stopsolution}
>   \protected\def\stopsolution
>     {}
> \stopnotmode
> 
> 
> \starttext
> 
> How many roads?
>  \startsolution
>    42 roads.
>  \stopsolution
> 
> How much wood?
>  \startsolution[1.5in]
>    Alotta wood!
>  \stopsolution
> 
> No more questions.
> 
> \stoptext
> 
> 
>> On Jan 11, 2022, at 1:13 PM, Hans Hagen <j.hagen@xs4all.nl> wrote:
>> 
>> 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
> ___________________________________________________________________________________


[-- Attachment #1.2: Type: text/html, Size: 10736 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Conditional text appearing in a fixed vertical space
  2022-01-11 19:50 Conditional text appearing in a fixed vertical space Gavin via ntg-context
  2022-01-11 20:13 ` Hans Hagen via ntg-context
@ 2022-01-11 23:44 ` Aditya Mahajan via ntg-context
  2022-01-12 15:30   ` Gavin via ntg-context
  1 sibling, 1 reply; 7+ messages in thread
From: Aditya Mahajan via ntg-context @ 2022-01-11 23:44 UTC (permalink / raw)
  To: Gavin via ntg-context; +Cc: Aditya Mahajan

[-- Attachment #1: Type: text/plain, Size: 1386 bytes --]

On Tue, 11 Jan 2022, 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.

This is how I would do it: piggyback on framedtext. Note that framedtext doesn't break across pages. So, if you have long answers, a different mechanism is needed. 

\definemode[solution][no]

\doifmodeelse{solution}
  {\defineframedtext[solution][empty=no]}
  {\defineframedtext[solution][empty=yes]}

% Doesn't work. Why?
% \expanded{\defineframedtext[solution][empty=\doifmodeelse{solution}{no}{yes}]}

\setupframedtext
  [solution]
  [
    spacebefore=medium,
    spaceafter=medium,
    width=broad,
    foregroundstyle=\rm\it,
    loffset=2em,
    roffset=2em,
    indentnext=no,
  ]


\starttext

Sample question. Always show answer.

\startsolution[height=1in, empty=no]
  Alotta wood!
\stopsolution


How much wood? 

\startsolution[height=1in]
  Alotta wood!
\stopsolution

You don't need to specify the height:

\startsolution
  \input ward
\stopsolution

No more questions.
\stoptext

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Conditional text appearing in a fixed vertical space
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Gavin via ntg-context @ 2022-01-12 15:30 UTC (permalink / raw)
  To: Aditya Mahajan; +Cc: Gavin, Gavin via ntg-context

Thanks Fabrice and Aditya!

With three completely different approaches, I learned three times more than I was expecting. This has been a great help. I will probably use the framedtext method, but I learned something from each.

Gavin


> On Jan 11, 2022, at 4:44 PM, Aditya Mahajan <adityam@umich.edu> wrote:
> 
> On Tue, 11 Jan 2022, 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.
> 
> This is how I would do it: piggyback on framedtext. Note that framedtext doesn't break across pages. So, if you have long answers, a different mechanism is needed. 
> 
> \definemode[solution][no]
> 
> \doifmodeelse{solution}
>  {\defineframedtext[solution][empty=no]}
>  {\defineframedtext[solution][empty=yes]}
> 
> % Doesn't work. Why?
> % \expanded{\defineframedtext[solution][empty=\doifmodeelse{solution}{no}{yes}]}
> 
> \setupframedtext
>  [solution]
>  [
>    spacebefore=medium,
>    spaceafter=medium,
>    width=broad,
>    foregroundstyle=\rm\it,
>    loffset=2em,
>    roffset=2em,
>    indentnext=no,
>  ]
> 
> 
> \starttext
> 
> Sample question. Always show answer.
> 
> \startsolution[height=1in, empty=no]
>  Alotta wood!
> \stopsolution
> 
> 
> How much wood? 
> 
> \startsolution[height=1in]
>  Alotta wood!
> \stopsolution
> 
> You don't need to specify the height:
> 
> \startsolution
>  \input ward
> \stopsolution
> 
> No more questions.
> \stoptext

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Conditional text appearing in a fixed vertical space
  2022-01-12 15:30   ` Gavin via ntg-context
@ 2022-01-13  0:49     ` fv leung via ntg-context
  0 siblings, 0 replies; 7+ messages in thread
From: fv leung via ntg-context @ 2022-01-13  0:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: fv leung


[-- Attachment #1.1: Type: text/plain, Size: 3047 bytes --]

You can also consider using viewerlayer:


\setupinteraction[state=start]

\defineviewerlayer[solution]

\setupcolors[state=start]
\usecolors[xwi]
\definecolor[keyColor][1.0(maroon)]

\starttext

\startitemize[n]
  \but[ToggleLayer{solution}]
  \samplefile{tufte}
  \blank[big]
  \startviewerlayer[solution]
    \keyColor
    \samplefile{knuth}
  \stopviewerlayer
\stopitemize

\stoptext

I print the file with the solution layer off to a 'clean' file for students.

Gavin via ntg-context <ntg-context@ntg.nl> 於 2022年1月12日 週三 下午11:30寫道:

> Thanks Fabrice and Aditya!
>
> With three completely different approaches, I learned three times more
> than I was expecting. This has been a great help. I will probably use the
> framedtext method, but I learned something from each.
>
> Gavin
>
>
> > On Jan 11, 2022, at 4:44 PM, Aditya Mahajan <adityam@umich.edu> wrote:
> >
> > On Tue, 11 Jan 2022, 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.
> >
> > This is how I would do it: piggyback on framedtext. Note that framedtext
> doesn't break across pages. So, if you have long answers, a different
> mechanism is needed.
> >
> > \definemode[solution][no]
> >
> > \doifmodeelse{solution}
> >  {\defineframedtext[solution][empty=no]}
> >  {\defineframedtext[solution][empty=yes]}
> >
> > % Doesn't work. Why?
> > %
> \expanded{\defineframedtext[solution][empty=\doifmodeelse{solution}{no}{yes}]}
> >
> > \setupframedtext
> >  [solution]
> >  [
> >    spacebefore=medium,
> >    spaceafter=medium,
> >    width=broad,
> >    foregroundstyle=\rm\it,
> >    loffset=2em,
> >    roffset=2em,
> >    indentnext=no,
> >  ]
> >
> >
> > \starttext
> >
> > Sample question. Always show answer.
> >
> > \startsolution[height=1in, empty=no]
> >  Alotta wood!
> > \stopsolution
> >
> >
> > How much wood?
> >
> > \startsolution[height=1in]
> >  Alotta wood!
> > \stopsolution
> >
> > You don't need to specify the height:
> >
> > \startsolution
> >  \input ward
> > \stopsolution
> >
> > No more questions.
> > \stoptext
>
>
> ___________________________________________________________________________________
> 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
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 4292 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-01-13  0:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11 19:50 Conditional text appearing in a fixed vertical space Gavin via ntg-context
2022-01-11 20:13 ` Hans Hagen via ntg-context
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

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).