Many of the latex packages used the term macro what does it mean and what is the definition of macro according to LaTeX and what is the use of this macro? Kindly let me know with examples. Thanking you in advance.
2 Answers
Macro processing is a particular idiom for programming languages see for example wikipedia.
Apart from TeX, other well known macro systems include m4, The C pre-processor, and the SGML/XML/HTML entity mechanism.
Almost all commands that you can define in latex are macros, which are replaced by their definitions of lower-level commands as the macro is "expanded".
In a macro processor (unlike a compiled language) the main mechanism is textual replacement so after
\newcommand\foo{hello}
the input
\foo\space world
the macro \foo is not a pointer to some pre-compiled function, it points to its replacement text and is replaced in line so the processor then sees
hello\space world
just as if that had been the original input, and processing restarts with this as input. (Some details have been omitted in this description)
\space is a macro defined already in LaTeX, expanding to a space so the input finally becomes
hello world
which is a sequence of non expandable tokens which gets passed to TeX's typesetting core.
- 757,742
-
Is there any command that are not macros in LaTeX? @David Carlisle – Biki Teron May 20 '17 at 21:15
-
yes all the TeX primitives for example. macros have to expand to something, so there has, in the end, to be something that they expand to. – David Carlisle May 20 '17 at 21:17
-
Can we say anything which can replace as macros? @David Carlisle – Biki Teron May 20 '17 at 21:21
-
Just you have mentioned in above "main mechanism is textual replacement so after" @David Carlisle – Biki Teron May 20 '17 at 21:23
-
Let us continue this discussion in chat. – Biki Teron May 20 '17 at 21:30
Macros in (La)TeX should be considered a noun. Then, according to Merriam-Webster:
Definition of
macro
pluralmacros
: a single computer instruction that stands for a sequence of operations
All other things coded at the package and class level rely on macros and some deeper primitives - part of the TeX core.
- 603,163