Node: Labelling Points, Next: , Previous: Point Drawing Functions, Up: Point Reference



Labelling

Labels make it possible to include TeX text within a drawing. Labels are implemented by means of class Label. The functions label() and dotlabel(), described in this section, create objects of type Label, and add them to the Picture, which was passed to them as an argument (current_picture, by default). See Label Reference, for more information.

void label (const string text_str, [const string position_str = "top", [const bool dot = false, [Picture& picture = current_picture]]]) const function
void label (const short text_short, [const string position_str = "top", [const bool dot = false, [Picture& picture = current_picture]]]) const function
These functions cause a Point to be labelled in the drawing. The first argument is the text of the label. It can either be a string, in the first version, or a short, in the second. It will often be the name of the Point in the C++ code, for example, "p0". It is not possible to automate this kind of labelling, because it is not possible to access the names of variables through the variables themselves in C++ .

text_str is always placed between "btex'' and "etex" in the MetaPost label command written to out_stream. This makes it possible to include math mode material in the text of labels, as in the following example.

          Point p0(2, 3);
          p0.label("$p_0$");
          


[Figure 101. Not displayed.]

Fig. 101.

If backslashes are needed in the text of the label, then text_str must contain double backslashes, so that single backslashes will be written to out_stream.

          Point P;
          Point Q(2, 2);
          Point R(P.mediate(Q));
          R.label("$\\overrightarrow{PQ}$", "ulft");
          


[Figure 102. Not displayed.]

Fig. 102.

The position argument indicates where the text of the label should be located relative to the Point. The valid values are the strings used in MetaPost for this purpose, i.e., top, bot, lft, rt, llft (lower left), lrt (lower right), ulft (upper left), and urt (upper right). The default is top. 3DLDF does not catch the error if an invalid position argument is used; the string is written to the output file and an error will occur when MetaPost is run.

The dot argument is used to determine whether the label should be dotted or not. The default is false. The function dotlabel() calls label(), passing true as the latter's dot argument.

void dotlabel ([const string text_str, [const string position_str = "top", [Picture& picture = current_picture]]]) const function
void dotlabel (const short text_short, [const string position_str = "top", [Picture& picture = current_picture]]) const function
These functions are like label() except that they always produces a dot.
          Point p0(2, 3);
          p0.dotlabel("$p_0$");
          


[Figure 103. Not displayed.]

Fig. 103.