Changes

Jump to navigation Jump to search
Add pitfall with nested macro calls
=== Pitfalls ===
Please keep ==== Passing preceding command's argument ==== 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">
Use <code>\doifsomethingelse</code> instead:
<context source="yes" text="This time this time is correct:">
\def\mynewcommand{\dosingleempty\doMyNewCommand}
\def\doMyNewCommand[#1]#2{%
</context>
==== Calling the macro from within command arguments (e.g. float title) ====
 
-- I have no deeper insight yet on the why and neither on which other cases this might apply to, but I hope it may be useful to someone running into errors.
 
If you wanted to call your macro from within an "argument" such as you would have to with titles or captions in floats:
 
<texcode>
\startplacefigure[title={We look at \mynewcommand{people} in floats}]
(content)
\stopplacefigure
</texcode>
 
The above will create a `"\doMyNewCommand doesn't match its definition"` error.
This can be solved by preceding the definition that takes the optional argument with `\unexpanded`:
 
<texcode>
\unexpanded\def\doMyNewCommand[#1]#2{% ... (etc.)
</texcode>
 
=== Comparison with LaTeX ===
On a final note, for comparative purposes: in LaTeX, a new command with an optional argument is defined with <code>\newcommand</code>.
57

edits

Navigation menu