Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 17, 2021 04:42 pm GMT

LaTeX & Macros: Macros with Arguments

Hello, how are you? :)

In this post I tell you

  • How to declare macros with arguments

Do you remember that in this post I gave you a brief introduction to Macros without arguments, these are helpful in those situations where you need the same expression multiple times, but what if you need to have the same expression but just modify something?

How to declare macros with arguments

The command is the following


ewcommand
{
ame
}[args]{expr}

  • ame
    is the name of the command
  • args is the number of arguments in the command, top 9
  • expr is the expression to manipulate

You already know what is
ame
, but if you have forgotten it, you can check it here

args, this is the number of arguments in the command, in other words, the blanks to be filled

  • If you want 1 argument you put 1, if you want 2 put 2 and so on. The maximum number of arguments is 9

The same number of arguments declared in args must match with the arguments used in the definition of expr

  • To put the position of the commands, we need to use #

The arguments have an order

Let's see some examples to clarify the information

Image description

Let's analyze the code :)

Here I declare two new commands

The command \oneArg has one argument (Which is declared in the square brackets) and this argument is going to be the exponent of x. Can you notice, there is a # this indicates Here is going to be my argument

The command woArgs has two arguments, one is going to be the variable, and the second is going to be the exponent, again, I use # to say Here is going to be my argument

See, when I use these new commands, check that \oneArg has one curly brackets while woArgs has two curly brackets

  • The curly brackets match with the number of arguments

That code produces

Image description

But wait, do you remember that the arguments have an order while declaring them, let's check it

Image description

Here we have two new commands \first and \second they have two arguments, but there are a subtle difference, did you notice it? Yes The position of the arguments Let's see what is the output

Image description

Now you have grasped what have an order means

This is all :)

Thanks for reading.

Do not forget to follow me on Twitter @latexteada

Greetings :)


Original Link: https://dev.to/latexteada/latex-macros-macros-with-arguments-2a42

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To