Difference between revisions of "System Macros/Action Processing"

From Wiki
Jump to navigation Jump to search
m
m (corrected navigation at bottom)
Line 41: Line 41:
 
</texcode>
 
</texcode>
  
< '''Prev:''' [[System Macros/Branches and Decisions|Branches & Decisions]] | '''Top:''' [[System Macros]] | '''Next:''' [[System Macros/Comma Separated Lists|Comma Separated Lists]] >
+
< '''Prev:''' [[System Macros/Loops and Recursion|Loops & Recusion]] | '''Top:''' [[System Macros]] | '''Next:''' [[System Macros/Comma Separated Lists|Comma Separated Lists]] >
  
 
[[Category:System Macros]]
 
[[Category:System Macros]]
 
[[Category:ConTeXt programming]]
 
[[Category:ConTeXt programming]]

Revision as of 02:42, 1 December 2006

< Prev: Loops & Recursion | Top: System Macros | Next: Comma Separated Lists >

ConTeXt makes extensive use of a sort of case or switch command. Depending of the presence of one or more provided items, some actions is taken. These macros can be nested without problems.

\processaction           [x]     [a=>\a,b=>\b,c=>\c]
\processfirstactioninset [x,y,z] [a=>\a,b=>\b,c=>\c]
\processallactionsinset  [x,y,z] [a=>\a,b=>\b,c=>\c]

This macro is most often used in the key-value parser, like in this (simplified) example, where the user has said width=small or something similar:

\processaction
    [\TESTwidth] % should expand to 'small'
    [small=>\message{small was chosen},
     medium=>\message{medium was chosen}]

You can supply both a default action and an action to be undertaken when an unknown value is met:

\processallactionsinset
    [x,y,z]
    [a=>\a,
     b=>\b,
     c=>\c,
     default=>\default,
     unknown=>\unknown{... \commalistelement ...}]

If the first argument is empty, this macro scans the list for the keyword default and executes the related action, if present. If the first argument is not empty but also not in the list, the action related to unknown is executed. Both keywords must be at the end of list #2. Afterwards, the actually found keyword is available in \commalistelement.

Sometimes an action needs to be undertaken that depends only on the first character of something (for instance, checking if some string represents a number or not). This macro get this character and puts it in \firstcharacter.

\getfirstcharacter {string}

< Prev: Loops & Recusion | Top: System Macros | Next: Comma Separated Lists >