Create document figures with LaTeX

Render LaTeX text, tables, and graphics in PNG or SVG using C++

 

LaTeX, renowned as a typesetting system, stands out as a highly esteemed tool for crafting figures intended for publications. Its features and advantages position it as the optimal choice for such tasks, and here is why:

  • High-quality typography: LaTeX provides precise control over fonts, character spacing, line breaks, and overall layout, ensuring the resulting figures achieve a high-quality appearance.
  • Mathematical typesetting: Originally designed for mathematical typesetting, this system excels in effectively handling complex mathematical equations and symbols.
  • LaTeX primarily deals with vector graphics, ensuring that your figures maintain scalability without compromising 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 effortlessly uphold a uniform style and formatting across all figures, ensuring a cohesive look throughout your document.

In summary, LaTeX offers a dependable foundation for crafting figures, providing exceptional typography, mathematical typesetting, scalability, document-wide consistency, reproducibility, version control, integration with packages, and automation capabilities.

Within the Aspose.TeX API solution, among other features, lies the capability to crop and render any LaTeX fragment representing a figure in either PNG or SVG. Below, you will discover a code snippet demonstrating these operations, with the result saved as a PNG file. More code examples can be found here.

To run the examples we need:

  • The Aspose.TeX for C++ API, - a feature-rich, powerful, and easy-to-use document processing and conversion API for the 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 SVG C++

The code snippet demonstrates how to use the Aspose.TeX’s figure rendering API to generate an image of a mathematical diagram. Here is the order:

  1. Create an instance of the SvgFigureRendererOptions 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 over 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. Instantiate the SvgFigureRenderer class and run the rendering process by invoking the Render() method."
  7. Retrieve the error report and the size of the output image.
C++ code example: Rendering an illustration figure in SVG
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.