Changes

Jump to navigation Jump to search
1,660 bytes removed ,  09:23, 1 August 2006
[[System_Macros/Branches_and_Decisions]]
== Cases == 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. <texcode>\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]<System_Macros/texcode> This macro is most often used in the <code>key-value</code> parser, like in this (simplified) example, where the user has said width=small or something similar: <texcode>\processaction [\TESTwidthProcessing_Actions] % should expand to 'small' [small=>\message{small was chosen}, medium=>\message{medium was chosen}]</texcode> You can supply both a <code>default</code> action and an action to be undertaken when an <code>unknown</code> value is met: <texcode>\processallactionsinset [x,y,z] [a=>\a, b=>\b, c=>\c, default=>\default, unknown=>\unknown{... \commalistelement ...}]</texcode> If the first argument is empty, this macro scans the list for the keyword <code>default</code> and executes the related action, if present. If the first argument is not empty but also not in the list, the action related to <code>unknown</code> is executed. Both keywords must be at the end of list <code>#2</code>. Afterwards, the actually found keyword is available in <code>\commalistelement</code>. 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 <code>\firstcharacter</code>. <texcode>\getfirstcharacter {string}</texcode>
== Comma separated lists ==

Navigation menu