Changes

Jump to navigation Jump to search
→‎Problems with expansion: handle unknown values in MkII
< '''Prev:''' [[System_MacrosSystem Macros/Loops_and_Recursion|Loops & Recursion]] | '''Top:''' [[System Macros]] | '''Next:''' [[System Macros/Comma Separated Lists|Comma Separated Lists]] > [[Category:System Macros]][[Category:ConTeXt programming]]
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.
\getfirstcharacter {string}
</texcode>
 
== Problems with expansion ==
Be aware that <code>\processaction</code> is not fully expandable. This means that the following won't work.
 
<texcode>
\def\MyMacro#1{\processaction[#1][a=>\a,b=>\b]}
\edef\x{\MyMacro{a}}
</texcode>
 
A solution in MkIV proposed by Taco on [[http://archive.contextgarden.net/message/20100513.073030.d6d1fa3a.en.html 2010-05-13]] is to define <code>\MyMacro</code> as follows
 
<texcode>
\def\MyMacro#1{\directlua{
local known = {a = '\a', b = '\b'}
tex.sprint(known['#1'] or '\a')}}
</texcode>
 
Another way that should work in MkII too:
 
<texcode>
\getparameters[MyMacro:][a=\a,b=\b]
\def\MyMacro#1{\doifdefinedelse{MyMacro:#1}{\getvalue{MyMacro:#1}}{\a}}
</texcode>
 
 
< '''Prev:''' [[System Macros/Loops and Recursion|Loops & Recusion]] | '''Top:''' [[System Macros]] | '''Next:''' [[System Macros/Comma Separated Lists|Comma Separated Lists]] >
 
[[Category:System Macros]]
[[Category:ConTeXt programming]]
3

edits

Navigation menu