Definitions
LaTeX has support for making new commands of many different kinds.

\newcommand & \renewcommand
\newcommand and \renewcommand define and redefine a command, respectively. Synopses:

  \newcommand{cmd}[nargs][optargdefault]{defn}
  \newcommand*{cmd}[nargs][optargdefault]{defn}
\renewcommand{cmd}[nargs][optargdefault]{defn}
\renewcommand*{cmd}[nargs][optargdefault]{defn}

The *-form of these two commands requires that the arguments not contain multiple paragraphs of text (not \long, in plain TeX terms).
cmd 	Required; the command name. It must begin with \. For \newcommand, it must not be already defined and must not begin with \end. For \renewcommand, it must already be defined.
nargs 	Optional; an integer from 0 to 9, specifying the number of arguments that the command will take. If this argument is not present, the default is for the command to have no arguments. When redefining a command, the new version can have a different number of arguments than the old version.
optargdefault 	Optional; if this argument is present then the first argument of defined command \cmd is optional, with default value optargdefault (which may be the empty string). If this argument is not present then \cmd does not take an optional argument.
That is, if \cmd is used with square brackets following, as in \cmd[myval], then within defn #1 expands myval. While if \cmd is called without square brackets following, then within defn the #1 expands to the default optargdefault. In either case, any required arguments will be referred to starting with #2.
Omitting [myval] in the call is different from having the square brackets with no contents, as in []. The former results in #1 expanding to optargdefault; the latter results in #1 expanding to the empty string.
defn 	The text to be substituted for every occurrence of cmd; a construct of the form #n in defn is replaced by the text of the nth argument.
A command with no arguments that is followed in the source by a space will swallow that space. The solution is to type {} after the command and before the space.
A simple example of defining a new command: \newcommand{\JH}{Jim Hef{}feron} causes the abbreviation \JH to be replaced by the longer text.
Redefining a command is basically the same: \renewcommand{\qedsymbol}{{\small QED}}.
Here’s a command definition that uses arguments:

\newcommand{\defreference}[1]{Definition~\ref{#1}}

Then, \defreference{def:basis} will expand to something like ‘Definition~3.14’.
An example with two arguments: \newcommand{\nbym}[2]{#1\!\times\!#2} is invoked as \nbym{2}{k}.
An example with optional arguments:

\newcommand{\salutation}[1][Sir or Madam]{Dear #1:}

Then, \salutation gives ‘Dear Sir or Madam:’ while \salutation[John] gives ‘Dear John:’. And \salutation[] gives ‘Dear :’.
The braces around defn do not delimit the scope of the result of expanding defn. So \newcommand{\shipname}[1]{\it #1} is wrong since in the sentence

The \shipname{Monitor} met the \shipname{Virginia}.

the words ‘met the’ will incorrectly be in italics. An extra pair of braces \newcommand{\shipname}[1]{{\it #1}} fixes it.

\providecommand
Defines a command, as long as no command of this name already exists. Synopses:

\providecommand{cmd}[nargs][optargdefault]{defn}
\providecommand*{cmd}[nargs][optargdefault]{defn}

If no command of this name already exists then this has the same effect as \newcommand (see \newcommand & \renewcommand). If a command of this name already exists then this definition does nothing. This is particularly useful in a style file, or other file that may be loaded more than once.

\newcounter: Allocating a counter
Synopsis:

\newcounter{countername}[supercounter]

The \newcounter command globally defines a new counter named countername. The name consists of letters only and does not begin with a backslash (‘\’). The name must not already be used by another counter. The new counter is initialized to zero.
If the optional argument [supercounter] appears, then countername will be numbered within, or subsidiary to, the existing counter supercounter. For example, ordinarily subsection is numbered within section. Any time supercounter is incremented with \stepcounter (see \stepcounter) or \refstepcounter (see \refstepcounter) then countername is reset to zero.
See Counters, for more information about counters.

\newlength: Allocating a length
Allocate a new length register. Synopsis:

\newlength{\arg}

This command takes one required argument, which must begin with a backslash (‘\’). It creates a new length register named \arg, which is a place to hold (rubber) lengths such as 1in plus.2in minus.1in (what plain TeX calls a skip register). The register gets an initial value of zero. The control sequence \arg must not already be defined.
See Lengths, for more about lengths.

\newsavebox: Allocating a box
Allocate a “bin” for holding a box. Synopsis:

\newsavebox{\cmd}

Defines \cmd to refer to a new bin for storing boxes. Such a box is for holding typeset material, to use multiple times (see Boxes) or to measure or manipulate. The name \cmd must start with a backslash (‘\’), and must not be already defined.
The allocation of a box is global. This command is fragile (see \protect).

\newenvironment & \renewenvironment
These commands define or redefine an environment env, that is, \begin{env} … \end{env}. Synopses:

  \newenvironment{env}[nargs][optargdefault]{begdefn}{enddefn}
  \newenvironment*{env}[nargs][optargdefault]{begdefn}{enddefn}
\renewenvironment{env}[nargs][optargdefault]{begdefn}{enddefn}
\renewenvironment*{env}[nargs][optargdefault]{begdefn}{enddefn}

Unlike \newcommand and \renewcommand, the *-forms \newenvironment* and \renewcommand* have the same effect as the forms with no *.
env 	Required; the environment name. It does not begin with backslash (\). It must not begin with the string end. For \newenvironment, the name env must not be the name of an already existing environment, and also the command \env must be undefined. For \renewenvironment, env must be the name of an existing environment.
nargs 	Optional; an integer from 0 to 9 denoting the number of arguments of that the environment will take. These arguments appear after the \begin, as in \begin{env}{arg1}…{argn}. If this argument is not present then the default is for the environment to have no arguments. When redefining an environment, the new version can have a different number of arguments than the old version.
optargdefault 	Optional; if this argument is present then the first argument of the defined environment is optional, with default value optargdefault (which may be the empty string). If this argument is not present then the environment does not take an optional argument.
That is, when [optargdefault] is present in the environment definition, if \begin{env} is used with square brackets following, as in \begin{env}[myval], then within the environment #1 expands myval. If \begin{env} is called without square brackets following, then within the environment the #1 expands to the default optargdefault. In either case, any required arguments will be referred to starting with #2.
Omitting [myval] in the call is different from having the square brackets with no contents, as in []. The former results in #1 expanding to optargdefault; the latter results in #1 expanding to the empty string.
begdefn 	Required; the text expanded at every occurrence of \begin{env}; a construct of the form #n in begdef is replaced by the text of the nth argument.
enddefn 	Required; the text expanded at every occurrence of \end{env}. Note that it may not contain any argument parameters, so #n cannot be used here.
The environment env delimits the scope of the result of expanding begdefn and enddefn. Thus, in the first example below, the effect of the \small is limited to the quote and does not extend to material following the environment.
This example gives an environment like LaTeX’s quotation except that it will be set in smaller type.

\newenvironment{smallquote}{%
  \small\begin{quotation}
}{%
  \end{quotation}
}

This shows the use of arguments; it gives a quotation environment that cites the author.

\newenvironment{citequote}[1][Shakespeare]{%
  \begin{quotation}
  \noindent\textit{#1}: 
}{%
  \end{quotation}
}

The author’s name is optional, and defaults to Shakespeare. In the document, use the environment as here:

\begin{citequote}[Lincoln]
  ..
\end{citequote}

The final example shows how to save the value of an argument to use in enddefn.

\newsavebox{\quoteauthor}
\newenvironment{citequote}[1][Shakespeare]{%
  \sbox\quoteauthor{#1}%
  \begin{quotation} 
}{%
  \hspace{1em plus 1fill}---\usebox{\quoteauthor}
  \end{quotation}
}

\newtheorem
Define a new theorem-like environment. Synopses:

\newtheorem{name}{title}[numbered_within]
\newtheorem{name}[numbered_like]{title}

Both create a theorem-like environment name. Using the first form,

\newtheorem{name}{title}[numbered_within]

with the optional argument after the second required argument, creates an environment whose counter is subordinate to the existing counter numbered_within: it will be reset when numbered_within is reset).
Using the second form,

\newtheorem{name}[numbered_like]{title}

with the optional argument between the two required arguments, will create an environment whose counter will share the previously defined counter numbered_like.
You can specify one of numbered_within and numbered_like, or neither, but not both.
This command creates a counter named name. In addition, unless the optional argument numbered_like is used, the current \ref value will be that of \thenumbered_within (see \ref).
This declaration is global. It is fragile (see \protect).
Arguments:
name 	The name of the environment. It must not begin with a backslash (‘\’). It must not be the name of an existing environment; indeed, the command name \name must not already be defined as anything.
title 	The text printed at the beginning of the environment, before the number. For example, ‘Theorem’.
numbered_within 	Optional; the name of an already defined counter, usually a sectional unit such as chapter or section. When the numbered_within counter is reset then the name environment’s counter will also be reset.
If this optional argument is not used then the command \thename is set to \arabic{name}.
numbered_like 	Optional; the name of an already defined theorem-like environment. The new environment will be numbered in sequence with numbered_like.
Without any optional arguments the environments are numbered sequentially. This example has a declaration in the preamble that results in ‘Definition 1’ and ‘Definition 2’ in the output.

\newtheorem{defn}{Definition}
\begin{document}
\section{...}
\begin{defn}
  First def 
\end{defn}

\section{...}
\begin{defn}
  Second def
\end{defn}

Because this example specifies the optional argument numbered_within to \newtheorem as section, the example, with the same document body, gives ‘Definition 1.1’ and ‘Definition 2.1’.

\newtheorem{defn}{Definition}[section]
\begin{document}
\section{...}
\begin{defn}
  First def 
\end{defn}

\section{...}
\begin{defn}
  Second def
\end{defn}

In this example there are two declarations in the preamble, the second of which calls for the new thm environment to use the same counter as defn. It gives ‘Definition 1.1’, followed by ‘Theorem 2.1’ and ‘Definition 2.2’.

\newtheorem{defn}{Definition}[section]
\newtheorem{thm}[defn]{Theorem}
\begin{document}
\section{...}
\begin{defn}
  First def 
\end{defn}

\section{...}
\begin{thm}
  First thm
\end{thm}

\begin{defn}
  Second def
\end{defn}

\newfont: Define a new font (obsolete)
\newfont, now obsolete, defines a command that will switch fonts. Synopsis:

\newfont{\cmd}{font description}

This defines a control sequence \cmd that will change the current font. LaTeX will look on your system for a file named fontname.tfm. The control sequence must must not already be defined. It must begin with a backslash (‘\’).
This command is obsolete. It is a low-level command for setting up an individual font. Today fonts are almost always defined in families (which allows you to, for example, associate a boldface with a roman) through the so-called “New Font Selection Scheme”, either by using .fd files or through the use of an engine that can access system fonts such as XeLaTeX (see TeX engines).
But since it is part of LaTeX, here is an explanation: the font description consists of a fontname and an optional at clause; this can have the form either at dimen or scaled factor, where a factor of ‘1000’ means no scaling. For LaTeX’s purposes, all this does is scale all the character and other font dimensions relative to the font’s design size, which is a value defined in the .tfm file.
This example defines two equivalent fonts and typesets a few characters in each:

\newfont{\testfontat}{cmb10 at 11pt}
\newfont{\testfontscaled}{cmb10 scaled 11pt}
\testfontat abc
\testfontscaled abc

\protect
All LaTeX commands are either fragile or robust. Footnotes, line breaks, any command that has an optional argument, and many more, are fragile. A fragile command can break when it is used in the argument to certain commands. To prevent such commands from breaking they must be preceded by the command \protect.
For example, when LaTeX runs the \section{section name} command it writes the section name text to the .aux auxiliary file, moving it there for use elsewhere in the document such as in the table of contents. Any argument that is internally expanded by LaTeX without typesetting it directly is referred to as a moving argument. A command is fragile if it can expand during this process into invalid TeX code. Some examples of moving arguments are those that appear in the \caption{..} command (see figure), in the \thanks{..} command (see \maketitle), and in @-expressions in the tabular and array environments (see tabular).
If you get strange errors from commands used in moving arguments, try preceding it with \protect. Every fragile commands must be protected with their own \protect.
Although usually a \protect command doesn’t hurt, length commands are robust and should not be preceded by a \protect command. Nor can a \protect command be used in the argument to \addtocounter or \setcounter command.
In this example the caption command gives a mysterious error about an extra curly brace. Fix the problem by preceding each \raisebox command with \protect.

\begin{figure}
  ..
  \caption{Company headquarters of A\raisebox{1pt}{B}\raisebox{-1pt}{C}}
\end{figure}

In the next example the \tableofcontents command gives an error because the \(..\) in the section title expands to illegal TeX in the .toc file. You can solve this by changing \(..\) to \protect\(..\protect\).

\begin{document}
\tableofcontents
 ..
\section{Einstein's \( e=mc^2 \)}
 ..