Skip to content

Commit 8207c37

Browse files
committed
more fixes for #20
1 parent 5dc9433 commit 8207c37

File tree

9 files changed

+53
-45
lines changed

9 files changed

+53
-45
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ <h2>DeclareSIUnit</h2>
127127
String.raw`\num{1234p}`,
128128
String.raw`\num{12345}`,
129129
String.raw`\num{0.123}`,
130+
String.raw`\num{0.10000}`,
130131
String.raw`\num{.123}`,
131132
String.raw`\num{0,1234}`,
132133
String.raw`\num{.12345}`,

siunitx.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angMethods.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ function parseAngle(parser: TexParser, text: string, options: IAngleOptions): IA
3636
subParser.i++; // GetNext() does not advance position unless skipping whitespace
3737

3838
if (token === ';'){
39-
if (ang.minutes === undefined) {
39+
if (!ang.minutes) {
4040
ang.minutes = generateNumberPiece();
4141
num = ang.minutes;
42-
} else if (ang.seconds === undefined) {
42+
} else if (!ang.seconds) {
4343
ang.seconds = generateNumberPiece();
4444
num = ang.seconds;
4545
} else {
@@ -164,7 +164,7 @@ function displayAngleMml(parser: TexParser, ang: IAnglePiece, options: IAngleOpt
164164
const root = parser.create('node', 'inferredMrow', [], {});
165165

166166
const degreeValue = +(ang.degrees.whole + (ang.degrees.decimal !== '' ? '.' : '') + ang.degrees.fractional);
167-
if (ang.degrees.whole === '' && options["fill-angle-degrees"]) {
167+
if (!ang.degrees.whole && options["fill-angle-degrees"]) {
168168
if (ang.minutes.sign === '-') {
169169
ang.degrees.sign = '-';
170170
ang.minutes.sign = '';
@@ -181,7 +181,7 @@ function displayAngleMml(parser: TexParser, ang: IAnglePiece, options: IAngleOpt
181181
// TODO: assume no exponents, maybe check for this and thow error
182182
degreeNodeToAdd = degreeOverDecimal(parser, degreeMml, options["angle-symbol-degree"], options as IOptions, true);
183183
}
184-
if (degreeNodeToAdd === undefined) {
184+
if (!degreeNodeToAdd) {
185185
// do nothing but add symbol to end
186186
degreeNodeToAdd = parser.create('node', 'inferredMrow', [], {});
187187
degreeNodeToAdd.appendChild(degreeMml);
@@ -217,7 +217,7 @@ function displayAngleMml(parser: TexParser, ang: IAnglePiece, options: IAngleOpt
217217
minuteNodeToAdd = degreeOverDecimal(parser, minutesMml, moddedAngleSymbolMinute, options as IOptions, false);
218218
}
219219

220-
if (minuteNodeToAdd === undefined) {
220+
if (!minuteNodeToAdd) {
221221
// do nothing but add symbol to end
222222
minuteNodeToAdd = parser.create('node', 'inferredMrow', [], {});
223223
minuteNodeToAdd.appendChild(minutesMml);
@@ -249,7 +249,7 @@ function displayAngleMml(parser: TexParser, ang: IAnglePiece, options: IAngleOpt
249249
secondsNodeToAdd = degreeOverDecimal(parser, secondsMml, moddedAngleSymbolSecond, options as IOptions, false);
250250
}
251251

252-
if (secondsNodeToAdd === undefined) {
252+
if (!secondsNodeToAdd) {
253253
// do nothing but add symbol to end
254254
secondsNodeToAdd = parser.create('node', 'inferredMrow', [], {});
255255
secondsNodeToAdd.appendChild(secondsMml);

src/complexMethods.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ export function parseComplexNumber(parser: TexParser, text: string, options: IOp
4545
complex.real = parseNumber(parser, split[0].trim(), options);
4646
//remove imaginary token, add sign, and parse
4747
let value = split[1].replace(imaginaryTokenRegex, '').trim();
48-
if (value === '') {
48+
if (!value) {
4949
value = '1';
5050
}
5151
complex.imaginary = parseNumber(parser, sign + value, options);
5252
} else {
5353
// here because positive imaginary only number was used... i.e. 2i
5454
let value = split[0].replace(imaginaryTokenRegex, '');
55-
if (value === '') {
55+
if (!value) {
5656
value = '1';
5757
}
5858
complex.imaginary = parseNumber(parser, value, options);

src/numDisplayMethods.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const groupNumbersMap = new Map<string, (parser: TexParser, num: INumberPiece, o
8484
function convertUncertaintyToPlusMinus(uncertainty: IUncertainty, piece: INumberPiece, options: INumOutputOptions): void {
8585
if (uncertainty.type !== 'pm') {
8686
// if there's a decimal in the uncertainty, then it's ok to display as-is
87-
if (uncertainty.decimal === '') {
87+
if (!uncertainty.decimal) {
8888
// add zeros, move whole to fraction part, and potentially add decimal and whole
8989
const diff = piece.fractional.length - uncertainty.whole.length;
9090
if (diff >= 0) {
@@ -115,7 +115,7 @@ export function convertUncertaintyToBracket(uncertainty: IUncertainty, piece: IN
115115
if (uncertainty.type === 'bracket') {
116116
// check to make sure that uncertainty doesn't need a decimal point via 'compact marker' or 'full' (full adds zeros to fractional only uncertainty!)
117117
// should only be checked if there is NOT already a decimal point
118-
if (uncertainty.decimal === '' && (options["uncertainty-mode"] === 'compact-marker' || options["uncertainty-mode"] === 'full')) {
118+
if (!uncertainty.decimal && (options["uncertainty-mode"] === 'compact-marker' || options["uncertainty-mode"] === 'full')) {
119119
const diff = uncertainty.whole.length - piece.fractional.length;
120120
if (diff > 0) {
121121
uncertainty.fractional = uncertainty.whole.slice(diff, uncertainty.whole.length);
@@ -193,7 +193,7 @@ export function createExponentMml(num: INumberPiece, parser: TexParser, options:
193193
const root = parser.create('node', 'inferredMrow', [], {});
194194
const exponentProductNode = (new TexParser(options["exponent-product"], parser.stack.env, parser.configuration)).mml();
195195
const exponentBaseNode = (new TexParser(options["exponent-base"], parser.stack.env, parser.configuration)).mml();
196-
if (options["print-zero-exponent"] && (num.exponent === '' || (num.exponent === '0'))) {
196+
if (options["print-zero-exponent"] && (!num.exponent || (num.exponent === '0'))) {
197197
const zeroNode = parser.create('token', 'mn', {}, '0');
198198

199199
if (options["output-exponent-marker"] !== '') {
@@ -268,20 +268,20 @@ export function displayNumberMml(num: INumberPiece, parser: TexParser, options:
268268
let numberString = '';
269269
let trailingMml: MmlNode;
270270
// if unity mantissa AND don't print it, then we don't need the rest of this.
271-
if (num.whole === '1' && num.fractional === '' && !options["print-unity-mantissa"]) {
271+
if (num.whole === '1' && !num.fractional && !options["print-unity-mantissa"]) {
272272
// don't do anything UNLESS exponent is also zero and printZeroExponent is false
273-
if (!options["print-zero-exponent"] && (num.exponent === '' || (num.exponent === '0' && num.exponentSign !== '-'))) {
274-
numberString += '1';
273+
if (!options["print-zero-exponent"] && (!num.exponent || (num.exponent === '0' && num.exponentSign !== '-'))) {
274+
numberString = '1';
275275
}
276276
} else {
277-
if ((num.whole === '' && num.fractional) || +num.whole === 0) {
277+
if ((!num.whole && num.fractional) || +(num.whole) === 0) {
278278
if (options["print-zero-integer"]) {
279-
numberString += '0';
279+
numberString = '0';
280280
}
281281
} else {
282-
numberString += num.whole;
282+
numberString = num.whole;
283283
}
284-
numberString += (num.decimal !== '' ? options["output-decimal-marker"] : '');
284+
numberString += (num.decimal ? options["output-decimal-marker"] : '');
285285
if (options["zero-decimal-as-symbol"] && +(num.fractional) === 0) {
286286
trailingMml = (new TexParser(options["zero-symbol"], parser.stack.env, parser.configuration)).mml();
287287
} else {
@@ -290,7 +290,7 @@ export function displayNumberMml(num: INumberPiece, parser: TexParser, options:
290290
}
291291
const numberNode = parser.create('token', 'mn', {}, numberString);
292292
rootNode.appendChild(numberNode);
293-
if (trailingMml !== undefined) {
293+
if (trailingMml) {
294294
rootNode.appendChild(trailingMml);
295295
}
296296
// display uncertanties (if not null)
@@ -315,7 +315,7 @@ export function displayNumberMml(num: INumberPiece, parser: TexParser, options:
315315
export function displayOutputMml(num: INumberPiece, parser: TexParser, options: IOptions): MmlNode {
316316
const color = options["number-color"] || options.color;
317317
const rootNode = parser.create('node', color ? 'mrow' : 'inferredMrow', [], color ? { mathcolor: color } : {});
318-
if (num.prefix !== '') {
318+
if (num.prefix) {
319319
const prefix = (new TexParser('{' + num.prefix + '}', parser.stack.env, parser.configuration)).mml();
320320
rootNode.appendChild(prefix);
321321
}

src/numPostProcessMethods.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function convertToScientific(parser: TexParser, numOriginal: INumberPiece, optio
5050
}
5151

5252
function convertToExponent(num: INumberPiece, targetExponent: number) {
53-
if (num === null) return;
53+
if (!num) return;
5454
// count difference between target exponent and current one.
5555
const diff = targetExponent - +(num.exponentSign + num.exponent);
5656
const dir = Math.sign(diff); // -: move numbers from frac to whole, +: move the other way
@@ -187,7 +187,7 @@ function roundPlaces(parser: TexParser, num: INumberPiece, options: INumPostOpti
187187
for (let i = 0; i < toAdd; i++) {
188188
num.fractional += '0'; // pad with zeros
189189
}
190-
if (num.decimal === '') {
190+
if (!num.decimal) {
191191
num.decimal = (options as INumOptions)["output-decimal-marker"];
192192
}
193193
} else {
@@ -242,7 +242,7 @@ function roundFigures(parser: TexParser, num: INumberPiece, options: INumPostOpt
242242

243243
for (let i = 0; i < options["round-precision"] - combined.length; i++) {
244244
num.fractional += '0'; // pad with zeros, it's only going to go in the fractional part
245-
if (num.decimal === '') num.decimal = '.';
245+
if (!num.decimal) num.decimal = '.';
246246
}
247247

248248
} else {
@@ -367,7 +367,7 @@ export function postProcessNumber(parser: TexParser, num: INumberPiece, options:
367367
// Check fraction length of uncertainty[0] and compare to value fraction length.
368368
// Could theoretically check for equal uncertainty precision in the case of two uncertainties...
369369
if (num.uncertainty && num.uncertainty.length > 0 && num.uncertainty[0].fractional.length > num.fractional.length) {
370-
if (num.decimal === '') {
370+
if (!num.decimal) {
371371
num.decimal = '.';
372372
}
373373
num.fractional = num.fractional.padEnd(num.uncertainty[0].fractional.length, '0');

src/qtyMethods.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { prefixPower } from "./units";
99
import { MmlNode } from "mathjax-full/js/core/MmlTree/MmlNode";
1010

1111
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)) {
1313
return;
1414
}
1515

@@ -24,6 +24,7 @@ function combineExponent(parser: TexParser, num: INumberPiece, units: IUnitPiece
2424
}
2525

2626
const firstUnit = units[0];
27+
// prefix can be undefined, empty, or string... this specifically checks for empty
2728
if (firstUnit.prefix !== '') {
2829
const unitPower = (firstUnit.power !== null ? +(firstUnit.power) : 1) * (firstUnit.position === 'denominator' ? -1 : 1);
2930
const addedPower = firstUnit.prefix ? prefixPower.get(firstUnit.prefix) : 1;
@@ -45,7 +46,7 @@ function combineExponent(parser: TexParser, num: INumberPiece, units: IUnitPiece
4546
convertToFixed(parser, num, options);
4647
}
4748

48-
function extractExponent(parser:TexParser, num: INumberPiece, units: IUnitPiece[], options: IQuantityOptions): void {
49+
function extractExponent(parser: TexParser, num: INumberPiece, units: IUnitPiece[], options: IQuantityOptions): void {
4950
if (units === null) {
5051
return;
5152
}
@@ -89,7 +90,7 @@ function extractExponent(parser:TexParser, num: INumberPiece, units: IUnitPiece[
8990
const newExponent = currentExponent + powersOfTen;
9091
num.exponent = Math.abs(newExponent).toString();
9192
num.exponentSign = Math.sign(newExponent) > 0 ? '' : '-';
92-
if (num.exponentMarker === '') {
93+
if (!num.exponentMarker) {
9394
num.exponentMarker = 'e';
9495
}
9596
}
@@ -168,18 +169,18 @@ const separateUncertaintyUnitsMmlMap = new Map<SeparateUncertaintyUnits, (num: M
168169
if (uncertaintyNode !== null) {
169170
const parent = uncertaintyNode.parent;
170171
const uncertaintyPosition = parent.childNodes.indexOf(uncertaintyNode);
171-
if (quantityProduct === null){
172-
172+
if (!quantityProduct) {
173+
173174
parent.childNodes.splice(uncertaintyPosition, 0, units);
174175
parent.appendChild(units);
175176
} else {
176-
177+
177178
parent.childNodes.splice(uncertaintyPosition, 0, quantityProduct, units);
178179

179180
// To make it match the MathML structure of the previous insert,
180181
// we should insert the 2nd unit at the same depth.
181182
// However, SRE seems to rearrange it all anyways.
182-
183+
183184
parent.appendChild(quantityProduct);
184185
parent.appendChild(units);
185186

@@ -222,22 +223,24 @@ const separateUncertaintyUnitsMap = new Map<SeparateUncertaintyUnits, (num: stri
222223
}]
223224
]);
224225

225-
export function createQuantityProductMml(parser:TexParser, options:IOptions):MmlNode|null{
226+
export function createQuantityProductMml(parser: TexParser, options: IOptions): MmlNode | null {
226227
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+
}
233237
return quantityProductNode;
234238
}
235239

236240
export function processQuantity(parser: TexParser): void {
237241
let globalOptions: IOptions = { ...parser.options.siunitx as IOptions };
238242

239243
const localOptions = findOptions(parser, globalOptions);
240-
//const localOptions = optionStringToObject(localOptionString);
241244

242245
let numString = parser.GetArgument('num');
243246
const unitString = parser.GetArgument('unit');

src/qtylistMethods.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ function bracketExponent(exponentResult: IExponentModeOutput, unitNode: MmlNode,
3535
return numNode;
3636
});
3737

38-
if (exponentResult.leading === undefined){
38+
if (!exponentResult.leading){
3939
exponentResult.leading = parser.create('node', 'inferredMrow', [], {});
4040
const leadingBracket = (new TexParser(bracketOpenMap.get(parser.currentCS)(options), parser.stack.env, parser.configuration)).mml();
4141
exponentResult.leading.appendChild(leadingBracket);
4242
}
4343

44-
if (exponentResult.trailing === undefined){
44+
if (!exponentResult.trailing){
4545
exponentResult.trailing = parser.create('node', 'inferredMrow', [], {});
4646
}
4747
if (options["list-exponents"] !== 'combine-bracket'){

test.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,30 @@
2020
</script>
2121

2222
<body>
23+
$$ \qty{2.67}{\farad} $$
24+
$$ \qty[quantity-product = {\ }]{2.67}{\farad} $$
25+
$$ \qty[quantity-product = ]{2.67}{\farad} $$
26+
2327
$$ \displaylines{
2428
\ang{-1;;} \\
2529
\ang{;-2;} \\
2630
\ang{;;-3} \\
2731
} $$
28-
$$ \displaylines{
32+
$$ \displaylines{
2933
\sisetup{fill-angle-degrees}
3034
\ang{-1;;} \\
3135
\ang{;-2;} \\
3236
\ang{;;-3} \\
3337
\sisetup{fill-angle-degrees = false}
3438
} $$
35-
$$ \displaylines{
39+
$$ \displaylines{
3640
\sisetup{fill-angle-minutes}
3741
\ang{-1;;} \\
3842
\ang{;-2;} \\
3943
\ang{;;-3} \\
4044
\sisetup{fill-angle-minutes = false}
4145
} $$
42-
$$ \displaylines{
46+
$$ \displaylines{
4347
\sisetup{fill-angle-seconds}
4448
\ang{-1;;} \\
4549
\ang{;-2;} \\

0 commit comments

Comments
 (0)