Exemple #1
0
            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);
            }
        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;
        }
Exemple #3
0
 public void AddAccent(string formula, string accentName)
 {
     AddAccent(formulaParser.Parse(formula), accentName);
 }
Exemple #4
0
 private TexFormula ParseFormula(string source) =>
 _formulaParser.Parse(new SourceSpan("Predefined formula fragment", source, 0, source.Length));