ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Blocks in a macro?
@ 2005-02-14 13:39 Michal Kvasnicka
  2005-02-14 14:26 ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Kvasnicka @ 2005-02-14 13:39 UTC (permalink / raw)


Good evening.

How can I include \begin<block> ... \end<block> into a macro?

I have defined:
    \defineblock[question]
    \defineblock[answer]
    \defineenumeration[question][location=serried, coupling=answer]
    \defineenumeration[answer][location=serried, coupling=answer]
    \hideblocks[answer]
I'd like to simplify my code from
    \beginquestion \startquestion question ... \stopquestion \endquestion
    \beginanswer \answer answer ... \par  \endanswer
to
    \q{question ...}{answer ...}
\q begin something like this:
    \def\q{%
       \beginquestion \question #1\par \endquestion
        \beginanswer \answer #2\par  \endanswer
    }

But no question/anwer is written into .tub file (only the beginning/end 
of those blocks).

Any hint?
Many thanks. Your sincerely
Michal Kvasnicka

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

* Re: Blocks in a macro?
  2005-02-14 13:39 Blocks in a macro? Michal Kvasnicka
@ 2005-02-14 14:26 ` Hans Hagen
  2005-02-14 15:01   ` Michal Kvasnicka
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2005-02-14 14:26 UTC (permalink / raw)


Michal Kvasnicka wrote:
> Good evening.
> 
> How can I include \begin<block> ... \end<block> into a macro?
> 
> I have defined:
>    \defineblock[question]
>    \defineblock[answer]
>    \defineenumeration[question][location=serried, coupling=answer]
>    \defineenumeration[answer][location=serried, coupling=answer]
>    \hideblocks[answer]
> I'd like to simplify my code from
>    \beginquestion \startquestion question ... \stopquestion \endquestion
>    \beginanswer \answer answer ... \par  \endanswer
> to
>    \q{question ...}{answer ...}
> \q begin something like this:
>    \def\q{%
>       \beginquestion \question #1\par \endquestion
>        \beginanswer \answer #2\par  \endanswer
>    }
> 
> But no question/anwer is written into .tub file (only the beginning/end 
> of those blocks).

you can't do that since buffer and block code works on the main input stream 
directly (catcode trickery and such)

but you can hook things into blocks (before/after keys)

   \setupblock[question][before=\startquestion,after=\stopquestion]

should work (i'm crossing my fingers now)

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------

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

* Re: Blocks in a macro?
  2005-02-14 14:26 ` Hans Hagen
@ 2005-02-14 15:01   ` Michal Kvasnicka
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Kvasnicka @ 2005-02-14 15:01 UTC (permalink / raw)


Good evening.

Many thanks for your help. Basicly it works. Problem is that it spoils 
formatting. Try the following example. The answers defined through block 
are not serried, while the last one defined directly is. Could it be 
solved somehow?

Many thanks once more.
M.K.

P.S. Does it mean that blocks cannot be reasonably linked to XML-marks too?



% output=pdf

\defineenumeration[question]
  [way=bychapter, coupling=answer, location=serried, text=, 
distance=0pt, width=broad]
\defineenumeration[answer]
  [way=bychapter, coupling=question, location=serried, text=, 
distance=0pt, width=broad]
\defineblock[question, answer]
\hideblocks[answer]
\setupblock[question][before=\startquestion,after=\stopquestion]
\setupblock[answer][before=\startanswer,after=\stopanswer]


\starttext
\chapter{Questions}
\beginquestion
Question one
\endquestion
\beginanswer
Answer one
\endanswer

\beginquestion
Question two
\endquestion
\beginanswer
Answer two
\endanswer


\chapter{Answers}
\reset[question,answer]
\useblocks[answer]

\startanswer
Answer three
\stopanswer
\stoptext

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

end of thread, other threads:[~2005-02-14 15:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-14 13:39 Blocks in a macro? Michal Kvasnicka
2005-02-14 14:26 ` Hans Hagen
2005-02-14 15:01   ` Michal Kvasnicka

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