Write TeX output to disk
Save the result of a TeX file conversion to disk via C# .NET
TeX is known as a typesetting language which 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. As it is known from the article TeX I/O of the Documentation, the TeX job runs on an explicitly specified TeX file. There you may also find out information on TeX interaction modes and primitives related to TeX input and output.
The main purpose of TeX is to help with the creation of mathematical or technical text writing. But when the file is already created and you do not want any further manipulations on it, you may want to convert it to another, more popular, format.
On this page, you will find a code example explaining how to use file system directories for input and output, write output to XPS format, override the job name, and write terminal output to disk. Simply put, it is a conversion that writes the output to disk. To run this 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 write TeX conversion output to disk C#:
- Create an instance of conversion options for the Object TeX format upon the ObjectTeX engine extension using the ConsoleAppOptions() method of the TeXOptions class.
- Specify a job name if you want to override the job name that will otherwise be extracted from the first argument of the TeXJob constructor.
- Specify a file system working directory for the input. Use the InputFileSystemDirectory class to do this.
- Specify a file system working directory for the output with an appropriate instance of the OutputFileSystemDirectory class.
- Specify that the terminal output must be written to a file in the output working directory.
- Create an object of the TeXJob class with an instance of XpsDevice and run the job by calling the Run() method.
C# code example: Converting TeX file and writing the output to disk
using Aspose.TeX.IO;
using Aspose.TeX.Presentation.Xps;
// Create conversion options for default ObjectTeX format upon ObjectTeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX());
// Specify a job name. Otherwise, the first argument of the TeXJob constructor will be taken as a job name.
options.JobName = "overriden-job-name";
// Specify a file system working directory for the input.
options.InputWorkingDirectory = new InputFileSystemDirectory(RunExamples.InputDirectory);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new 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.TerminalOut = new OutputFileTerminal(options.OutputWorkingDirectory);
// Run the job.
TeXJob job = new TeXJob("hello-world", new XpsDevice(), options);
job.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.