# Using commands and environments

Using commands and environments

We have already seen many examples of commands and environments, but now we will formalize the concepts.

### Commands

In LATEX there are seven single character commands, they are #, $, %, &, ~, _, and ^. The octothon (#) is used in creating new commands and environments. We have already seen the dollar sign ($) (used for entering inline math mode), the ampersand (&) (used for vertical alignment), the underscore (_) (used for subscripts), and the caret (^) (used for superscripts) commands. The percent sign (%) is used for making comments in your LATEX document. The compiler will ignore everything on a line after the percent sign. Comments are extremely helpful for both the writer and other readers of LATEX input files. Anyone wishing to make changes to a document, especially long after it was originally written, will find the comments invaluable. Finally, the tilde (~) is used to create unbreakable spaces. That is if you want to have a space appear in your document, but you do not want to have a line break at that space you can use the tilde.

The rest of the LATEX commands consist of a back slash (\) followed by one or more letters or a single special character. Some examples of commands we have already seen are \sin, \varphi, and \cdots. It should be noted that many commands can only be used in math mode. You can produce the TeX and LATEX logos with the commands \TeX and \LATEX. It is important to note that LATEX is case sensitive, so \latex is not the same as \LATEX.

Commands often have arguments. There are two types of arguments, mandatory and optional. As the names imply you must always include mandatory arguments, but optional arguments may or may not be included. Mandatory arguments are enclosed in curly braces ({}) and optional arguments are enclosed in square braces ([]). One example of a command with an option argument is the \sqrt command. The result of adding an optional argument to the \sqrt command can be seen by changing the line $\sqrt{x^{5}} + y_{n}$ to $\sqrt[3]{x^{5}} + y_{n}$ in our document.

### Environments

Environments have the form

\begin{EnvironmentName}

...

\end{EnvironmentName}

We have seen many examples of environments already, such as the document environment, the eqnarray environment, and the equation environment.

### New commands and environments

As noted above LATEX allows you to create your own commands and environments. The ability to create your own commands is what makes LATEX such a powerful tool. Creating your own commands allows you to make a simple change in one place in your document, and have it affect the entire document. Below is the example of an inner product command and an environment with strange tab-sets.