Difference between revisions of "Command/defineitemgroup"

From Wiki
Jump to navigation Jump to search
m
m
Line 1: Line 1:
 
== Defining lists ==
 
== Defining lists ==
  
Defining {{\itemize}} like *itemgroups* is accomplished through {{\defineitemgroup}} and the correspoding setup. For historical reasons these have a non-standard, duplicate interface
+
Defining {{cmd|itemize}} like *itemgroups* is accomplished through {{cmd|defineitemgroup}} and the correspoding setup. For historical reasons these have a non-standard, duplicate interface
 
requiring some options to be specified as key-value setups, others as an argument list.
 
requiring some options to be specified as key-value setups, others as an argument list.
  
 
<code>
 
<code>
\defineitemgroup [myitems]
+
\defineitemgroup[myitems]
\setupitemgroup [myitems] [each] [joinedup]
+
\setupitemgroup [myitems] [each] [joinedup]
\setupitemgroup [myitems] [each] [itemalign=flushright]
+
\setupitemgroup [myitems] [each] [itemalign=flushright]
<code>
+
</code>
  
 
The second argument determines the itemization level the settings apply to.
 
The second argument determines the itemization level the settings apply to.
Line 14: Line 14:
 
The third argument comes in two varieties.
 
The third argument comes in two varieties.
  
Parameters that concern whitespace (both vertical and horizontal) belong in the argument list: ``joinedup``, ``packed``, ``nowhite`` and the likes.
+
Parameters that concern whitespace (both vertical and horizontal) belong in the argument list: joinedup, packed, nowhite, and others.
  
 
Further options are part of the setup. Both kinds can be given in a combined version:
 
Further options are part of the setup. Both kinds can be given in a combined version:
Line 24: Line 24:
 
== Custom bullets ==
 
== Custom bullets ==
  
Bullets are very flexible. They hook into the {{\symbol}} mechanism.
+
Bullets are very flexible. They hook into the {{cmd|symbol}} mechanism.
  
The macro generator here is {{\definesymbol}}. Basically it allows for all valid Context code to appear inside the definition, including the list item counter. This counter can be accessed via {{\currentitemnumber}}. To achieve the “item number in a box” effect we have to draw this
+
The macro generator here is {{cmd|definesymbol}}. Basically it allows for all valid Context code to appear inside the definition, including the list item counter. This counter can be accessed via {{cmd|currentitemnumber}}. To achieve the “item number in a box” effect we have to draw this
 
number as the contents of the box like so:
 
number as the contents of the box like so:
  
<context>
+
<code>
    \definesymbol [instruction_symbol_numbered]
+
\definesymbol [instruction_symbol_numbered]
      [{\framed{\currentitemnumber}}]
+
  [{\framed{\currentitemnumber}}]
</context>
+
</code>
  
The {{\framed}} must be adapted to the specific requirements.
+
The {{cmd|framed}} must be adapted to the specific requirements.
  
 
== Putting it together ==
 
== Putting it together ==
Line 40: Line 40:
 
Below listing combines all the above into one working example.
 
Below listing combines all the above into one working example.
  
<context source=yes>
+
<code>
 
     \unprotect
 
     \unprotect
 
      
 
      
Line 96: Line 96:
 
       \stopInstructions
 
       \stopInstructions
 
     \stoptext
 
     \stoptext
</context>
+
</code>

Revision as of 16:49, 25 August 2013

Defining lists

Defining \itemize like *itemgroups* is accomplished through \defineitemgroup and the correspoding setup. For historical reasons these have a non-standard, duplicate interface requiring some options to be specified as key-value setups, others as an argument list.

\defineitemgroup[myitems] \setupitemgroup [myitems] [each] [joinedup] \setupitemgroup [myitems] [each] [itemalign=flushright]

The second argument determines the itemization level the settings apply to.

The third argument comes in two varieties.

Parameters that concern whitespace (both vertical and horizontal) belong in the argument list: joinedup, packed, nowhite, and others.

Further options are part of the setup. Both kinds can be given in a combined version:

\setupitemgroup [myitems] [each] [joinedup] [itemalign=flushright]

Custom bullets

Bullets are very flexible. They hook into the \symbol mechanism.

The macro generator here is \definesymbol. Basically it allows for all valid Context code to appear inside the definition, including the list item counter. This counter can be accessed via \currentitemnumber. To achieve the “item number in a box” effect we have to draw this number as the contents of the box like so:

\definesymbol [instruction_symbol_numbered]

 [{\framed{\currentitemnumber}}]

The \framed must be adapted to the specific requirements.

Putting it together

Below listing combines all the above into one working example.

   \unprotect
   
   %% the bullet: a red square
   
   \defineframed [instruction_symbol_frame] [
     background=color,
     backgroundcolor=red,
     frame=off,
     width=1em,
     height=\framedparameter{width}, %% -> let height = width
   ]
   
   %% bare bullet
   
   \definesymbol [instruction_symbol]
     [{\instruction_symbol_frame{\strut}}]
   
   %% same bullet, with item number inside
   
   \definesymbol [instruction_symbol_numbered]
     [{\instruction_symbol_frame{\currentitemnumber}}]
   
   %% define the “regular“ itemization with a red box as bullet indicator
   
   \defineitemgroup [RegularList]
   \setupitemgroup [RegularList] [each] [joinedup]
   \setupitemgroup [RegularList] [symbol=instruction_symbol]
   
   %% define the “Instructions” type itemization that includes the item
   %% number inside the box
   
   \defineitemgroup [Instructions]
   \setupitemgroup [Instructions] [each] [joinedup]
   \setupitemgroup [Instructions] [symbol=instruction_symbol_numbered]
   
   \protect
   
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   %% demo
   
   \starttext
     Chemicals
     \startRegularList
       \startitem \input knuth \stopitem
       \startitem \input ward \stopitem
     \stopRegularList
   
     \blank [2*big]
   
     Instructions
     \startInstructions
       \startitem \input knuth \stopitem
       \startitem \input ward \stopitem
     \stopInstructions
   \stoptext