Hello, how are you? :)
In this post I tell you
- How to create macros with optional arguments
We have seen that we can create our own instructions, macros without arguments, and macros with arguments. Sometimes is convenient to set a default argument in a macros and modify it just when we need it, that is what we are going to learn today
Optional Arguments
Macros with one argument
The general structure of that is
\newcommand{name}[Narg][default]{instructions}
-
name
is the name of the command -
Narg
is the number of arguments -
default
is going to be the value which will be the default value, but, also, the argument which will change -
instructions
is what the command will do
Produces
Did you notice? If we want to change the argument we use []
instead of {}
If we do not specify the argument it will show the default command, but if we change, the instruction will change
Macros with multiple arguments
We already know how to set an optional argument but with macros with one argument, what if we want a macros with multiple argument?
Only the first argument may be optional
Produces
We need to call the optional argument with []
as the previous example
This is all for today.
Do not forget to follow me on Twitter @latexteada
Greetings :)
Top comments (0)