For instance, in physics, numbers like 6.626 * 10^-19 J*s are quite common, and encoding units like J*s manually in text is clunky (" " ("kg"*"m")/("s"^(-1)), for instance).
These can be parsed according to the rules below. Specific recognition of the letter "e" may need to be added to the lexer; in this case, the parser can convert it back to the standard Letters "e" under the constant rule.
Note that in the following specifications brackets ([...]) represent optional items.
The entire expression will be grouped ({...} in LaTeX).
The following will be converted to Unicode:
Leading mu → µ
Trailing ohm → Ω
Identifiers such as kg or m will be converted to text (i.e. \text{kg} or \text{m}).
The exponential expression will be rendered as an exponent; thus, s^-1 will compile to \text{s}^{-1}.
Num
numFunc := 'num' ldel num rdel
numTics := '`' num '`'
num := NUMBER ['e' ['-'] NUMBER] [unit] | unit
The entire expression will be grouped together.
The leading NUMBER will be unchanged.
The optional 'e' term will be treated as exponential notation; that is, e-3 after the first number will compile to \times 10^{-3}.
The entire num expression will be wrapped in invisible delimiters.
A space will be added before any present unit terms. This means that, without a leading number, num(...) behaves identically to unit(...) except for adding a small leading space, \, in LaTeX.
For instance, in physics, numbers like
6.626 * 10^-19 J*s
are quite common, and encoding units likeJ*s
manually in text is clunky (" " ("kg"*"m")/("s"^(-1))
, for instance).Examples of syntax:
The above items will become:
These can be parsed according to the rules below. Specific recognition of the letter "e" may need to be added to the lexer; in this case, the parser can convert it back to the standard
Letters "e"
under theconstant
rule.Note that in the following specifications brackets (
[...]
) represent optional items.Rules
Units
The entire expression will be grouped (
{...}
in LaTeX).The following will be converted to Unicode:
Leading
mu
→µ
Trailing
ohm
→Ω
Identifiers such as
kg
orm
will be converted to text (i.e.\text{kg}
or\text{m}
).The exponential expression will be rendered as an exponent; thus,
s^-1
will compile to\text{s}^{-1}
.Num
The entire expression will be grouped together.
The leading
NUMBER
will be unchanged.The optional
'e'
term will be treated as exponential notation; that is,e-3
after the first number will compile to\times 10^{-3}
.The entire
num
expression will be wrapped in invisible delimiters.A space will be added before any present unit terms. This means that, without a leading number,
num(...)
behaves identically tounit(...)
except for adding a small leading space,\,
in LaTeX.