Aspose.TeX LaTeX Figure Renderer for .NET
Aspose.TeX LaTeX Figure Renderer for .NET
Aspose.TeX LaTeX Figure Renderer for .NET brings TeX-quality typesetting directly into your .NET applications. With this plugin, you can input LaTeX figure definitions and obtain pixel-perfect PNG or resolution-independent SVG outputs. Whether you are generating scientific plots, mathematical diagrams, or custom figure layouts, the renderer handles package inclusion, macro definitions, and layout constraints behind the scenes, enabling you to focus on your content.
Installation and Setup
- Install the NuGet package for Aspose.TeX for .NET.
- Configure metered licensing in your application as described in the Metered Licensing guide.
- For supported frameworks and prerequisites, see the Installation page.
Features and Functionalities
Rendering to PNG
- Generate high-quality raster images directly from LaTeX figure source.
- Control pixel dimensions, DPI settings, and background transparency.
- Automatically handle font embedding and glyph antialiasing for crisp display.
Rendering to SVG
- Produce fully vectorized output suitable for responsive design and printing.
- Preserve text as selectable SVG text elements when appropriate.
- Support advanced SVG features such as gradients and clipping paths.
High-Fidelity Output and DPI Control
- Define rendering resolution for both screen and print.
- Specify DPI separately for X and Y axes.
- Ensure consistent stroke, line width, and font size across outputs.
Custom Preprocessing of LaTeX Source
- Inject package imports, macro definitions, or custom preambles.
- Merge user-provided LaTeX fragments into a single document context.
- Sanitize and validate LaTeX input to catch errors early.
Error Reporting and Diagnostics
- Detailed exception messages pinpoint compilation or package issues.
- Access underlying TeX log output for troubleshooting.
- Graceful fallback to placeholder graphics if rendering fails.
Caching and Reuse of Figures
- Cache output images or SVG streams by source hash.
- Use in-memory or on-disk caching strategies.
- Automatically invalidate cache when source or parameters change.
Asynchronous and Batch Rendering
- Submit multiple figures concurrently for parallel rendering.
- Integrate seamlessly with async/await patterns.
- Batch-process figure generation tasks efficiently.
Code Examples
Rendering LaTeX Figure to PNG
// Create the FigureRenderer plugin.
FigureRendererPlugin renderer = new FigureRendererPlugin();
// Configure PNG options.
PngFigureRendererPluginOptions options = new PngFigureRendererPluginOptions()
{
BackgroundColor = Color.Yellow,
Resolution = 150,
Margin = 10,
Preamble = "LaTeX preamble"
};
// Add LaTeX input fragment.
options.AddInputDataSource(new StringDataSource("LaTeX fragment"));
// Create output stream.
using (Stream stream = File.Open(outputPath, FileMode.Create))
{
options.AddOutputDataTarget(new StreamDataSource(stream));
ResultContainer result = renderer.Process(options);
}
Rendering LaTeX Figure to SVG
FigureRendererPlugin renderer = new FigureRendererPlugin();
SvgFigureRendererPluginOptions options = new SvgFigureRendererPluginOptions()
{
BackgroundColor = Color.White,
Margin = 10,
Preamble = "LaTeX preamble"
};
options.AddInputDataSource(new StringDataSource("LaTeX fragment"));
using (Stream stream = File.Open(outputPath, FileMode.Create))
{
options.AddOutputDataTarget(new StreamDataSource(stream));
ResultContainer result = renderer.Process(options);
}
Tips and Best Practices
- Keep the LaTeX preamble minimal to reduce compilation time.
- Use SVG for scalable or print-ready outputs; PNG for thumbnails or fixed sizes.
- Precompute and cache figures during build or startup to avoid runtime delays.
- Sanitize all LaTeX input to prevent injection of unsafe commands.
- Monitor cache usage and define eviction policies for long-running services.
Optimizing Performance
- Adjust DPI and resolution settings to balance quality and performance.
- Implement caching strategies to avoid repeated compilation.
- Use asynchronous rendering for high-throughput environments.
- Profile rendering performance regularly to detect bottlenecks.
Frequently Asked Questions
What formats can I render with Aspose.TeX LaTeX Figure Renderer? You can render LaTeX figures into PNG (raster) and SVG (vector) formats.
Can I customize rendering options? Yes, you can control background color, DPI, resolution, margins, text color, and other settings.
Is Adobe TeX or MikTeX required? No, the renderer works independently of third-party TeX distributions.
Can I use it for batch figure rendering? Yes, the API supports batch and asynchronous figure rendering workflows.
Does it preserve LaTeX fonts and macros? Yes, the renderer embeds necessary fonts and respects macros defined in the preamble.
Which environments are supported? Compatible with Windows, macOS, and Linux systems that support .NET Framework or .NET Core. Also works with C#, F#, VB.NET, Delphi, and C++ via COM Interop.