Debian Codegraph @

texmf-dist/doc/metapost/base/source-tutorial/label.tex

raw
1 \subsection{The \texttt{label} command}
2
3 One of the nicest features of \MP{} is that it relies on \TeX{} (or
4 \LaTeX) to typeset labels within figures. Almost all figures in
5 technical documents are accompanied by labels which help clarify the
6 situation for which the figure is assisting to illustrate. Such labels
7 may include anything from simple typesetting as in
8 Figures~\ref{fig:draw1}, \ref{fig:annulus2}, and~\ref{fig:draw2} to
9 typesetting function declarations and even axes labeling.
10
11 The |label| command requires two arguments\Dash a string to typeset and
12 the point for which label is placed. For example, the command
13
14 \begin{lstlisting}[style=MP]
15 label("A", (0,0));
16 \end{lstlisting}
17 will place the letter ``A'' at the coordinate |(0,0)| and the box around
18 this label is centered vertically and horizontally at this point.
19 Simple strings like \lstinline[style=text]{"A"} require no real
20 typesetting to ensure that they appear properly in the figure. However,
21 many typeset strings in technical figures require the assistance of
22 \TeX{} to properly display them.
23
24 \begin{figure}
25 \begin{withattachment}{parabola.mp}
26 \centering
27 \includegraphics{parabola.mps}
28 \end{withattachment}
29 \caption{Labeling text}
30 \label{fig:parabola}
31 \end{figure}
32
33 For example, \autoref{fig:parabola} is an example where typesetting is
34 preferred. That is, the axes labels and the function declaration look
35 less than perfect if \TeX{} is not used. For reasons such as this,
36 \MP{} provides a way to \textit{escape} to \TeX{} in order to assist in
37 typesetting the labels. Therefore, instead of labeling the ``A'' as
38 above,
39
40 \begin{lstlisting}[style=MP]
41 label(btex A etex, (0,0));
42 \end{lstlisting}
43 provides a much nicer technique for typesetting the label. The
44 |btex ... etex| block instructs \MP{} to process everything in between
45 |btex| and |etex| using \TeX. Therefore, the function declaration in
46 \autoref{fig:parabola} is labeled using
47
48 \begin{lstlisting}[style=MP]
49 label(btex $f(x)=x^2$ etex, (a,b));
50 \end{lstlisting}
51 where $(a,b)$ is the point for which the label is to be centered.
52
53 Since many \MP{} users prefer to typeset their labels using \LaTeX{}
54 instead of plain \TeX, \MP{} provides a convenient method for
55 accommodating this, done in the preamble of the \MP{} source file. The
56 following code ensures that the |btex ... etex| block escapes to
57 \LaTeX{} (instead of plain \TeX) for text processing.
58
59 \begin{lstlisting}[style=MP]
60 verbatimtex
61 %&latex
62 \documentclass{minimal}
63 \begin{document}
64 etex
65 beginfig(|$n$|);
66 |\quad$\langle\mbox{\normalfont\textit{draw commands}}\rangle$|
67 endfig;
68 end
69 \end{lstlisting}
70
71 Often times it is desirable to typeset labels with a justification that
72 are not necessarily centered. For example, one may wish to place an
73 ``A'' centered horizontally about |(0,0)|, but placed above
74 |(0,0)|. \MP{} provides eight suffixes to accommodate such needs. The
75 suffixes |.lft|, |.rt|, |.bot|, and |.top| align the label on the left,
76 right, bottom, and top, respectively, of the designated point. A hybrid
77 of these four justifications provide four additional ones, namely,
78 |.llft|, |.ulft|, |.lrt|, and |.urt| to align the label on the lower
79 left, upper left, lower right, and upper right, respectively, of the
80 designated point. For example,
81
82 \begin{lstlisting}[style=MP]
83 label.top(btex A etex, (0,0));
84 \end{lstlisting}
85 places the ``A'' directly above |(0,0)|. \autoref{fig:label}
86 demonstrates each of the suffixes and their corresponding placement of
87 the labels.
88
89 \begin{figure}
90 \begin{withattachment}{label.mp}
91 \hfill%
92 \includegraphics{label-1.mps}%
93 \hfill%
94 \includegraphics{label-2.mps}%
95 \hfill\mbox{}%
96 \end{withattachment}
97 \caption{Label suffixes}
98 \label{fig:label}
99 \end{figure}