Changes

Jump to navigation Jump to search
Merge sections
== Using Lua ==
There is a lovely set of functions in the <tt>utilities.parsers</tt> table that turns strings into nice Lua-accessible tables of various kinds. An example is given below; the functions are documented on the [[String_ManipulationString_manipulation#util-prs.lua|string manipulation]] page.
<texcode>
</texcode>
== Using ConTeXt/TeX ==
This section is based on a post on the mailing list by Taco Hoekwater from [[http://www.mail-archive.com/ntg-context@ntg.nl/msg03235.html 2004-06-28]] and Hans Hagen from [[https://www.mail-archive.com/ntg-context@ntg.nl/msg100795.html 2021-12-14]].
=== Example code 1 === To parse your own optional keyval argument from a command. You may want to adapt the logic according to your needs. Note that in the example below, <tt>[#1]</tt> is not optional.  <texcode>\tolerant\protected\def\MyCommand[#1]#2 {\ifempty{#1}% I only got \quote{#2}. \orelse\ifhastok={#1}% \getdummyparameters[MyOwnKeyOne={},MyOwnKeyTwo={B},#1] % this is to define default values; overwritten when mentioned as part of ",#1" \ifcstok{\dummyparameter{MyOwnKeyOne}}\emptytoks \else % if this one is not empty, we do ... Here is #1! \fi And I also got \quote{#2}. \else #1 and #2 % whatever \fi}</texcode> Of course, one can pass on <tt>#1</tt> as argument to other commands. If <tt>MyOwnKeyOne</tt> is not matched by its argument list, it's ignored. See also https://www.mail-archive.com/ntg-context@ntg.nl/msg100795.html for more complex cases and other variants. === Example 2 ===
<texcode>
</texcode>
=== The same example, Example 2 with commentary ===
The 'key' to the keyval functionality in ConTeXt are two macros called
</texcode>
[[Category:Inside ConTeXtProgramming and Databases]][[Category:Tools]]
57

edits

Navigation menu