示例#1
0
        protected override void Write(OpenXMLRenderer renderer, MathInline obj)
        {
            var text = obj.Content.Text.Substring(obj.Content.Start, obj.Content.Length);

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            TexFormula formula = null;

            try
            {
                formula = _formulaParser.Parse(text);
            }
            catch (Exception)
            {
                return;
            }

            var mathRenderer = new MathRendering.OpenXMLWpfMathRenderer();

            var mathObj = (DocumentFormat.OpenXml.OpenXmlCompositeElement)mathRenderer.Render(formula.RootAtom);

            renderer.Push(mathObj);
            renderer.PopTo(mathObj);
        }
示例#2
0
        protected override void Write(OpenXMLRenderer renderer, MathBlock obj)
        {
            string text = string.Empty; // obj.Content.Text.Substring(obj.Content.Start, obj.Content.Length);

            for (int i = 0; i < obj.Lines.Count; ++i)
            {
                var l = obj.Lines.Lines[i];
                text += l.Slice.Text.Substring(l.Slice.Start, l.Slice.Length);
            }

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            TexFormula formula = null;

            try
            {
                formula = _formulaParser.Parse(text);
            }
            catch (Exception)
            {
                return;
            }

            var mathRenderer = new MathRendering.OpenXMLWpfMathRenderer();

            var mathObj = (DocumentFormat.OpenXml.OpenXmlCompositeElement)mathRenderer.Render(formula.RootAtom);

            var wordParagraph = renderer.PushNewParagraph(); // this is a Word paragraph

            renderer.Push(new Paragraph());                  // Attention this is a __Math__ paragraph!
            renderer.Push(mathObj);
            renderer.PopTo(wordParagraph);
        }