Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/c0eb6cbcfb001b7e6355cafa4611afed to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/c0eb6cbcfb001b7e6355cafa4611afed to your computer and use it in GitHub Desktop.
Create and use custom TeX formats with .NET

Aspose.TeX for .NET – Custom TeX Format Examples

These snippets demonstrate creating and using custom TeX formats with Aspose.TeX for .NET. Create your own TeX format files to precompile frequently used macros and definitions, then use them for faster typesetting.

Key Use Cases

  • Create a custom TeX format file
  • How to create TeX format with custom macros
  • Typeset with custom TeX format
  • How to use a custom format for document processing
  • Precompile TeX macros for performance
  • Define custom document classes

How to Run Examples

  1. Reference Aspose.TeX for .NET: Aspose.TeX on Windows; Aspose.TeX.Drawing on non‑Windows.
  2. Copy a snippet into your project.
  3. Apply a temporary license as described in the licensing guide.
  4. Build and run.

Restrictions

In evaluation mode, the output may contain watermarks and limitations. Apply a valid license to unlock full functionality.

Related Documentation

More about custom TeX formats:

Related Resources

Requirements

  • .NET 6.0+, .NET Core, or .NET Framework
  • Aspose.TeX for .NET library

What is a Custom TeX Format?

A custom TeX format is a precompiled binary file containing:

  • Macro definitions
  • Font metrics
  • Hyphenation patterns
  • Custom document classes
  • Frequently used packages

This approach significantly improves typesetting performance by avoiding repetitive macro compilation.

Examples Overview

1. Create Custom Format

The first example demonstrates creating a custom TeX format file (.fmt) using the ObjectIniTeX engine. The format is created from a TeX source file containing macro definitions.

2. Typeset with Custom Format

The second example shows how to use the previously created custom format for document typesetting. This approach is much faster than loading all macros each time.

Aspose.TeX for .NET – Custom TeX Format Examples
// Create a custom TeX format file
// Learn more: https://docs.aspose.com/tex/net/other-tex-formats/
// Create TeX engine options for no format upon ObjectTeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectIniTeX);
// Specify a file system working directory for the input.
options.InputWorkingDirectory = new InputFileSystemDirectory(DataDir);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Run format creation.
TeXJob.CreateFormat("customtex", options);
// For further output to look fine.
options.TerminalOut.Writer.WriteLine();
// Typeset a TeX file using a custom TeX format
// Learn more: https://docs.aspose.com/tex/net/other-tex-formats/
// Create the file system input working directory.
// Create the format provider using the file system input working directory.
// We use the project output directory as our custom format file is supposed to be located there.
using (FormatProvider formatProvider =
new FormatProvider(new InputFileSystemDirectory(OutputDir), "customtex"))
{
// Create conversion options for a custom format upon ObjectTeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX(formatProvider));
options.JobName = "typeset-with-custom-format";
// Specify the input working directory. This is not required here as we are providing the main input as a stream.
// But it is required when the main input has dependencies (e.g. images).
options.InputWorkingDirectory = new InputFileSystemDirectory(DataDir);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Run the job.
new TeXJob(new MemoryStream(Encoding.ASCII.GetBytes(
"Congratulations! You have successfully typeset this text with your own TeX format!\\end")),
new XpsDevice(), options).Run();
// For further output to look fine.
options.TerminalOut.Writer.WriteLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment