Skip to main content

lookup_dimension_cs

Function lookup_dimension_cs 

Source
pub fn lookup_dimension_cs(cs: &str, noerror: bool) -> Option<Dimension>
Expand description

Faithful port of Perl LookupDimension (Package.pm L1371-1393, as widened by upstream PR #2829): try to turn the argument into a Dimension, recognizing strings, registers, ….

  • a string that looks like an obvious dimension (/^[0-9+-.]\w\w+$/, e.g. "3pt" — but NOT "0.4pt", whose . fails \w) parses directly;
  • otherwise the string is tokenized: a single token that resolves to a register returns its value (“easy and proper case”);
  • a multi-token sequence is read as a dimension from a fresh mouth;
  • anything else warns (expected:register) unless noerror, and yields None (Perl returns undef).

NOTE the #2829 semantics change carried over faithfully: a single token whose definition is a MACRO (e.g. a document that \defs \jot) no longer reads its body as a dimension — it now falls through to the warn branch. (Perl’s digested-Box coercion branch has no Rust equivalent here: all our callers pass strings.)