@@ -9,7 +9,7 @@ import { prefixPower } from "./units";
9
9
import { MmlNode } from "mathjax-full/js/core/MmlTree/MmlNode" ;
10
10
11
11
function combineExponent ( parser : TexParser , num : INumberPiece , units : IUnitPiece [ ] , options : IQuantityOptions ) : void {
12
- if ( num . exponent === '' || ( units === null || units . length === 0 ) ) {
12
+ if ( ! num . exponent || ( ! units || units . length === 0 ) ) {
13
13
return ;
14
14
}
15
15
@@ -24,6 +24,7 @@ function combineExponent(parser: TexParser, num: INumberPiece, units: IUnitPiece
24
24
}
25
25
26
26
const firstUnit = units [ 0 ] ;
27
+ // prefix can be undefined, empty, or string... this specifically checks for empty
27
28
if ( firstUnit . prefix !== '' ) {
28
29
const unitPower = ( firstUnit . power !== null ? + ( firstUnit . power ) : 1 ) * ( firstUnit . position === 'denominator' ? - 1 : 1 ) ;
29
30
const addedPower = firstUnit . prefix ? prefixPower . get ( firstUnit . prefix ) : 1 ;
@@ -45,7 +46,7 @@ function combineExponent(parser: TexParser, num: INumberPiece, units: IUnitPiece
45
46
convertToFixed ( parser , num , options ) ;
46
47
}
47
48
48
- function extractExponent ( parser :TexParser , num : INumberPiece , units : IUnitPiece [ ] , options : IQuantityOptions ) : void {
49
+ function extractExponent ( parser : TexParser , num : INumberPiece , units : IUnitPiece [ ] , options : IQuantityOptions ) : void {
49
50
if ( units === null ) {
50
51
return ;
51
52
}
@@ -89,7 +90,7 @@ function extractExponent(parser:TexParser, num: INumberPiece, units: IUnitPiece[
89
90
const newExponent = currentExponent + powersOfTen ;
90
91
num . exponent = Math . abs ( newExponent ) . toString ( ) ;
91
92
num . exponentSign = Math . sign ( newExponent ) > 0 ? '' : '-' ;
92
- if ( num . exponentMarker === '' ) {
93
+ if ( ! num . exponentMarker ) {
93
94
num . exponentMarker = 'e' ;
94
95
}
95
96
}
@@ -168,18 +169,18 @@ const separateUncertaintyUnitsMmlMap = new Map<SeparateUncertaintyUnits, (num: M
168
169
if ( uncertaintyNode !== null ) {
169
170
const parent = uncertaintyNode . parent ;
170
171
const uncertaintyPosition = parent . childNodes . indexOf ( uncertaintyNode ) ;
171
- if ( quantityProduct === null ) {
172
-
172
+ if ( ! quantityProduct ) {
173
+
173
174
parent . childNodes . splice ( uncertaintyPosition , 0 , units ) ;
174
175
parent . appendChild ( units ) ;
175
176
} else {
176
-
177
+
177
178
parent . childNodes . splice ( uncertaintyPosition , 0 , quantityProduct , units ) ;
178
179
179
180
// To make it match the MathML structure of the previous insert,
180
181
// we should insert the 2nd unit at the same depth.
181
182
// However, SRE seems to rearrange it all anyways.
182
-
183
+
183
184
parent . appendChild ( quantityProduct ) ;
184
185
parent . appendChild ( units ) ;
185
186
@@ -222,22 +223,24 @@ const separateUncertaintyUnitsMap = new Map<SeparateUncertaintyUnits, (num: stri
222
223
} ]
223
224
] ) ;
224
225
225
- export function createQuantityProductMml ( parser :TexParser , options :IOptions ) :MmlNode | null {
226
+ export function createQuantityProductMml ( parser : TexParser , options : IOptions ) : MmlNode | null {
226
227
let quantityProductNode = null ;
227
- const trimmedQuantityProduct = options [ "quantity-product" ] . trimStart ( ) ;
228
- if ( trimmedQuantityProduct !== '' ) {
229
- const spacerNode = ( new TexParser ( trimmedQuantityProduct , parser . stack . env , parser . configuration ) ) . mml ( ) ;
230
- const spacerUnicode = findInnerText ( spacerNode ) ;
231
- quantityProductNode = parser . create ( 'token' , 'mo' , { } , spacerUnicode ) ;
232
- }
228
+
229
+ const trimmedQuantityProduct = options [ "quantity-product" ] . trimStart ( ) ;
230
+ if ( trimmedQuantityProduct ) {
231
+ const spacerNode = ( new TexParser ( trimmedQuantityProduct , parser . stack . env , parser . configuration ) ) . mml ( ) ;
232
+ const spacerUnicode = findInnerText ( spacerNode ) ;
233
+ quantityProductNode = parser . create ( 'token' , 'mo' , { } , spacerUnicode ) ;
234
+ } else {
235
+ quantityProductNode = parser . create ( 'token' , 'mo' , { } ) ;
236
+ }
233
237
return quantityProductNode ;
234
238
}
235
239
236
240
export function processQuantity ( parser : TexParser ) : void {
237
241
let globalOptions : IOptions = { ...parser . options . siunitx as IOptions } ;
238
242
239
243
const localOptions = findOptions ( parser , globalOptions ) ;
240
- //const localOptions = optionStringToObject(localOptionString);
241
244
242
245
let numString = parser . GetArgument ( 'num' ) ;
243
246
const unitString = parser . GetArgument ( 'unit' ) ;
0 commit comments