Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/4e3bae6ecbe041bcb411e0cf4c98dc71 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/4e3bae6ecbe041bcb411e0cf4c98dc71 to your computer and use it in GitHub Desktop.
Alternative ways to provide main TeX input: memory streams and terminal with .NET

Aspose.TeX for .NET – Other Ways to Provide Main TeX Input Examples

These snippets demonstrate alternative ways to provide the main TeX input file to Aspose.TeX for .NET. Learn how to use memory streams and terminal input instead of traditional file system files.

Key Use Cases

  • Provide the main TeX input file as a stream
  • How to process LaTeX documents from memory (without creating temporary files)
  • How to process TeX content from in-memory strings
  • Custom job name assignment for stream-based input
  • Enter the main TeX input file from the terminal (interactive mode)

How to Run Examples

  1. Reference Aspose.TeX for .NET: Aspose.TeX on Windows; Aspose.TeX.Drawing on non‑Windows.
  2. Copy a snippet into your project.
  3. Apply a temporary license as described in the licensing guide.
  4. Build and run.

Restrictions

In evaluation mode, the output may contain watermarks and limitations. Apply a valid license to unlock full features.

Related Documentation

More about alternative input methods in Aspose.TeX:

Related Resources

Requirements

  • .NET 6.0+, .NET Core, or .NET Framework
  • Aspose.TeX for .NET library

Examples Overview

1. Stream Input with LaTeX Document

Provide a complete LaTeX document as a memory stream. The document is processed directly from memory without creating any temporary files. Output files will have the default name texput unless you specify a custom job name.

Important Note: When providing input as a stream without specifying a job name, all output files will be named texput (the default TeX job name).

2. Stream Input with PNG Output

Process simple TeX commands from a memory stream with a custom job name. This example demonstrates how to specify options.JobName to control the output file names.

3. Terminal Input (Interactive)

An alternative way to provide the main input file - the TeX engine prompt you to enter the file name interactively from the terminal. This example is marked as [Ignore] in tests as it requires manual user interaction.

Note: This approach is useful for educational purposes or interactive scenarios, but in production environments, you would typically use one of the other input methods (file system or streams).

Aspose.TeX for .NET – Other Ways to Provide Main TeX Input Examples
// Enter main TeX input file from the terminal (interactive)
// Learn more: https://docs.aspose.com/tex/net/other-ways-of-main-input/
// Create conversion options for default ObjectTeX format upon ObjectTeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX());
// Specify a file system working directory for the input.
options.InputWorkingDirectory = new InputFileSystemDirectory(DataDir);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Specify the console as the output terminal.
options.TerminalOut = new OutputConsoleTerminal();
// Define the saving options.
options.SaveOptions = new XpsSaveOptions();
// Run the job. The TeX engine will ask to enter the file name from the terminal.
// Note: This is an interactive example. In production, you would typically
// provide input via TerminalIn property or use one of the other input methods.
TeXJob job = new TeXJob(new XpsDevice(), options);
job.Run();
// For further output to look fine.
options.TerminalOut.Writer.WriteLine();
// Stream input with LaTeX document and XPS output
// Learn more: https://docs.aspose.com/tex/net/other-ways-of-main-input/
// Create conversion options for Object LaTeX format upon Object TeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Specify the console as the output terminal.
options.TerminalOut = new OutputConsoleTerminal();
// Define the saving options.
options.SaveOptions = new XpsSaveOptions();
// Create the XPS device.
XpsDevice device = new XpsDevice();
// Run the job with LaTeX document from memory stream.
TeXJob job = new TeXJob(new MemoryStream(Encoding.ASCII.GetBytes(
@"\documentclass{article} \begin{document} Hello, World! \end{document}")),
device, options);
job.Run();
// For further output to look fine.
options.TerminalOut.Writer.WriteLine();
// Stream input with PNG output and custom job name
// Learn more: https://docs.aspose.com/tex/net/other-ways-of-main-input/
// Create conversion options for default ObjectTeX format upon ObjectTeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX());
// Specify a job name.
options.JobName = "stream-in-image-out";
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Specify the console as the output terminal.
options.TerminalOut = new OutputConsoleTerminal();
// Define the saving options.
PngSaveOptions pngSaveOptions = new PngSaveOptions();
pngSaveOptions.Resolution = 300;
options.SaveOptions = pngSaveOptions;
// Create the image device.
ImageDevice device = new ImageDevice();
// Run the job with TeX content from memory stream.
TeXJob job = new TeXJob(new MemoryStream(Encoding.ASCII.GetBytes(
"\\hrule height 10pt width 95pt\\vskip10pt\\hrule height 5pt\\end")),
device, options);
job.Run();
// For further output to look fine.
options.TerminalOut.Writer.WriteLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment