Difference between revisions of "Command/useblocks"

From Wiki
Jump to navigation Jump to search
(Created page with "Documentation for \useblocks")
 
Line 32: Line 32:
  
 
% We don't want to display blocks when we define them.
 
% We don't want to display blocks when we define them.
\hideblocks[myquestion,myanswer]  
+
\hideblocks[myquestion,myanswer]
  
 
\starttext
 
\starttext
Line 87: Line 87:
 
<cd:commandref name="defineblock">to define a new kind of block.</cd:commandref>
 
<cd:commandref name="defineblock">to define a new kind of block.</cd:commandref>
 
<cd:commandref name="setupblock">to set up block style.</cd:commandref>
 
<cd:commandref name="setupblock">to set up block style.</cd:commandref>
<cd:commandref name="keepblocks">to start displaying blocks where they are defined.</cd:commandref></cd:seealso>
+
<cd:commandref name="keepblocks">to start displaying blocks where they are defined.</cd:commandref>
 +
<cd:commandref name="hideblocks">to stop displaying blocks where they are defined.</cd:commandref>
 +
<cd:commandref name="selectblocks">to display only blocks mentioned in the current section.</cd:commandref>
 +
<cd:commandref name="processblocks">to process blocks without printing them.</cd:commandref></cd:seealso>
 
</cd:commandgroup>
 
</cd:commandgroup>

Revision as of 15:37, 18 November 2021


\useblocks

Summary

The command \useblocks is used to typeset blocks

Settings

\useblocks[...,...][...,...][...=...,...]
[...,...]name
[...,...]name
criteriumtext section

Description

Typesets all the requested blocks defined in the document, in the order in which they were defined. An optional second argument can be used to print only blocks with certain tags.

Examples

Example 1

\setuppapersize[A7]
\defineblock[myquestion]
\defineblock[myanswer]

% We don't want to display blocks when we define them.
\hideblocks[myquestion,myanswer]

\starttext
\beginmyquestion[first]
First question, defined at the start
\endmyquestion

\beginmyanswer[first]
First answer
\endmyanswer

\subsection{My questions and answers, original interleaving}
\useblocks[myquestion,myanswer]

\subsection{Only the first answer}
\useblocks[myanswer][first]

\beginmyquestion
Second block, defined at the end
\endmyquestion

\beginmyanswer
Second answer, also defined at the end
\endmyanswer

\subsection{You can't select by tag only}
\useblocks[first]   % produces nothing
\useblocks[][first] % produces nothing

\stoptext

This gives:

Test if a block is empty or not

In some cases, one may want use the collected blocks, e. g., at the end of a chapter, preceded (of course) with a section header. However, some chapters may not have had blocks, so that an empty section would appear. In this case, \doifelseblocksempty it comes in handy to test if a block is empty or not (will work from some upload in Aug 2021 onwards):

\setuppapersize[A7]
\defineblock[testa]
\defineblock[testb]

\starttext

\begintestb
Test B was a great!
\endtestb

\doifelseblocksempty {testa}{}{} {\section{Test A}} {Nothing to show here} % {name}{tag}{criterium}
\doifelseblocksempty {testb}{}{} {\section{Test B}} {Nothing to show here} % {name}{tag}{criterium}

\stoptext

Notes

See also

Help from ConTeXt-Mailinglist/Forum

All issues with: