Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/a7c27e237ee752a9e87592207aad51de to your computer and use it in GitHub Desktop.
Save aspose-com-gists/a7c27e237ee752a9e87592207aad51de to your computer and use it in GitHub Desktop.
Render Equations and Math Formulas using C#
// This code example demonstrates how to render math formulas and equations
// 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 = File.Open(@"D:\Files\Tex\math-formula.png", FileMode.Create))
// Run rendering.
MathRenderer.Render(@"This is a sample formula $f(x) = x^2$ example.", stream, options, out size);
// Show other results.
System.Console.Out.WriteLine(options.ErrorReport);
System.Console.Out.WriteLine();
System.Console.Out.WriteLine("Size: " + size);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment