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.
const
function: 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
]]])These functions cause a
Point
to be labelled in the drawing. The first argument is the text of the label. It can either be astring
, in the first version, or ashort
, in the second. It will often be the name of thePoint
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 MetaPostlabel
command written toout_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$");
![]()
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");
![]()
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 invalidposition
argument is used; thestring
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 functiondotlabel()
callslabel()
, passingtrue
as the latter's dot argument.
const
function: 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]])These functions are like
label()
except that they always produces a dot.Point p0(2, 3); p0.dotlabel("$p_0$");
![]()
Fig. 103.