Latex typesetting is made by using special tags or commands that provide a
handful of ways to format your document. Sometimes standard commands are not
enough to fulfil some specific needs, in such cases new commands can be
defined and this article explains how.
Commands
Introduction
Most of the LaTeX commands are simple words preceded by a special character.
Defining a new command
New commands are defined by \newcommand statement, let's see an example of the simplest usage.
CODE - NEW COMMAND
\documentclass{article}
\title{Hello World}
\date{November 9, 2018}
\begin{document}
\maketitle
\newcommand{\proof}{example of a new command}
proof
\end{document}
base structure for a new command: \newcommand{⟨name⟩}[⟨number of arguments⟩]{⟨definition⟩}
- Name it is the name given to the new command.
- Number of arguments it is the number of obligatory subjects assigned to it, up to a maximum of nine. If you do not specify this value, the new command will have no arguments.
- Definition are the instructions that specify what you want the new command to "do". The arguments eventually assigned to the command are indicated in the ⟨definition⟩ with # followed by a sequential number: # 1, # 2, etc.
CODE - NEW COMMAND
\documentclass{article}
\title{Hello World}
\date{November 9, 2018}
\begin{document}
\maketitle
\newcommand{\plants} [1]{\textit{#1}}
\plants{Rose}
\end{document}