Skip to content

Commit ebce2f7

Browse files
committed
lint
1 parent d9422dd commit ebce2f7

21 files changed

Lines changed: 236 additions & 120 deletions

src/api.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5477,7 +5477,9 @@ type ParseLatexOptions = NumberFormat & {
54775477
strict: boolean;
54785478
skipSpace: boolean;
54795479
parseNumbers: "auto" | "rational" | "decimal" | "never";
5480-
getSymbolType: (symbol) => BoxedType;
5480+
getSymbolType: (symbol) =>
5481+
| BoxedType
5482+
| TypeString;
54815483
hasSubscriptEvaluate: (symbol) => boolean;
54825484
parseUnexpectedToken: (lhs, parser) => Expression | null;
54835485
preserveLatex: boolean;
@@ -5536,7 +5538,9 @@ it will be parsed as a decimal number even if this setting is `"rational"`.
55365538
#### ParseLatexOptions.getSymbolType()
55375539
55385540
```ts
5539-
getSymbolType: (symbol) => BoxedType;
5541+
getSymbolType: (symbol) =>
5542+
| BoxedType
5543+
| TypeString;
55405544
```
55415545
55425546
This handler is invoked when the parser encounters a

src/compute-engine/boxed-expression/boxed-function.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,9 +1371,7 @@ function solveOr(
13711371
const seen = new Set<string>();
13721372
const results: BoxedExpression[] = [];
13731373
for (const op of operands) {
1374-
const sol = op.solve(varNames) as
1375-
| ReadonlyArray<BoxedExpression>
1376-
| null;
1374+
const sol = op.solve(varNames) as ReadonlyArray<BoxedExpression> | null;
13771375
if (!sol || !Array.isArray(sol)) continue;
13781376
for (const s of sol) {
13791377
const key = JSON.stringify(s.json);
@@ -1396,9 +1394,7 @@ function solveOr(
13961394
if (!Array.isArray(sol)) {
13971395
const rec = sol as Record<string, BoxedExpression>;
13981396
const key = JSON.stringify(
1399-
Object.fromEntries(
1400-
Object.entries(rec).map(([k, v]) => [k, v.json])
1401-
)
1397+
Object.fromEntries(Object.entries(rec).map(([k, v]) => [k, v.json]))
14021398
);
14031399
if (!seen.has(key)) {
14041400
seen.add(key);
@@ -1409,9 +1405,7 @@ function solveOr(
14091405
// Array of Records
14101406
for (const s of sol as Array<Record<string, BoxedExpression>>) {
14111407
const key = JSON.stringify(
1412-
Object.fromEntries(
1413-
Object.entries(s).map(([k, v]) => [k, v.json])
1414-
)
1408+
Object.fromEntries(Object.entries(s).map(([k, v]) => [k, v.json]))
14151409
);
14161410
if (!seen.has(key)) {
14171411
seen.add(key);
@@ -1438,7 +1432,8 @@ function filterSolutionByTypes(
14381432
const val = solution[v]?.evaluate();
14391433
if (!val) continue;
14401434
if (varTypeObj.matches('integer') && val.isInteger === false) return false;
1441-
if (varTypeObj.matches('rational') && val.isRational === false) return false;
1435+
if (varTypeObj.matches('rational') && val.isRational === false)
1436+
return false;
14421437
if (varTypeObj.matches('real') && val.isReal === false) return false;
14431438
}
14441439
return true;

src/compute-engine/boxed-expression/simplify.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,14 @@ function simplifyNonCommutativeFunction(
438438
const isAbsRule = because?.startsWith('|');
439439
// Quotient-power distribution: a/(b/c)^d -> a*(c/b)^d eliminates nested fractions
440440
const isQuotientPowerRule = because === 'a / (b/c)^d -> a * (c/b)^d';
441-
if (!isCheaper(expr, last, options?.costFunction) && !isPowerCombination && !isLogRule && !isRootSignRule && !isAbsRule && !isQuotientPowerRule)
441+
if (
442+
!isCheaper(expr, last, options?.costFunction) &&
443+
!isPowerCombination &&
444+
!isLogRule &&
445+
!isRootSignRule &&
446+
!isAbsRule &&
447+
!isQuotientPowerRule
448+
)
442449
return steps;
443450

444451
result.at(-1)!.value = last;

src/compute-engine/boxed-expression/solve.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isInequalityOperator } from '../latex-syntax/utils';
21
import { matchAnyRules } from './rules';
32
import { expand } from './expand';
43
import type {

src/compute-engine/cost-function.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ export function costFunction(expr: BoxedExpression): number {
147147
if (innerPow) return 3 + costFunction(innerPow.ops[1]);
148148
}
149149
nameCost = 4;
150-
}
151-
else if (name === 'Sqrt') {
150+
} else if (name === 'Sqrt') {
152151
// Sqrt with perfect squares inside should be more expensive
153152
// because √(x²y) should simplify to |x|√y
154153
const fnExpr = isBoxedFunction(expr) ? expr : undefined;

src/compute-engine/latex-syntax/dictionary/definitions-arithmetic.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,12 +1102,42 @@ export const DEFINITIONS_ARITHMETIC: LatexDictionary = [
11021102
kind: 'function',
11031103
parse: 'LCM',
11041104
},
1105-
{ symbolTrigger: 'max', kind: 'function', parse: 'Max', arguments: 'implicit' },
1106-
{ symbolTrigger: 'min', kind: 'function', parse: 'Min', arguments: 'implicit' },
1107-
{ name: 'Max', latexTrigger: '\\max', kind: 'function', arguments: 'implicit' },
1108-
{ name: 'Min', latexTrigger: '\\min', kind: 'function', arguments: 'implicit' },
1109-
{ name: 'Supremum', latexTrigger: '\\sup', kind: 'function', arguments: 'implicit' },
1110-
{ name: 'Infimum', latexTrigger: '\\inf', kind: 'function', arguments: 'implicit' },
1105+
{
1106+
symbolTrigger: 'max',
1107+
kind: 'function',
1108+
parse: 'Max',
1109+
arguments: 'implicit',
1110+
},
1111+
{
1112+
symbolTrigger: 'min',
1113+
kind: 'function',
1114+
parse: 'Min',
1115+
arguments: 'implicit',
1116+
},
1117+
{
1118+
name: 'Max',
1119+
latexTrigger: '\\max',
1120+
kind: 'function',
1121+
arguments: 'implicit',
1122+
},
1123+
{
1124+
name: 'Min',
1125+
latexTrigger: '\\min',
1126+
kind: 'function',
1127+
arguments: 'implicit',
1128+
},
1129+
{
1130+
name: 'Supremum',
1131+
latexTrigger: '\\sup',
1132+
kind: 'function',
1133+
arguments: 'implicit',
1134+
},
1135+
{
1136+
name: 'Infimum',
1137+
latexTrigger: '\\inf',
1138+
kind: 'function',
1139+
arguments: 'implicit',
1140+
},
11111141

11121142
{
11131143
name: 'Limit',

src/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { Expression } from '../../../math-json';
2-
import { stringValue, operands, operand, operator } from '../../../math-json/utils';
2+
import {
3+
stringValue,
4+
operands,
5+
operand,
6+
operator,
7+
} from '../../../math-json/utils';
38
import { LatexDictionary, Parser, Serializer } from '../types';
49
import { joinLatex } from '../tokenizer';
510
import { DELIMITERS_SHORTHAND } from './definitions-core';
@@ -103,8 +108,7 @@ export const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary = [
103108
const columns = parseColumnFormat(parser);
104109
const [op, cells] = parseCells(parser);
105110

106-
if (columns)
107-
return ['Norm', [op, cells, { str: columns }]] as Expression;
111+
if (columns) return ['Norm', [op, cells, { str: columns }]] as Expression;
108112

109113
return ['Norm', [op, cells]] as Expression;
110114
},
@@ -237,7 +241,12 @@ export const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary = [
237241
},
238242

239243
// Also support plain text: tr(A)
240-
{ symbolTrigger: 'tr', kind: 'function', parse: 'Trace', arguments: 'implicit' },
244+
{
245+
symbolTrigger: 'tr',
246+
kind: 'function',
247+
parse: 'Trace',
248+
arguments: 'implicit',
249+
},
241250

242251
{
243252
name: 'Kernel',
@@ -247,7 +256,12 @@ export const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary = [
247256
serialize: (serializer: Serializer, expr: Expression): string =>
248257
serializeImplicitOperator(serializer, expr, '\\ker'),
249258
},
250-
{ symbolTrigger: 'ker', kind: 'function', parse: 'Kernel', arguments: 'implicit' },
259+
{
260+
symbolTrigger: 'ker',
261+
kind: 'function',
262+
parse: 'Kernel',
263+
arguments: 'implicit',
264+
},
251265

252266
{
253267
name: 'Dimension',
@@ -272,7 +286,12 @@ export const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary = [
272286
serialize: (serializer: Serializer, expr: Expression): string =>
273287
serializeImplicitOperator(serializer, expr, '\\deg'),
274288
},
275-
{ symbolTrigger: 'deg', kind: 'function', parse: 'Degree', arguments: 'implicit' },
289+
{
290+
symbolTrigger: 'deg',
291+
kind: 'function',
292+
parse: 'Degree',
293+
arguments: 'implicit',
294+
},
276295

277296
{
278297
name: 'Hom',
@@ -282,7 +301,12 @@ export const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary = [
282301
serialize: (serializer: Serializer, expr: Expression): string =>
283302
serializeImplicitOperator(serializer, expr, '\\hom'),
284303
},
285-
{ symbolTrigger: 'hom', kind: 'function', parse: 'Hom', arguments: 'implicit' },
304+
{
305+
symbolTrigger: 'hom',
306+
kind: 'function',
307+
parse: 'Hom',
308+
arguments: 'implicit',
309+
},
286310

287311
{
288312
name: 'Determinant',
@@ -306,7 +330,12 @@ export const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary = [
306330
},
307331

308332
// Also support plain text: det(A)
309-
{ symbolTrigger: 'det', kind: 'function', parse: 'Determinant', arguments: 'implicit' },
333+
{
334+
symbolTrigger: 'det',
335+
kind: 'function',
336+
parse: 'Determinant',
337+
arguments: 'implicit',
338+
},
310339

311340
// MatrixMultiply serializes as multiplication with \cdot
312341
{

src/compute-engine/latex-syntax/dictionary/definitions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ function makeParseHandler(
654654
//
655655
if (kind === 'function') {
656656
const fnName = entry.parse ?? entry.name ?? idTrigger;
657-
const argMode = ('arguments' in entry ? entry.arguments : undefined) ?? 'enclosure';
657+
const argMode =
658+
('arguments' in entry ? entry.arguments : undefined) ?? 'enclosure';
658659
if (fnName)
659660
return (parser: Parser, until: Terminator) => {
660661
const args = parser.parseArguments(argMode, until);

src/compute-engine/latex-syntax/parse-symbol.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ function parseSymbolBody(parser: Parser): string | null {
151151
while (!parser.atEnd) {
152152
const token = parser.peek;
153153
if (token === '<}>' || token === '_' || token === '^') break;
154-
if (token === '<space>') { parser.nextToken(); continue; }
154+
if (token === '<space>') {
155+
parser.nextToken();
156+
continue;
157+
}
155158
const next = parseSymbolToken(parser, { toplevel: false });
156159
if (next === null) return null;
157160
id += next;

src/compute-engine/latex-syntax/serializer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ function parseSymbolBody(
524524
if (countTokens(body) > 1) {
525525
// Use \operatorname for symbols containing \unicode escapes
526526
// (these are named symbols, not styled text)
527-
if (body.includes('\\unicode'))
528-
body = `\\operatorname{${body}}`;
527+
if (body.includes('\\unicode')) body = `\\operatorname{${body}}`;
529528
else body = `\\mathrm{${body}}`;
530529
}
531530
break;

0 commit comments

Comments
 (0)