Typeset TeX files

Typeset a TeX file using a custom TeX format C++

 

Typesetting is the process of arranging text and images on a page in a visually appealing and legible manner. This process involves adjusting the spacing, font, and layout of the text. In the context of TeX, typesetting refers to the process of reading a TeX file and converting it into a typeset document, such as a PDF. This is done using a program called a TeX engine, which interprets the TeX code and produces a typeset document.

TeX and LaTeX are known for their powerful typesetting capabilities, like the ability to handle complex mathematical equations and symbols, as well as their ability to produce high-quality documents. Other typesetting tools include Microsoft Word, Adobe InDesign, and QuarkXPress.

You can typeset a TeX file from the command line by running the appropriate command, or you can use TeX libraries for different programming languages to typeset TeX files programmatically. For example, you can use Aspose.TeX for C++ to typeset TeX files. Here you will find a code example for such a task.

To run the examples we need:

  • The Aspose.TeX for C++ API which is a feature-rich, powerful and easy-to-use document processing and conversion API for C++ platform.
  • Open the NuGet package manager, search for Aspose.TeX.Cpp and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command

PM> Install-Package Aspose.TeX.Cpp

Steps to typeset TeX using C++.

  1. Instantiate typesetting options for Object TeX/Object LaTeX upon the Object TeX engine extension using the ConsoleAppOptions() method of the TeXOptions class. Use the ObjectTeX() configuration if the TeX file you want to typeset is in Plain TeX format, or even contains only TeX primitives besides text data. If your TeX file is in LaTeX format, get_ObjectLaTeX() configuration must be used instead.
  2. Specify a file system working directory for the output using the OutputFileSystemDirectory class.
  3. Create an instance of the TeXJob class with a newly created XpsDevice object and run the job by calling the Run() method.

C++ code example: Typesetting a TeX/LaTeX file

using Aspose::TeX::IO;
using Aspose::TeX::Presentation::Xps;
// Create conversion options for the Object TeX/Object LaTeX format upon the Object TeX engine extension.
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX()); // TeXConfig::get_ObjectLaTeX()
// Specify a file system working directory for the output.
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory));
// Run the job.
System::MakeObject<Aspose::TeX::TeXJob>(System::IO::Path::Combine(RunExamples::InputDirectory, u"hello-world"),
    System::MakeObject<XpsDevice>(), options)->Run();

TeX What is TeX File Format

TeX is not actually a format. It is both a programming language and also an interpreter engine that understands this language. A TeX file is a plain text file created using TeX syntax to be converted to some target format by being processed by a TeX engine. This output document may include graphics, tables, lists, formulas, and equations.