• 沒有找到結果。

Fonts and Sizes

6.1.5 Your Own Package

If you define a lot of new environments and commands, the preamble of your document will get quite long. In this situation, it is a good idea to create a LATEX package containing all your command and environment definitions.

You can then use the \usepackage command to make the package available in your document.

% Demo Package by Tobias Oetiker

\ProvidesPackage{demopack}

\newcommand{\tnss}{The not so Short Introduction to \LaTeXe}

\newcommand{\txsit}[1]{The \emph{#1} Short Introduction to \LaTeXe}

\newenvironment{king}{\begin{quote}}{\end{quote}}

Figure 6.1: Example Package.

Writing a package basically consists of copying the contents of your doc-ument preamble into a separate file with a name ending in .sty. There is one special command,

\ProvidesPackage{package name}

for use at the very beginning of your package file. \ProvidesPackage tells LATEX the name of the package and will allow it to issue a sensible error message when you try to include a package twice. Figure6.1 shows a small example package that contains the commands defined in the examples above.

6.2 Fonts and Sizes

6.2.1 Font Changing Commands

LATEX chooses the appropriate font and font size based on the logical struc-ture of the document (sections, footnotes, . . . ). In some cases, one might like to change fonts and sizes by hand. To do this, you can use the com-mands listed in Tables 6.1and 6.2. The actual size of each font is a design issue and depends on the document class and its options. Table 6.3 shows the absolute point size for these commands as implemented in the standard document classes.

{\small The small and

\textbf{bold} Romans ruled}

{\Large all of great big

\textit{Italy}.}

The small and bold Romans ruled

all of

great big Italy.

One important feature of LATEX 2ε is that the font attributes are indepen-dent. This means that you can issue size or even font changing commands, and still keep the bold or slant attribute set earlier.

In math mode you can use the font changing commands to temporarily exit math mode and enter some normal text. If you want to switch to another font for math typesetting you need another special set of commands; refer to Table6.4.

In connection with the font size commands, curly braces play a significant role. They are used to build groups. Groups limit the scope of most LATEX commands.

He likes {\LARGE large and

{\small small} letters}. He likes

large and

small

letters

. The font size commands also change the line spacing, but only if the paragraph ends within the scope of the font size command. The closing curly brace } should therefore not come too early. Note the position of the

\par command in the next two examples. 1

1\par is equivalent to a blank line

Table 6.1: Fonts.

\textrm{...} roman \textsf{...} sans serif

\texttt{...} typewriter

\textmd{...} medium \textbf{...} bold face

\textup{...} upright \textit{...} italic

\textsl{...} slanted \textsc{...} small caps

\emph{...} emphasized \textnormal{...} document font

Table 6.2: Font Sizes.

\tiny tiny font

\scriptsize very small font

\footnotesize quite small font

\small small font

\normalsize normal font

\large large font

\Large

larger font

\LARGE

very large font

\huge

huge

\Huge

largest

6.2 Fonts and Sizes 107

Table 6.3: Absolute Point Sizes in Standard Classes.

size 10pt (default) 11pt option 12pt option

\tiny 5pt 6pt 6pt

\scriptsize 7pt 8pt 8pt

\footnotesize 8pt 9pt 10pt

\small 9pt 10pt 11pt

\normalsize 10pt 11pt 12pt

\large 12pt 12pt 14pt

\Large 14pt 14pt 17pt

\LARGE 17pt 17pt 20pt

\huge 20pt 20pt 25pt

\Huge 25pt 25pt 25pt

Table 6.4: Math Fonts.

\mathrm{...} Roman Font

\mathbf{...} Boldface Font

\mathsf{...} Sans Serif Font

\mathtt{...} Typewriter Font

\mathit{...} Italic Font

\mathcal{...} CALLIGRAPHIC FONT

\mathnormal{...} N ormal F ont

{\Large Don’t read this! It is not true. You can believe me!\par}

Don’t read this! It is not true.

You can believe me!

{\Large This is not true either.

But remember I am a liar.}\par

This is not true either. But re-member I am a liar.

If you want to activate a size changing command for a whole paragraph of text or even more, you might want to use the environment syntax for font changing commands.

\begin{Large}

This is not true.

But then again, what is these days \ldots

\end{Large}

This is not true. But then again, what is these days . . .

This will save you from counting lots of curly braces.

6.2.2 Danger, Will Robinson, Danger

As noted at the beginning of this chapter, it is dangerous to clutter your document with explicit commands like this, because they work in opposition to the basic idea of LATEX, which is to separate the logical and visual markup of your document. This means that if you use the same font changing com-mand in several places in order to typeset a special kind of information, you should use \newcommand to define a “logical wrapper command” for the font changing command.

\newcommand{\oops}[1]{\textbf{#1}}

Do not \oops{enter} this room, it’s occupied by a \oops{machine}

of unknown origin and purpose.

Do not enter this room, it’s occupied by a machine of unknown origin and purpose.

This approach has the advantage that you can decide at some later stage that you want to use some visual representation of danger other than

\textbf, without having to wade through your document, identifying all the occurrences of \textbf and then figuring out for each one whether it was used for pointing out danger or for some other reason.

6.2.3 Advice

To conclude this journey into the land of fonts and font sizes, here is a little word of advice: