Text
Represents an arbitrary text label placed as a Graphics object
Text["String", {0,0}]
Supports styling such as Style
and Directive
, i.e.
Graphics[{
Text[Style["Hello World", FontSize->14], {0,0}]
}]
Styling options
The following options can be provided to Style
wrapper
FontSize->Number
- 10, 12, 14...FontFamily->String
- this is basically an SVG attribute, please see here. If you have imported any font using CSS, you can also use it.
To change the color, just put in somewhere to the list
Graphics[{
Red, Text["Hello World", {0,0}]
}]
Methods
EventHandler
One can listen to a several events produced by this primitive using EventHandler
EventHandler[t_Text, {event_ -> handler_, ...}]
where event
can be
"mousemove"
detects and sends coordinates of a mouse, when it is over this element"drag"
makes primitive draggable and emits coordinates"zoom"
detects zoom / mouse-wheel"click"
detects mouse clicks
Dynamic updates
For both the position and text content dynamic updates are supported
txt = RandomWord[];
pos = {0,0};
Graphics[{
Red, Text[txt // Offload, pos // Offload]
}]
task = SetInterval[With[{},
txt = RandomWord[];
pos = RandomReal[{-1,1}, 2];
], 500];
SetTimeout[TaskRemove[task], 5000];
use TaskRemove[task];
to stop an animation
Math support
You can use a limited Latex-math kinda mode, that I implemented instead of full Boxes
support as it was done in Mathematica, since it might slow down the system a lot
Text["wavenumber (cm^{-1})", {0,0}]
Text["\\alpha (cm^{-1})", {0,0}]
A list of features
- most used Greek symbols like
alpha
and etc are supported - subscript
a_1
ora_{hi}
- superscript
a^2
ora^{23}
In principle, it will anyway ends up in HTML, therefore one can use any special symbol
"I will display ❌"