Load TeX source files from ZIP

.NET API Solution to load TeX files from ZIP archive

 

TeX is known as a typesetting language. This means that you do not format your text in the document, but rather enter plain text containing the text fragments of the document along with commands that control the output. At the output, you will get the formatted file of the desired (specified) format. To gain a deeper understanding of TeX input and output, learn the TeX I/O section of the Documentation.

As it is known, the main purpose of TeX is to help create mathematical or technical text writing. But before any manipulations, the file should be first loaded. Here you will find code snippets explaining how to load TeX source files from ZIP using the ZIP working directory for input, direct the output to a PDF file, and write terminal output to console.

To load TeX files we need:

  • The Aspose.TeX for .NET API which is a feature-rich, powerful and easy-to-use document manipulation, and conversion API for 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 load TeX from a ZIP archive C#:

  1. Create a stream object to read the ZIP archive to use it as a source for the input working directory.
  2. Create a stream object to write the ZIP archive to use it as a target for the output working directory.
  3. Create conversion options for the Object TeX format upon the Object TeX engine extension using ConsoleAppOptions() method of the TeXOptions class.
  4. Specify a ZIP archive working directory for the input, and specify a folder inside the archive, if needed. Use the InputZipDirectory class constructor.
  5. Specify a ZIP archive working directory for the output. Use the OutputZipDirectory class constructor.
  6. Specify the console as the output terminal using the OutputConsoleTerminal class.
  7. Define the saving options using the PdfSaveOptions class.
  8. Create an instance of the TeXJob class with a newly created PdfDevice object and run the job by calling the Run() method.
  9. Finalize the output ZIP archive by calling OutputZipDirectory’s Finish() method.

C# code example: loading TeX from ZIP

using Aspose.TeX.IO;
using Aspose.TeX.Presentation.Pdf;
using System.IO;
// Open the stream on the ZIP archive that will serve as an input working directory.
using (Stream inZipStream = File.Open(Path.Combine(RunExamples.InputDirectory, "zip-in.zip"), FileMode.Open))
// Open the stream on the ZIP archive that will serve as an output working directory.
using (Stream outZipStream = File.Open(Path.Combine(RunExamples.OutputDirectory, "zip-pdf-out.zip"), FileMode.Create))
{
    // Create conversion options for the default Object TeX format upon the Object TeX engine extension.
    TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX());
    // Specify a ZIP archive working directory for the input. You can also specify a path inside the archive.
    options.InputWorkingDirectory = new InputZipDirectory(inZipStream, "in");
    // Specify a ZIP archive working directory for the output.
    options.OutputWorkingDirectory = new OutputZipDirectory(outZipStream);
    // Specify the console as the output terminal.
    options.TerminalOut = new OutputConsoleTerminal(); // Default value. Arbitrary assignment.

    // Define the saving options.
    options.SaveOptions = new PdfSaveOptions();
    // Run the job.
    TeXJob job = new TeXJob("hello-world", new PdfDevice(), options);
    job.Run();

    // Finalize output ZIP archive.
    ((OutputZipDirectory)options.OutputWorkingDirectory).Finish();
}



FAQ

1. What classes are used to load TeX files from ZIP?

To provide the input of TeX files from ZIP, use the InputZipDirectory class.

2. How do I install TeX Package?

To do this, open the NuGet package manager, search for Aspose.TeX and install it, or use the following command in the Package Manager Console: Install-Package Aspose.TeX.

3. How do I load a TeX file from ZIP?

Create a stream object to read the ZIP archive for the input. Then create conversion options using ConsoleAppOptions(). Next, specify a ZIP archive working directory for the input. Specify the saving options and 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.