Department of Engineering

IT Services

Customising

Macros

At the top of the source of this file is

\def\xdt{$\cal X\!\!$\texttt{.desktop}}

which defines \xdt to be $\cal X\!\!$.desktop. Using such constructions can make your document much tidier, and saves on typing.

Modifications

Many of the features of a LATEX document are easily customised, but you'll often have to look at the class (.cls) files to find out what to do. For example, suppose you wanted to have References in a book rather than Bibliography. If you look in book.cls you'll see

   \newcommand\bibname{Bibliography}

so adding

   \renewcommand{\bibname}{References}

to your file should achieve what you want.

Counters (e.g. figure) have related commands (e.g. thefigure) to control their appearance, so they're easy to customise

 
   \renewcommand\thefigure{\roman{figure}}

produces figure numbers in lower case roman numerals. Longer commands can be adapted too. Remember however, that if the command involves a @ you have to enclose your changes in \makeatletter ... \makeatother. Here's an example that changes the appearance of section headings -

 
\makeatletter
\renewcommand{\section}{\@startsection{section}{1}{0mm}
{\baselineskip}%
{\baselineskip}{\normalfont\normalsize\scshape\centering}}%
\makeatother
\begin{document}

New Commands

A completely new command can be created using

\newcommand{\ commandname}[number of arguments]{ command text, using #1, #2 etc to denote arguments}

For example,

\newcommand{\ve}[1]{\(#1_1 ... #1_n\)}
\ve{x}

produces as output x1 ... xn

A problem with this example is that it shouldn't change to math mode if LATEX is already in that mode. A better try would be

\newcommand{\ve}[1]{\ensuremath{#1_1 ... #1_n}}

which will only change to math mode if it's necessary.

A new environment is just as easily created - give the name of the environment, and what you want to happen on entering and leaving the environment. The following provides a variant of the itemize command.

\newenvironment{emlist}{\begin{itemize} \em}{\end{itemize}}
\begin{emlist}
\item first comment
\item second comment
\end{emlist}
The end of the environment ends the scope of the emphasis.
  • first comment
  • second comment

The end of the environment ends the scope of the emphasis.

Packages

There are many features and options not mentioned in this handout. See the packages section of the online LATEX page for more details. You can often find out what you want by looking at the files in the system directories. If your file begins

\documentclass[12pt]{article}

then various macro files are read when you run latex, namely (article.cls and size12.sty). Some of these files are well-enough commented to be useful documentation.

An Example

minipage creates a miniature page complete with its own footnotes etc. It can be created to any set width. Footnotes within a minipage use a different counter to other footnotes1. This example ensures that all the numbers follow on in sequence. The footnotes in minipages are marked by letters rather than numbers, so here the type is changed to arabic.

\begin{minipage}{\textwidth}
% Set the minipage footnote counter
\setcounter{mpfootnote}{\value{footnote}}
% Redefine the command that produces the footnote number
\renewcommand{\thempfootnote}{\arabic{mpfootnote}}
\begin{tabular}{|ll|}\hline
one & two\footnote{A minipage footnote}\\\hline
\end{tabular}
\setcounter{footnote}{\value{mpfootnote}}
\end{minipage}
one two1


1 A minipage footnote


You might find this trick useful if you want footnotes in tables. They don't come out otherwise.2

Here's an example of using a package. The multicol file lets one change the number of columns easily. To switch into 3-column text use

\begin{multicols}{3}{
Put the text here. Maths, tables, pictures etc are all ok, but not
figures. But you have to remember to load in the \texttt{multicol}
package at the top of your document.
}
\end{multicols}

Put the text here. Maths, tables, pictures etc are all ok, but not figures. But you have to remember to load in the multicol package at the top of your document. LATEX uses the value of the environmental variable TEXINPUTS to decide where to look for sty files. If you create a directory called (say) inputs, copy a system *.sty file into it and do

 
export TEXINPUTS=inputs//:${TEXINPUTS:-:}

then your copy will be read in preference to the system one and you can customise easily.