Create document figures with LaTeX

Render LaTeX text, tables, and graphics in PNG or SVG using C# .NET

 

LaTeX, is a typesetting system and a highly regarded tool for creating figures for publications. It includes features and benefits that make it the right choice for this job, and here is why:

  • High-quality typography: LaTeX offers precise control over fonts, character spacing, line breaks, and overall layout, so the resulting figures look great.

  • Mathematical typesetting: As this system was originally designed for mathematical typesetting, it excels in handling complex mathematical equations and symbols.

  • LaTeX primarily deals with vector graphics, which ensures that your figures remain scalable without any loss of quality. Such graphics are resolution-independent which is particularly advantageous for scientific or technical illustrations.
  • Consistency with the document: Since LaTeX is a document preparation system, you can easily maintain a consistent style and formatting across all figures, ensuring a cohesive look throughout your document.

Overall, LaTeX offers a reliable platform for figure creation, providing high-quality typography, mathematical typesetting, scalability, consistency with the document, reproducibility, version control, integration with packages, and automation capabilities.

The Aspose.TeX API solution, among other features, allows cropping out and rendering any LaTeX fragment that represents a figure in PNG or SVG. Here you will find a code snippet of such operations with the result saved as PNG. And more code examples are here.

To run the examples we need:

  • The Aspose.TeX for .NET API which is a feature-rich, powerful and easy-to-use document manipulation and conversion API for C# platform.

  • Open the NuGet package manager, search for Aspose.TeX and install it. You may also use the following command from the Package Manager Console:

Package Manager Console Command

PM> Install-Package Aspose.TeX

Steps to render LaTeX figures in PNG C#

The provided code snippet demonstrates how to use the figure rendering API from Aspose.TeX to create a mathematical diagram image. Here is the order:

  1. Create an instance of the PngFigureRendererOptions class.
  2. Specify the Preamble property of the options object.
  3. Set the scaling factor and background color.
  4. Configure a MemoryStream object to capture the log output generated by the rendering process. Assign this stream to the LogStream property. If the ShowTerminal property is set to true, the terminal output will be displayed on the console.
  5. Then create a file stream to save the output image.
  6. Create an instance of the PngFigureRenderer class and run rendering by calling the Render() method.
  7. Get the error report and the output.
C# code example: Rendering an illustration figure in PNG
LaTeX Fragment
LaTeX Preamble
Output Format
Select the target format

        



FAQ

1. Can LaTeX text be rendered in documents outside of LaTeX environments?

Yes, there are tools and libraries that allow LaTeX syntax to be processed and rendered into formats like PDF, HTML, or even images, enabling LaTeX-based content to be integrated into documents created with other software or displayed on webpages.

2. How can I render LaTeX tables in documents?

Aspose.TeX can parse LaTeX table syntax and render it directly into other document formats or graphical representations suitable for inclusion in various types of documents. For example, for rendering in SVG you will need the SvgFigureRenderer class.

3. Where can I see the example of Aspose.TeX API figure rendering implementation?

The easiest way to visualize the implementation of the solution is to try our cross-platform applications that cover almost the full functionality of the API.

LaTeX What is LaTeX File Format

LaTeX is a TeX format if said briefly. LaTeX files are plain text files written in their own markup language. They may require the inclusion of other data like images and/or other LaTeX files. LaTeX provides you with plenty of advanced features to create tables, include graphics, write math equations and formulas, etc. All these features are available in so-called packages.