2

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.

Biki Teron
  • 3,275

2 Answers2

8

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.

David Carlisle
  • 757,742
3

Macros in (La)TeX should be considered a noun. Then, according to Merriam-Webster:

Definition of macro
plural macros
: 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.

Werner
  • 603,163