public override void Parse(SourceSpan source, XElement element) { var name = element.AttributeValue("name"); var args = element.Elements("Argument"); var argTypes = GetArgumentTypes(args); var argValues = GetArgumentValues(args); Debug.Assert(argValues.Length == 1 || argValues.Length == 0); TexFormula formula = null; if (argValues.Length == 1) { var parser = new TexFormulaParser(); formula = parser.Parse((string)argValues[0]); } else { formula = new TexFormula { Source = source }; } this.SharedCacheFormulas.Add(name, formula); }
static TexPredefinedFormulaParser() { typeMappings = new Dictionary <string, Type>(); argValueParsers = new Dictionary <string, ArgumentValueParser>(); actionParsers = new Dictionary <string, ActionParser>(); formulaParser = new TexFormulaParser(); var sharedCacheFormulas = new Dictionary <string, TexFormula>(); typeMappings.Add("Formula", typeof(TexFormula)); typeMappings.Add("string", typeof(string)); typeMappings.Add("double", typeof(double)); typeMappings.Add("int", typeof(int)); typeMappings.Add("bool", typeof(bool)); typeMappings.Add("char", typeof(char)); typeMappings.Add("Color", typeof(Color)); typeMappings.Add("Unit", typeof(TexUnit)); typeMappings.Add("AtomType", typeof(TexAtomType)); actionParsers.Add("CreateFormula", new CreateTeXFormulaParser(sharedCacheFormulas)); actionParsers.Add("MethodInvocation", new MethodInvocationParser(sharedCacheFormulas)); actionParsers.Add("Return", new ReturnParser(sharedCacheFormulas)); argValueParsers.Add("Formula", new TeXFormulaValueParser(sharedCacheFormulas)); argValueParsers.Add("string", new StringValueParser(sharedCacheFormulas)); argValueParsers.Add("double", new DoubleValueParser(sharedCacheFormulas)); argValueParsers.Add("int", new IntValueParser(sharedCacheFormulas)); argValueParsers.Add("bool", new BooleanValueParser(sharedCacheFormulas)); argValueParsers.Add("char", new CharValueParser(sharedCacheFormulas)); argValueParsers.Add("Color", new ColorConstantValueParser(sharedCacheFormulas)); argValueParsers.Add("Unit", new EnumParser(typeof(TexUnit), sharedCacheFormulas)); argValueParsers.Add("AtomType", new EnumParser(typeof(TexAtomType), sharedCacheFormulas)); }
public void AddEmbraced(TexFormula formula, string leftSymbol, string rightSymbol) { this.Add( new FencedAtom( _source, formula?.RootAtom, TexFormulaParser.GetDelimiterSymbol(leftSymbol, null), TexFormulaParser.GetDelimiterSymbol(rightSymbol, null))); }
public void Parse(SourceSpan source, XElement element, PredefinedFormulaContext context) { var name = element.AttributeValue("name"); var args = element.Elements("Argument"); var argValues = GetArgumentValues(args, context); Debug.Assert(argValues.Length == 1 || argValues.Length == 0); TexFormula formula; if (argValues.Length == 1) { var parser = new TexFormulaParser(); formula = parser.Parse((string)argValues[0] !); // Nullable TODO: This might need null checking } else { formula = new TexFormula { Source = source }; } context.AddFormula(name, formula); }
public TexFormulaHelper(TexFormula formula) { this.formulaParser = new TexFormulaParser(); this.Formula = formula; }
public void AddEmbraced(TexFormula formula, string leftSymbol, string rightSymbol) { Add(new FencedAtom(formula == null ? null : formula.RootAtom, TexFormulaParser.GetDelimiterSymbol(leftSymbol), TexFormulaParser.GetDelimiterSymbol(rightSymbol))); }
public void AddEmbraced(TexFormula formula, char leftChar, char rightChar) { AddEmbraced(formula, TexFormulaParser.GetDelimeterMapping(leftChar), TexFormulaParser.GetDelimeterMapping(rightChar)); }
private static void UpdateVisual(string sourceText, VisualContainerElement element) { TexFormulaParser.Initialize(); TexFormulaParser _formulaParser = new TexFormulaParser(); // Create formula object from input text. TexFormula formula = null; try { formula = _formulaParser.Parse(sourceText); } #if !DEBUG catch (Exception ex) { MessageBox.Show("An error occurred while parsing the given input:" + Environment.NewLine + Environment.NewLine + ex.Message, "WPF-Math Example", MessageBoxButton.OK, MessageBoxImage.Error); return; } #endif finally { } // Render formula to visual. var visual = new DrawingVisual(); var renderer = formula.GetRenderer(TexStyle.Display, 30d); var formulaSize = renderer.RenderSize; using (var drawingContext = visual.RenderOpen()) { renderer.Render(drawingContext, 0, 1); } element.Visual = visual; //this.Visual = visual; }
public TexExpressionVisitor(System.Linq.Expressions.Expression value, TexFormulaParser tfp ) { _tfp = tfp; Formula = new TexFormula(); Visit(value); }
public TexFormulaHelper(TexFormula formula, SourceSpan source) { this._formulaParser = new TexFormulaParser(); this.Formula = formula; this._source = source; }
public TexExpressionVisitor(System.Linq.Expressions.Expression value, TexFormulaParser tfp) { _tfp = tfp; Formula = new TexFormula(); Visit(value); }