Command/defineitemgroup

From Wiki
< Command
Revision as of 16:47, 25 August 2013 by Thangalin (talk | contribs) (Created page with " == Defining lists == Defining {{\itemize}} like *itemgroups* is accomplished through {{\defineitemgroup}} and the correspoding setup. For historical reasons these have a non-st...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Defining lists

Defining Template:\itemize like *itemgroups* is accomplished through Template:\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.

Custom bullets

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

The macro generator here is Template:\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 Template:\currentitemnumber. To achieve the “item number in a box” effect we have to draw this number as the contents of the box like so:

The Template:\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