示例#1
0
        private void ShowWindow(Calc_node node)
        {
            MathRenderer renderer = new MathRenderer();
            Window       window   = new Window();

            window.Closed += (s, e) => window.Dispatcher.InvokeShutdown();
            Canvas block = renderer.RenderElement(node);

            window.Content = block;
            window.Show();
            System.Windows.Threading.Dispatcher.Run();
        }
        public static void Run()
        {
            // ExStart:LaTeXMathRenderer
            // Create rendering options specifying the image resolution 150 dpi
            MathRendererOptions options = new PngMathRendererOptions()
            {
                Resolution = 150
            };

            // Specify the preamble.
            options.Preamble = @"\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{color}";
            // Specify the scaling factor 300%.
            options.Scale = 3000;
            // Specify the foreground color.
            options.TextColor = System.Drawing.Color.Black;
            // Specify the background color.
            options.BackgroundColor = System.Drawing.Color.White;
            // Specify the output stream for the log file.
            options.LogStream = new MemoryStream();
            // Specify whether to show the terminal output on the console or not.
            options.ShowTerminal = true;

            // The variable in which the dimensions of the resulting image will be written.
            System.Drawing.SizeF size = new System.Drawing.SizeF();
            // Create the output stream for the formula image.
            using (Stream stream = System.IO.File.Open(
                       Path.Combine(RunExamples.OutputDirectory, "math-formula.png"), FileMode.Create))
                // Run rendering.
                MathRenderer.Render(@"\begin{equation*}
e^x = x^{\color{red}0} + x^{\color{red}1} + \frac{x^{\color{red}2}}{2} + \frac{x^{\color{red}3}}{6} + \cdots = \sum_{n\geq 0} \frac{x^{\color{red}n}}{n!}
\end{equation*}", stream, options, out size);

            // Show other results.
            System.Console.Out.WriteLine(options.ErrorReport);
            System.Console.Out.WriteLine();
            System.Console.Out.WriteLine("Size: " + size);
            // ExEnd:LaTeXMathRenderer
        }