Hello, how are you? :)
In this post you I tell you
- How to put or declare math in a macro
Introduction
We have checked two types of macros
- Macros without arguments
- Macros with arguments
And, we have seen that they help us to avoid repeating the same structure many times, but with normal text, not with math.
Math in macros
Today we will meet the instruction
\ensuremath{myEquation}
This command allow us to define macros with math which works in text and math modes, the general structure is
\newcommand{\name}{\ensuremath{myEquation}}
So, you could had thought, I just put the instructions between $
and it is all but no, because if you do that in the macros, in the normal text you need to put the math between $
too, and it is not correct
Here I declared the macro with math using our new instruction, it produces
Did you notice, with ensuremath
you can use your command either between $
or without them
The recommendation is to use the math inside the
$
symbols or\[\]
as we have seen, to have an order and know when something is about math and when it is not related with math
Here is an example where you can play.
What happens if you do not use ensuremath
and want to use a math expression without using $
?
This is all for today
Do not forget to follow me on Twitter @latexteada
Greetings :)
Top comments (0)