From 4829ea3d40f889ad8d357f0d623759c09573fe43 Mon Sep 17 00:00:00 2001 From: ed eustace Date: Thu, 27 Jun 2019 16:27:46 +0100 Subject: [PATCH] feat: ignore \\text command We have LaTex that intersperses text into mathematical expressions. We want to be able to parse the LaTeX to math and just ignore thes commands. This commit adds text as a whitespace rule. --- lib/converters/latex-to-ast.js | 2 +- spec/quick_latex-to-ast.spec.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/converters/latex-to-ast.js b/lib/converters/latex-to-ast.js index 4c82bdf..293d22a 100644 --- a/lib/converters/latex-to-ast.js +++ b/lib/converters/latex-to-ast.js @@ -143,7 +143,7 @@ import flatten from './flatten'; // Some of the latex commands that lead to spacing -const whitespace_rule = '\\s|\\\\,|\\\\!|\\\\ |\\\\>|\\\\;|\\\\:|\\\\quad\\b|\\\\qquad\\b'; +const whitespace_rule = '\\s|\\\\,|\\\\!|\\\\ |\\\\>|\\\\;|\\\\:|\\\\quad\\b|\\\\qquad\\b|\\\\text{.*?}'; const latex_rules = [ ['[0-9]+(\\.[0-9]*)?(E[+\\-]?[0-9]+)?', 'NUMBER'], diff --git a/spec/quick_latex-to-ast.spec.js b/spec/quick_latex-to-ast.spec.js index e0d513f..553c527 100644 --- a/spec/quick_latex-to-ast.spec.js +++ b/spec/quick_latex-to-ast.spec.js @@ -4,8 +4,9 @@ import { ParseError } from '../lib/converters/error'; var converter = new latexToAst(); var trees = { - + '1 * 3\\text{eggs}' : ['*', 1, 3], '\\frac{1}{2} x': ['*',['/',1,2],'x'], + '\\frac{1}{2\\text{foo}} x': ['*',['/',1,2],'x'], '1+x+3': ['+',1,'x',3], '1-x-3': ['+',1,['-','x'],['-',3]], "1 + - x": ['+',1,['-','x']],