Changes

Jump to navigation Jump to search
Added example for \command[optional]{text}
If you ''don't'' want any optional arguments, but still want your arguments enclosed in <tt>[]</tt> with appropriate handling for spaces (or line breaks) between the square brackets, use <cmd>dodoubleargument</cmd> instead of <cmd>dodoubleempty</cmd>. There are of course versions for other numbers of arguments, found by replacing <tt>double</tt> with <tt>single</tt> through <tt>seventuple</tt>; see [http://source.contextgarden.net/tex/context/base/syst-gen.mkii syst-gen.tex] for the exact names.
----=== Examples ===
To define <tt>\mycommand[.1.][.2.]{.3.}</tt>, i.e., with curly braces around a non-optional third argument, you just define
\def\doMycommand[#1][#2]#3{whatever}
</texcode>
 
 
 
 
To define <code>\mycommand[optional]{text}</code>, do the following
 
<texcode>
 
\def\mynewcommand{\dosingleempty\doMyNewCommand}
\def\doMyNewCommand[#1]#2{%
\iffirstargument
There is an optional parameter: {\bf #1}\par
\else
No optional parameter\par
\fi
This is the mandatory text: {\em #2}
}
 
\starttext
\mynewcommand[opt]{Hello People}
 
\mynewcommand{Hello People}
\stoptext
</texcode>
 
<context>
 
\def\mynewcommand{\dosingleempty\doMyNewCommand}
\def\doMyNewCommand[#1]#2{%
\iffirstargument
There is an optional parameter: {\bf #1}\par
\else
No optional parameter\par
\fi
This is the mandatory text: {\em #2}
}
 
\starttext
\mynewcommand[opt]{Hello People}
\blank
\mynewcommand{Hello People}
\stoptext
</context>
 
[[Category:Inside ConTeXt]]
43

edits

Navigation menu