|
|
|||
![]() |
Department of Engineering |
| University of Cambridge > Engineering Department > computing help > LaTeX |
\def\xdt{$\cal X\!\!$\texttt{.desktop}}
One problem that can arise is that your new code can introduce unwanted
space. The Spaces in macros section of the FAQ covers this issue.
\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.
The following weekday macro uses the ifthen
package. Note the use of '%' characters to suppress spaces in the final
output. weekday{3} should print out Wednesday.
\usepackage{ifthen}
\newcommand{\weekday}[1]%
{%
\ifthenelse{\equal{#1}{1}}{Monday}{}%
\ifthenelse{\equal{#1}{2}}{Tuesday}{}%
\ifthenelse{\equal{#1}{3}}{Wednesday}{}%
\ifthenelse{\equal{#1}{4}}{Thursday}{}%
\ifthenelse{\equal{#1}{5}}{Friday}{}%
\ifthenelse{\equal{#1}{6}}{Saturday}{}%
\ifthenelse{\equal{#1}{7}}{Sunday}{}%
}
\weekday{3}
\newcommand\bibname{Bibliography}
so adding
\renewcommand{\bibname}{References}
to your file should achieve what you want.
Counters (e.g. figure - a variable that stores the figure
number) 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 @ character you have to enclose your changes in
\makeatletter ... \makeatother or put the code
into a package. Here's an example that
changes the appearance of section headings, making them into centred
small caps -
\makeatletter
\renewcommand{\section}{\@startsection{section}{1}{0mm}
{\baselineskip}%
{\baselineskip}{\normalfont\normalsize\scshape\centering}}%
\makeatother
\begin{document}
The following's adapted from the TeX Frequently Asked Questions -
Rather than overwriting an old command it's common to want to add some
code at the beginning or the end of it.
Suppose we want a version of a command that does some
small extension of its original definition: we might try:
\renewcommand{\splat}{addedcode\splat}
However, this would not work: a call to \splat would execute
addedcode, and then call the redefined \splat again; this is an infinite recursive loop.
Fortunately, the TeX primitive \let command comes to our rescue; it allows us to take a "snapshot" of the current state of a command, which we can then
use in the redefinition of the command. So:
\let\Oldsplat\splat
\renewcommand{\splat}{addedcode\Oldsplat}
effects the required patch, safely. Adding things at the end of a command
works similarly.
If \splat takes arguments, one must pass them on:
\renewcommand{\splat}[2]{addedcode\Oldsplat{#1}{#2}}
\newenvironment{\
environmentname}[number of arguments][
default value of the 1st (optional) argument]{
entry code, using #1, #2 etc to denote arguments}
{
exit code - arguments can't be used}
Simple use isn't as painful as it looks - the following provides a
variant of the itemize command, emphasising the items.
\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.
produces
\renewenvironment is used to change existing environments, but you can't change the number of arguments an environment takes.
| | computing help | LaTeX | |