packages

plot::text

Label text with a TeX-like math subset. Between $ signs: Greek and symbol commands (\alpha, \times, \leq, ...), superscripts and subscripts (x^2, x_{ij}, nested), {..} groups and \mathrm{..} or \text{..} for upright words. Everything is set upright in the one built-in face; fractions, roots and italics are not drawn. \$ writes a dollar sign.

Structs

RunSource

pub struct Run

A piece of text at one size and baseline: scale times the base size, raised by rise ems (negative lowers it).

nabi
assert(plot::text::parse("$x^2$")[1].scale < 1.0);

Functions

parseSource

pub fn parse(s: str) -> List<Run>

The runs of s.

nabi
use plot::text::parse;

let r = parse("$\\alpha^2$ [m]");
assert(r[0].text == "\u{3b1}" && r[1].text == "2" && r[1].rise > 0.0);
assert(r[2].text == " [m]");
assert(parse("cost \\$5")[0].text == "cost $5");

symbolSource

pub fn symbol(name: str) -> str | none

The character a math command stands for, none if unknown.

nabi
assert(plot::text::symbol("Omega") == "\u{3a9}");
assert(plot::text::symbol("times") == "\u{d7}");

plainSource

pub fn plain(runs: List<Run>) -> str

The runs as one line of plain text: superscripts and subscripts as Unicode script characters where they exist, else after ^ or _.

nabi
use plot::text::{parse, plain};

assert(plain(parse("$10^{-3}$")) == "10\u{207b}\u{b3}");
assert(plain(parse("$x_i$")) == "x\u{1d62}");