
\documentclass[10pt]{amsart}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{local}


   \oddsidemargin=0in
   \evensidemargin=0in
   \textwidth=6.5in

\renewcommand{\a}{\alpha}
\newcommand{\bQ}{\mathbb{Q}}
\newcommand{\Q}{\mathbf{Q}}
\newcommand{\Hom}[3]{\mathrm{Hom}_{#1}\left(#2,#3\right)}

\DeclareMathOperator{\GL}{GL}

\begin{document}
\filename
\centerline{\LaTeX\ {\sc Seminar: Defining Macros}}



Often with \LaTeX, one finds that certain symbols are used over and over again.  For example, any number theorist is bound to use
the symbol $\Q$ (or $\bQ$ if you prefer) for the rational numbers countless times in the course of their \TeX\ career.  It would be a major
pain if every time one wanted to print this symbol, the commands \verb=\mathbf{Q}= or \verb=\mathbb{Q}= had to be issued.
The real power of \TeX\ lies in its ready customizability.

\section{Defining Commands Without Argument}

First, and importantly, all macros and user defined commands {\em must} appear before the \verb=\begin{documant}=
command but after the \verb=\documentclass= and \verb=\usepackage= commands.
Two of the simplest and most useful commands for writing macros are
\verb=\newcommand= and \verb=\renewcommand=.
In both cases, the format is
\begin{verbatim}
    \newcommand{\name}{command}.
\end{verbatim}
Here, \verb=name= is the name given to the command, and \verb=command= is the long, explicit version of what you want \verb=\name=
to do every time it is issued.  For example, we have written the macro
\begin{verbatim}
    \newcommand{\Q}{\mathbf{Q}},
\end{verbatim}
which prints $\Q$ every time \verb=\Q= is written in math mode (observe that \verb=\mathbf= is only valid in math mode).
Sometimes, you will define a command that \LaTeX\ has already defined.  In general, you should find out what the predefined
command does, and if it is something essential or really useful, you probably should think up a different name.  If it is dispensible, though,
use the command \verb=\renewcommand= which redefines the symbol to your specifications.  For example, after writing the macro
\begin{verbatim}
    \renewcommand{\a}{\alpha},
\end{verbatim}
we can easily print $\a,\a,\a,\a$ with two short character strokes.

\section{Commands With Argument}

Macros can also accept multiple arguments.  The general command to write such macros is
\begin{verbatim}
    \newcommand{\name}[narg]{command},
\end{verbatim}
where \verb=narg= is a positive integer indicating the number of arguments that \verb=\name= is to take.  When
\verb=\name= is called, the syntax is \verb=\name{arg1}{arg2}...{argn}=.  The variable \verb=#j= is used for
the $j^{\text{th}}$ argument.  Thus, for example, defining the command
\begin{verbatim}
    \newcommand{\Hom}[3]{\mathrm{Hom}_{#1}\left(#2,#3\right)}
\end{verbatim}
defines a new command \verb=\Hom= with three arguments.  Thus, when we issue the command \verb=\Hom{k}{V}{W}=
we get
$$\Hom{k}{V}{W}.$$

\section{Declaring Math Operator}

Many times, it is convenient to be able to produce roman script operators such as $\sin,\cos,\log,\lim$ in math mode.
If these are just called by typing \verb=$sin,cos,log,lim$= the result will be
$$sin, cos, log, lim$$ instead of
$$\sin,\cos,\log,\lim$$ as desired.  It so happens that the commands \verb=\sin,\cos,\log,\lim= are already
defined in \LaTeX\ and produce these symbols.  If we want to define similar operators that will print in roman script,
we can issue the command (again, in the preamble, where all the new commands are defined)
\begin{verbatim}
    \DeclareMathOperator{\name}{operator},
\end{verbatim}
where \verb=\name= is the command that will be issued to produce \verb=operator= in roman script.
Thus, we have defined \verb=\DeclareMathOperator{\GL}{GL}=
so that we can print $\GL(V)$ without having to type \verb=\mathrm{GL}(V)= every time.

One can also define new environments in \LaTeX, but this is beyond the scope of the seminar, and an appropriate reference
should be consulted.  Play around with the file \verb=comm.tex= and write some useful macros.

\end{document}
