Write output to ZIP
Save the result of TeX file conversion as ZIP via C++
TeX is a data markup language and the core of the computer typesetting system also known as the publication set system. While it is often referred to as a file format, it is actually a programming language and interpreter engine used to create mathematical, technical, and other complex documents. However, once a file is created, it may be necessary to convert it to a more popular format to be able to use the result on any device and platform.
Aspose.TeX API Solution offers a feature for converting TeX files and saving the result as a ZIP archive. The provided here code snippet shows how to convert a TeX file to PDF and save the output as a zip file. The API converter can transform TeX files in C++ language and can be used to create a cross-platform application or be integrated into your C++ project.
To run the examples, you will need the Aspose.TeX for C++ API, a feature-rich and easy-to-use document manipulation and conversion tool for the C++ platform. You can install the Aspose.TeX API by searching for it in the NuGet package manager or by using the Install-Package Aspose.TeX command in the Package Manager Console.
Package Manager Console Command
PM> Install-Package Aspose.TeX
The code here is converting a TeX file and saving it as a PDF in a ZIP archive. Take the next steps to process such conversion:
- Create an instance of the TeXOptions Class. Use it to specify a ZIP archive working directory for the output using the OutputWorkingDirectory property.
- Specify the console as the output terminal using the OutputConsoleTerminal Class.
- Define the options for saving the output using the PdfSaveOptions Class.
- Run the TeX to PDF conversion using the TeXJob Method for PdfDevice.
- Refine the output.
- Finalize the output ZIP archive using the OutputZipDirectory Class. The code uses a try-catch block to handle any exceptions that may occur during the process.
C++ Code for using ZIP directories for output
using Aspose::TeX::IO;
using Aspose::TeX::Presentation::Pdf;
using System::IO;
// Open a stream on a ZIP archive that will serve as the input working directory.
{
System::SharedPtr<System::IO::Stream> inZipStream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::InputDirectory, u"zip-in.zip"), System::IO::FileMode::Open);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_1({ inZipStream});
// ------------------------------------------
try{
System::SharedPtr<System::IO::Stream> outZipStream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::OutputDirectory, u"zip-pdf-out.zip"), System::IO::FileMode::Create);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ outZipStream});
// ------------------------------------------
try
{
// Create typesetting options for default ObjectTeX format on ObjectTeX engine extension.
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX());
// Specify a ZIP archive working directory for the input.
options->set_InputWorkingDirectory(System::MakeObject<InputZipDirectory>(inZipStream, u"in"));
// Specify a ZIP archive working directory for the output.
options->set_OutputWorkingDirectory(System::MakeObject<OutputZipDirectory>(outZipStream));
// Specify the console as an output terminal.
options->set_TerminalOut(System::MakeObject<OutputConsoleTerminal>());
// Default. Not necessary to specify.
// Create and specify saving options.
options->set_SaveOptions(System::MakeObject<PdfSaveOptions>());
// Run typesetting.
Aspose::TeX::TeX::Typeset(u"hello-world", System::MakeObject<PdfDevice>(), options);
// For the consequent output to look right.
options->get_TerminalOut()->get_Writer()->WriteLine();
// Finalize the output ZIP archive.
(System::DynamicCast<Aspose::TeX::IO::OutputZipDirectory>(options->get_OutputWorkingDirectory()))->Finish();
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}
catch(...)
{
__dispose_guard_1.SetCurrentException(std::current_exception());
}
}
FAQ
1. How do I view TeX output?
To open a TeX file so that the result of typesetting could be viewed, use the cross-platform TeX Viewer . It also allows you save the file as images.
2. Can I write TeX output to a ZIP archive?
Yes, this API Solution provides such functionality. You will need the OutputZipDirectory class, which implements a method for getting a file stream to write to when the working directory is a ZIP archive.
3. How to write TeX output to a ZIP archive?
Create an instance of the TeXOptions class. Then specify a ZIP archive working directory for the output. Specify saving options and run the conversion. Finally, finalize writing the output to a ZIP archive by calling the Finish() method.
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.