## Including Text

Here we will add some text labels to the mathlet from the previous pages. Since we will only add text primitives to the scene, most of the code of the previous example can be reused. Only the last two commands need to be replaced.

With LiveGraphics3D you can label the whole plot and individual axes,
and you can put text labels at arbitrary three-dimensional
points in your scene.
For example, in order to label the blue and green sections with labels
`x = const.`

and `y = const.`

, respectively,
we only need to insert two ** Text** primitives.
The arguments of each

**primitive specify the text to be displayed, a three-dimensional point determining the position of the label, and (optionally) a two-dimensional vector specifying the horizontal and vertical alignment with respect to the projected three-dimensional position. The default value for this 2D vector is**

`Text`

**, specifying that the text is centered horizontally and vertically. For the first label we use**

`{0,0}`

**to align the right and top edges of the text with the projected three-dimensional point, while the left and top edges of the second label are aligned at its three-dimensional location by specifying**

`{1,1}`

**.**

`{-1,1}`

(* all but the last two commands are the same as in the previous example *) labels = {Text["x = const.", {x, -2, 0}, {1,1}], Text["y = const.", {3, y, 0}, {-1,1}]}; example = Graphics3D[ {mesh, point, xSection, ySection, tanplane, labels}, Boxed -> False] WriteLiveForm["meshPlaneText1.lg3d", example]

**Resulting applet:**

Note that the labels are moving with the labeled sections as
you drag the red point because the variables
and

**x**

**appear in the specification of their position. However, this was only the first step. There are actually many ways to format text in LiveGraphics3D. First of all, we can change the font and its size by wrapping the labels in a formatting function named**

**y**

**. Here is an alternative assignment for**

`StyleForm`

**, which modifies the font and its size:**

`labels`

labels = {Text[StyleForm["x = const.", FontFamily -> "Times", FontSize -> 20], {x, -2, 0}, {1,1}], Text[StyleForm["y = const.", FontFamily -> "Times", FontSize -> 20], {3, y, 0}, {-1,1}]};

Most systems support the fonts "Times", "Courier", and "Helvetica";
however, not all special characters are supported in all fonts
nor by all systems.
In our experience, "Times" usually offers the largest set of
special characters. These characters can be entered with their
hexadecimal unicode; for example, ** "\:03b1"** represents
a lower-case Greek alpha.
Many special characters, in particular Greek characters,
may be entered by names such as

**for the lower-case alpha or**

`"\[Alpha]"`

**for the upper-case alpha. A list of all named characters recognized by LiveGraphics3D is available in the reference guide for**

`"\[CapitalAlpha]"`

*Mathematica*3.0 (Wolfram, 1996).

In order to modify the style of parts of a text label,
you can use ** StringForm**.
The first argument of

**is a formatting string, which contains placeholders (**

`StringForm`

**,**

``1``

**, etc.) for the following arguments. Here is an example, which also shows how to specify symbols in italics and in bold letters:**

``2``

labels = {Text[StyleForm[StringForm["`1` = const.", StyleForm["x", FontSlant -> "Italic"]], FontFamily -> "Times", FontSize -> 20], {x, -2, 0}, {1,1}], Text[StyleForm[StringForm["`1` = const.", StyleForm["y", FontWeight -> "Bold"]], FontFamily -> "Times", FontSize -> 20], {3, y, 0}, {-1,1}]};

**Resulting applet:**

Apart from static labels, we can also include the value of any
variable in a text label. For example, we can replace the
string ** "const."**
by the actual value of

**x**

and **y**

. The next example
shows two slight variations: The label for **x**

emphasizes
the difference between the text label **x**

specified with
**and the value of**

`"x"`

**x**

specified
with **:**

**x**

labels = {Text[StyleForm[StringForm["`1` = `2`", "x", x], FontFamily -> "Times", FontSize -> 20], {x, -2, 0}, {1,1}], Text[StyleForm[StringForm["y = `1`", y], FontFamily -> "Times", FontSize -> 20], {3, y, 0}, {-1,1}]};

**Resulting applet:**

As you drag the red point in this example, the new numeric values of

and **x**

will be displayed by the two
text primitives.
**y**

To display a changing numeric value in LiveGraphics3D, the text label must refer to a specific variable. For technical reasons, it is not possible to include arbitrary mathematical expressions within label; a primitive such as

will result in an error. This is not a serious limitation, however, since we can always define a dependent variable for any mathematical expression and then include the name of this dependent variable in a text label instead of the expression.
**Text[x+y, {0,0,0}]**

For example, let us display the values of

and **x**

with only two decimal digits. The most straightforward
way to accomplish this, is to display **y**** Round[100*x]/100**
and

**instead of**

`Round[100*y]/100`

**x**

and
**y**

, respectively. Since we cannot put these expressions
into a **primitive, we have to define new dependent variables, say**

`Text`

**and**

`xDisplay`

**. Thus, the complete**

`yDisplay`

`<APPLET>`

tag becomes:
<applet archive="live.jar" code="Live.class" width="500" height="500"> <param name="INPUT_FILE" value="meshPlaneText4.lg3d"> <param name="INDEPENDENT_VARIABLES" value="{x -> 1, y -> 0}" > <param name="DEPENDENT_VARIABLES" value="{ x -> If[x < -1, -1, x], x -> If[x > 3, 3, x], y -> If[y < -2, -2, y], y -> If[y > 1, 1, y], z -> 2y*Exp[-x^2-y^2], xDisplay -> Round[100 * x] / 100, yDisplay -> Round[100 * y] / 100}" > </applet>

Note the two new variables ** xDisplay** and

**in the list for dependent variables. These variables also have to appear in the definition of**

`yDisplay`

**:**

`labels`

labels = {Text[StyleForm[StringForm["`1` = `2`", "x", xDisplay], FontFamily -> "Times", FontSize -> 20], {x, -2, 0}, {1,1}], Text[StyleForm[StringForm["y = `1`", yDisplay], FontFamily -> "Times", FontSize -> 20], {3, y, 0}, {-1,1}]};

**Resulting applet:**

When you drag the red point in this example, the displayed coordinates will only include two decimal digits, making the labels more readable and avoiding frequent changes of the length of the labels. Depending on which Java plug-in your browser has, using the default monospaced font instead of Times might eliminate these changes entirely.

As mentioned earlier, ** Text** primitives are
not the only possibility to include labels in LiveGraphics3D.
Two other possibilities, namely labels for axes and the whole plot,
will be discussed in the next section.

Next Page: Labeling Axes and Plots

#### Table of Contents

- Introduction
- LiveGraphics3D Overview
- LiveGraphics3D Input
- Parametrized Graphics
- Moving Lines and Polygons
- Including Text
- Labeling Axes and Plots
- Animations
- Occlusions of Objects
- Intersecting Objects
- Two-Dimensional Mathlets
- Stereo Images
- Generating Graphical Input
- Advanced Examples
- Future Directions
- References