Skip to main content

Module text

Module text 

Source
Expand description

Inline text markup for super- and subscripts.

Labels, titles, and annotations support a small, matplotlib-flavoured markup:

  • ^ raises the next character (or a ^{...} group) into a superscript.
  • _ lowers the next character (or a _{...} group) into a subscript.
  • \^, \_, and \\ are escapes that emit a literal ^, _, or \.

The markup is resolved to Unicode super/subscript code points, so it renders identically across every backend (PNG, SVG, PDF, WASM) with no special glyph handling. Characters that have no Unicode super/subscript form are left as-is.

use plotkit_core::text::format_markup;

assert_eq!(format_markup("x^2"), "x²");
assert_eq!(format_markup("H_2O"), "H₂O");
assert_eq!(format_markup("10^{-3}"), "10⁻³");
assert_eq!(format_markup("5 \\^ 2"), "5 ^ 2"); // escaped, left literal

Functions§

format_markup
Resolves super/subscript markup in input to Unicode. See the module docs for the syntax. Strings without ^, _, or \ are returned unchanged (and the common case allocates only what it copies).