Skip to content

Commit 27495fe

Browse files
author
Kinon
committed
Fix diagram & macro importing
1 parent 65a3982 commit 27495fe

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

TypeMath/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,10 @@ class Application
781781
break;
782782
case "~>": style = StrokeStyle.Wavy;
783783
break;
784+
case "":
785+
style = StrokeStyle.None;
786+
this.diagramOption.head = "";
787+
break;
784788
}
785789
}
786790
if (code.children[2])

TypeMath/latexReader.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference path="formula.ts" />
2+
/// <reference path="util.ts" />
23

34
enum LaTeXASTType
45
{
@@ -16,6 +17,7 @@ class LaTeXReader
1617
{
1718
rest: string;
1819
parsed: string;
20+
macroArgNum: { [key: string]: number } = {};
1921

2022
constructor(src: string)
2123
{
@@ -90,7 +92,7 @@ class LaTeXReader
9092
item]
9193
});
9294
}
93-
else if (isXy && (m = this.pattern(/^\\ar(?:@([2-9]?)(?:\{([^\}]*)\})?)?\[([^\]]*)\]([\^\|_]?)/)))
95+
else if (isXy && (m = this.pattern(/^\\ar(?:@([2-9])?(?:\{([^\}]*)\})?)?\[([^\]]*)\]\s*([\^\|_])?/)))
9496
{
9597
var args = [
9698
this.optionalSymbol(m[1]),
@@ -124,7 +126,7 @@ class LaTeXReader
124126
}
125127
private optionalSymbol(s: string): LaTeXAST
126128
{
127-
return s
129+
return s || s === ""
128130
? { type: LaTeXASTType.Symbol, value: s, children: null }
129131
: null;
130132
}
@@ -164,9 +166,10 @@ class LaTeXReader
164166
}
165167
else if (this.str("#"))
166168
{
169+
m = this.pattern(/^[0-9]+/);
167170
return {
168171
type: LaTeXASTType.Symbol,
169-
value: this.parsed,
172+
value: "#" + this.parsed,
170173
children: null
171174
};
172175
}
@@ -244,6 +247,9 @@ class LaTeXReader
244247
arg.push(null);
245248
}
246249
}
250+
if (name == "newcommand" && arg[1])
251+
this.macroArgNum[arg[0].value] = parseInt(arg[1].value);
252+
247253
return {
248254
type: LaTeXASTType.Command,
249255
value: name,
@@ -292,7 +298,10 @@ class LaTeXReader
292298
case "underbrace":
293299
return [true];
294300
default:
295-
return [];
301+
if (cmd in this.macroArgNum)
302+
return Util.repeat(true, this.macroArgNum[cmd]);
303+
else
304+
return [];
296305
}
297306
}
298307
private white(): void

0 commit comments

Comments
 (0)