Changes

Jump to navigation Jump to search
\stoptext
</context>
 
=== Pitfalls ===
 
Please keep in mind that <code>\iffirstargument</code> will always return true if you put before it a command which itself has an argument. See the following example:
 
<context source="yes" text="produces">
\def\mynewcommand{\dosingleempty\doMyNewCommand}
\def\doMyNewCommand[#1]#2{%
\startalignment[center]
\iffirstargument
There is an optional parameter: {\bf #1}\par
\else
No optional parameter\par
\fi
This is the mandatory text: {\em #2}
\stopalignment
}
\starttext
\mynewcommand[opt]{Hello People}
\blank
\mynewcommand{Hello People}
\stoptext
</context>
 
Use <code>\doifsomethingelse</code> instead:
 
<context source="yes" text="this time is correct:">
\def\mynewcommand{\dosingleempty\doMyNewCommand}
\def\doMyNewCommand[#1]#2{%
\startalignment[center]
\doifsomethingelse{#1}
{There is an optional parameter: {\bf #1}\par}
{No optional parameter\par}
This is the mandatory text: {\em #2}
\stopalignment
}
\starttext
\mynewcommand[opt]{Hello People}
\blank
\mynewcommand{Hello People}
\stoptext
</context>
 
[[Category:Inside ConTeXt]]
43

edits

Navigation menu