Write TeX output to disk

Save the result of TeX file conversion to disk via C++

 

TeX is a typesetting language that allows you to enter plain text containing text fragments of a document along with commands that contol the typesetting process, rather than format the document content in some special application. According to the documentation article TeX I/O , TeX can only reference input and output files by their names.

The main use of TeX is to create mathematical, publishing, or technical documents of any complexity. TeX representation is not very convenient for reading. So once a TeX file is created, it can be converted to a more widely used format. Then you can share the result with anyone, even if they do not have software to work with TeX.

This page provides an example of using the Aspose.TeX for C++ API, a powerful and easy-to-use document processing and conversion tool, to convert a TeX file to another format and write the output to disk. To use the API, you can install it via the NuGet package manager or using the Package Manager Console command shown below.

Package Manager Console Command

PM> Install-Package Aspose.TeX.Cpp

The code here is converting a TeX file and saving it as an XPS file on a disk. Take the following steps to perform such conversion:

  1. This C++ code sets up the options for typesetting using the Object TeX engine extension with the Object TeX format. It creates a new instance of the TeXOptions class corresponding to the required configuration using the TeXConfig::ObjectTeX() method.
  2. Then it overrides the job name with overriden-job-name and specifies the input and output working directories using the InputFileSystemDirectory and OutputFileSystemDirectory classes. It also sets the terminal output to be written to a file in the output directory using the OutputFileTerminal class.
  3. Finally, the code creates a TeXJob class object with the input file name, the XpsDevice object, and the options set up earlier.

C++ code example: Converting TeX and writing the output to the disk

using Aspose::TeX::IO;
using Aspose::TeX::Presentation.Xps;
// Create typesetting options for default Object TeX format on Object TeX engine extension.
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX());
// Specify the job name. Otherwise, [*TeXJob*] constructor's first argument (file name only) will be taken as a job name.
options->set_JobName(u"overriden-job-name");
// Specify a file system working directory for input.
options->set_InputWorkingDirectory(System::MakeObject<InputFileSystemDirectory>(RunExamples::InputDirectory));
// Specify a file system working directory for output.
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory));
// Specify that the terminal output must be written to a file in the output working directory.
// The file name is <job_name>.trm.
options->set_TerminalOut(System::MakeObject<OutputFileTerminal>(options->get_OutputWorkingDirectory()));

// Run the typesetting job.
System::MakeObject<Aspose::TeX::TeXJob>(System::IO::Path::Combine(RunExamples::InputDirectory, u"hello-world"),
    System::MakeObject<XpsDevice>(), options)->Run();



FAQ

1. Can I transform TeX files to PDF?

Yes, the Aspose.TeX API Solution provides this functionality. You will need the Aspose.TeX.Presentation.Pdf namespace that contains classes for typesetting TeX files to PDF.

2. Can I write TeX output to disk?

The Aspose.TeX API Solution includes such functionality. To do this, use the OutputFileSystemDirectory class that implements a simple method for getting a file stream to write to by name.

3. How to write TeX output to disk?

First, create conversion options using ConsoleAppOptions(). Next, specify a file system working directory for the input and output. Finally, run the job.

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.