TexParser
finds the siunitx token and maps to the correct token parser (i.e. num, ang, unit, qty, DeclareSIUnit)
DeclareSIUnit is special and has its own starting logic because we want to override the options parsing (stuff in square brackets []). The bracketed option is passed as a string to the DeclareSIUnit parser method, instead of a dictionary (which won't work).
-
Generate map from defaults that matches single characters OR tokens (text preceeded by a backslash). The map will resolve to a function to process that character or token OR map to another map. A second map is needed for tokens with more than one meaning. (i.e. \pm -> sign AND uncertainty )
-
Replace simple math signs with latex equivalents.
-
Generate INumPiece which has empty properties for all of the parts of a number. Start parsing content of
\num
inside curly braces. Pass results to previously discussed map.- Map: If whole and decimal part are still empty, interpret char as
inputSigns
by default. Else, interpret char asinputUncertaintySigns
by default - Function: Just run the function on the char/token
- Map: If whole and decimal part are still empty, interpret char as
-
Depending on current position in number and options:
- drop decimal portion
- drop explicit plus signs
- drop negative for zero values
- drop uncertainty if zero
-
Return
INumPiece
.
-
Check for dropping uncertainty and dropping exponent options.
-
Do rounding... also process if rounding makes it zero.
- None
- Round places
- ignore if uncertainty exists
- round up/down
- pad right with zeros (optional)
- Round figures
- Round uncertainty
-
Check for zero decimal options, pad left with zeros, pad right with zeros
-
Process exponents
- input: leave as-is
- fixed: convert entire number to a fixed exponent
- engineering: convert entire number to engineering mode
- scientific: convert entire number to scientific mode
-
Remove explicit + sign in exponents. *** NO OPTION???
-
Return
INumPiece
.
-
Display prefix (<, >, etc)
-
Group number in sets with subtle spacing. Options include whole part, decimal part, both, and none as well as quantity to group (3 or 4 at a time).
-
Check options to add color to negative values OR bracket negative values (and remove signs). For brackets, we only add the leading bracket here.
-
Check options to display exponential numbers that are 1 or 0. ***
-
Check options to display uncertainties
- seperate: plus/minus uncertainty
- compact: uncertainty in bracket at end **
- full: uncertainty in bracket at end **
- compact-marker: uncertainty in bracket at end **
-
Check options to display exponents that are zero. Check options to print a 1 with exponents.
-
Check options to add color to negative values OR bracket negative values (and remove signs). For brackets, we only add the trailing bracket here.
-
Return LaTeX output.
Very similar to \num
with a few additions.
-
Generate
IAnglePiece
which is threeINumPiece
for degrees, minutes, seconds. Assume last two are empty for now. -
Generate same number mapping as in
\num
. -
Parse angles into each piece using number mapping.
-
Postprocess angle in
IAnglePiece
into desired format:- input: same as input
- arc: convert if needed to arc format (degrees,minutes,seconds)
- decimal: convert if needed to decimal mode
-
Convert
IAnglePiece
to LaTeX string and check options to include:- show degree symbol above decimal marker
- degree, minutes, seconds separator
- add minutes and seconds explicitly if zero
Separate options into global and local options. This is necessary because the /unit
macro can contain sub-macros. These can have their own options. We need a copy of the local options applied to /unit
so that if a sub-macro has its own options, we can revert to the original local options after processing that sub-macro.
Units are parsed into an array of IUnitPiece
. These contain
String provided will either contain a backslash or not. Assume no backslash means plain text units, but any backslash is all macro-based units.
Macro unit is parsed into IUnitMacroProcessResult
using the following flow:
- Is it a macro modifier? (contained in
modifierMacroMap
) ex. 'square', 'cubic', 'tothe`, 'per', 'of', 'highlight', 'cancel', etc...- Return
next
orprevious
typeIUnitMacroProcessResult
based on which part the modifier affects.
- Return
- Is it a prefix? (contained in
prefixSymbol
map) ex. 'deci', 'centi', 'kilo', etc...- Return
prefix
typeIUnitMacroProcessResult
.
- Return
- Is it a user-defined unit?
- Return
unit
typeIUnitMacroProcessResult
.
- Return
- Is it a package-defined unit symbol? ex. 'meter', 'metre', hertz', 'ng', 'umol', 'mA', etc...
- Return
unit
typeIUnitMacroProcessResult
.
- Return
- Error
- Return
new TexError('102', 'The unit macro, ' + macro + ', has not been defined.')
- Return
Any macro options are applied to the local and global options at this point.
The IUnitMacroProcessResult
is processed:
next
andprefix
types are stored into anextModifier
varible for the next macro.previous
type pulls the lastIUnitPiece
from the array and copies properties over.unit
type:- Check for
nextModifer
and apply it to the internalIUnitPiece
from the current result.- check
perMode
options to see if next unit should continue to be in the denominator if this one is in the denominator.
- check
- Add internal
IUnitPiece
to array
- Check for
Create yet another TeXParser
to parse the string. Assume unit starts in the numerator. Each string-based unit will be placed into prefixUnit
unless control characters are hit: ~
.
/
^
_
When a control character or end-of-string is reached, a regex is applied to prefixUnit
to create an IUnitPiece
. This IUnitPiece
is then modified based on which control character triggered the regex.
RegExp('(' + prefixes + ')?(' + units + ')')
(prefixes example: 'E|P|k|d|c|...') (units example: 'Hz|m|g|N|...')
Output LaTeX string from IUnitPiece
array.