If you see this, something is wrong
First published on Tuesday, Sep 2, 2025 and last modified on Wednesday, Sep 24, 2025 by François Chaplais.
Macros are a programmatic way of defining “shortcuts” in LaTeX. Macros should be defined in the preamble of a document.
Simple macros act really like shortcuts. Here is the syntax.
\newcommand{macro name}{macro definition}For instance, if I define the \lturl to be a macro that creates a link to the LaTeX2Web home page, I can do it as follows.
\newcommand{\lturl}{\url{https://latex2web.app/}}every instance of \lturl will compile as https://latex2web.app/ .
Complex macros accept parameters. Here is the syntax.
\newcommand{macro name}[digit]{macro definition}Here digit is a digit that indicates the number of parameters.
When the macro is executed, for any digit x smaller or equal to digit, any occurence of the string #x in the macro definition will be replaced by the parameter that has been passed to the macro at parsing time. To execute a macro named \macroName in the document, it must be used as follows.
\macroName{arg1}{arg2}....Let us give a practical example. In LaTeX, there is no command to style directly a text in bold and italic at the same time. We implement this as a macro. Here is the definition.
\newcommand{\bi}[1]{\bf{\em{#1}}}The following code \bi{bold italic} will result in bold italic .
Macros can be used in the definition of other macros. For instance, let us say that we want to define bold italic style at a \large size. We can do as follows.
\newcommand{\bil}[1]{\large{\bi{#1}}}The command \bil{large bold italic} will result in large bold italic.
Macros are defined in the preamble using the \newcommand command. The syntax for defining a simple macro is
\newcommand{macro name}{macro definition}The syntax to define a macro that accepts parameters is
\newcommand{macro name}[digit]{macro definition}