Visualize Your Ideas With Code
fix(2d): handle empty LaTeX parts (#1092)
Jacob2ccc1f1fc7e2
diff --git a/packages/2d/src/lib/components/Latex.ts b/packages/2d/src/lib/components/Latex.tsindex 268dbea3..9518b568 100644--- a/packages/2d/src/lib/components/Latex.ts+++ b/packages/2d/src/lib/components/Latex.ts@@ -88,8 +88,7 @@ export class Latex extends SVGNode {prev.push(...current.split(/{{(.*?)}}/));return prev;}, [])- .map(sub => sub.trim())- .filter(sub => sub.length > 0);+ .filter(sub => sub.trim().length > 0);})@signal()public declare readonly tex: Signal<string[] | string, string[], this>;@@ -124,7 +123,7 @@ export class Latex extends SVGNode {}protected override parseSVG(svg: string): SVGDocument {- const subTexs = this.svgSubTexMap[svg]!;+ const subTexs = this.svgSubTexMap[svg]!.map(sub => sub.trim());const key = `[${subTexs.join(',')}]::${JSON.stringify(this.options())}`;const cached = Latex.texNodesPool[key];if (cached && (cached.size.x > 0 || cached.size.y > 0)) {@@ -138,6 +137,10 @@ export class Latex extends SVGNode {const subSvg = this.subTexToSVG(sub);const subNodes = SVGNode.parseSVGData(subSvg).nodes;+ if (subNodes.length === 0) {+ continue;+ }+const firstId = this.getNodeCharacterId(subNodes[0]);const spliceIndex = oldNodes.findIndex(node => this.getNodeCharacterId(node) === firstId,